Skip to content

Commit 21cf4b4

Browse files
committed
cache begin in callexpr
1 parent dc33c5a commit 21cf4b4

File tree

4 files changed

+37
-2
lines changed

4 files changed

+37
-2
lines changed

clang/include/clang/AST/Expr.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3202,6 +3202,12 @@ class CallExpr : public Expr {
32023202
void setRParenLoc(SourceLocation L) { RParenLoc = L; }
32033203

32043204
SourceLocation getBeginLoc() const {
3205+
if(CallExprBits.HasTrailingSourceLoc) {
3206+
static_assert(sizeof(CallExpr) <= offsetToTrailingObjects + 2 * sizeof(SourceLocation));
3207+
return *reinterpret_cast<const SourceLocation*>(reinterpret_cast<const char *>(this) +
3208+
sizeof(CallExpr));
3209+
}
3210+
32053211
//if (const auto *OCE = dyn_cast<CXXOperatorCallExpr>(this))
32063212
// return OCE->getBeginLoc();
32073213

@@ -3223,6 +3229,23 @@ class CallExpr : public Expr {
32233229

32243230
SourceLocation getEndLoc() const LLVM_READONLY;
32253231

3232+
private:
3233+
friend class ASTStmtReader;
3234+
bool hasTrailingSourceLoc() const {
3235+
return CallExprBits.HasTrailingSourceLoc;
3236+
}
3237+
void setTrailingSourceLocs() {
3238+
assert(!CallExprBits.HasTrailingSourceLoc);
3239+
static_assert(sizeof(CallExpr) <= offsetToTrailingObjects + 2 * sizeof(SourceLocation));
3240+
SourceLocation* Locs = reinterpret_cast<SourceLocation*>(reinterpret_cast<char *>(this) +
3241+
sizeof(CallExpr));
3242+
Locs[0] = getBeginLoc();
3243+
Locs[1] = getEndLoc();
3244+
CallExprBits.HasTrailingSourceLoc = true;
3245+
}
3246+
3247+
public:
3248+
32263249
/// Return true if this is a call to __assume() or __builtin_assume() with
32273250
/// a non-value-dependent constant parameter evaluating as false.
32283251
bool isBuiltinAssumeFalse(const ASTContext &Ctx) const;

clang/include/clang/AST/Stmt.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -568,9 +568,12 @@ class alignas(void *) Stmt {
568568

569569
LLVM_PREFERRED_TYPE(bool)
570570
unsigned ExplicitObjectMemFunUsingMemberSyntax : 1;
571+
572+
LLVM_PREFERRED_TYPE(bool)
573+
unsigned HasTrailingSourceLoc : 1;
571574
};
572575

573-
enum { NumCallExprBits = 24 };
576+
enum { NumCallExprBits = 25 };
574577

575578
class MemberExprBitfields {
576579
friend class ASTStmtReader;

clang/lib/AST/Expr.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1475,6 +1475,7 @@ CallExpr::CallExpr(StmtClass SC, Expr *Fn, ArrayRef<Expr *> PreArgs,
14751475
CallExprBits.HasFPFeatures = FPFeatures.requiresTrailingStorage();
14761476
CallExprBits.IsCoroElideSafe = false;
14771477
CallExprBits.ExplicitObjectMemFunUsingMemberSyntax = false;
1478+
CallExprBits.HasTrailingSourceLoc = false;
14781479

14791480
if (hasStoredFPFeatures())
14801481
setStoredFPFeatures(FPFeatures);
@@ -1487,6 +1488,9 @@ CallExpr::CallExpr(StmtClass SC, unsigned NumPreArgs, unsigned NumArgs,
14871488
assert((NumPreArgs == getNumPreArgs()) && "NumPreArgs overflow!");
14881489
CallExprBits.HasFPFeatures = HasFPFeatures;
14891490
CallExprBits.IsCoroElideSafe = false;
1491+
CallExprBits.ExplicitObjectMemFunUsingMemberSyntax = false;
1492+
CallExprBits.HasTrailingSourceLoc = false;
1493+
14901494
}
14911495

14921496
CallExpr *CallExpr::Create(const ASTContext &Ctx, Expr *Fn,
@@ -1500,8 +1504,10 @@ CallExpr *CallExpr::Create(const ASTContext &Ctx, Expr *Fn,
15001504
void *Mem =
15011505
Ctx.Allocate(sizeToAllocateForCallExprSubclass<CallExpr>(SizeOfTrailingObjects),
15021506
alignof(CallExpr));
1503-
return new (Mem) CallExpr(CallExprClass, Fn, /*PreArgs=*/{}, Args, Ty, VK,
1507+
CallExpr* E = new (Mem) CallExpr(CallExprClass, Fn, /*PreArgs=*/{}, Args, Ty, VK,
15041508
RParenLoc, FPFeatures, MinNumArgs, UsesADL);
1509+
E->setTrailingSourceLocs();
1510+
return E;
15051511
}
15061512

15071513
CallExpr *CallExpr::CreateEmpty(const ASTContext &Ctx, unsigned NumArgs,

clang/lib/Serialization/ASTReaderStmt.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,6 +1047,9 @@ void ASTStmtReader::VisitCallExpr(CallExpr *E) {
10471047
if (HasFPFeatures)
10481048
E->setStoredFPFeatures(
10491049
FPOptionsOverride::getFromOpaqueInt(Record.readInt()));
1050+
1051+
if(E->getStmtClass() == Stmt::CallExprClass)
1052+
E->setTrailingSourceLocs();
10501053
}
10511054

10521055
void ASTStmtReader::VisitCXXMemberCallExpr(CXXMemberCallExpr *E) {

0 commit comments

Comments
 (0)