Skip to content

Commit 63a8b54

Browse files
committed
Storing the endloc is not necessary (and was done incorrectly)
1 parent fd4aaf5 commit 63a8b54

File tree

4 files changed

+24
-36
lines changed

4 files changed

+24
-36
lines changed

clang/include/clang/AST/Expr.h

Lines changed: 19 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2911,11 +2911,10 @@ class CallExpr : public Expr {
29112911
// itself is 24 bytes. To avoid having to recompute or store the offset of the
29122912
// trailing objects, we put it at 32 bytes (such that it is suitable for all
29132913
// subclasses) We use the 8 bytes gap left for instances of CallExpr to store
2914-
// the begin and end source locations. Caching the begin source location in
2915-
// particular as a significant impact on perf as getBeginLoc is assumed to be
2916-
// cheap.
2914+
// the begin source location, which has a significant impact on perf as
2915+
// getBeginLoc is assumed to be cheap.
29172916
// The layourt is as follow:
2918-
// CallExpr | Begin | End | Trailing Objects
2917+
// CallExpr | Begin | 4 bytes left | Trailing Objects
29192918
// CXXMemberCallExpr | Trailing Objects
29202919
// A bit in CallExprBitfields indicates if source locations are presents.
29212920

@@ -3051,9 +3050,9 @@ class CallExpr : public Expr {
30513050
CallExprBits.ExplicitObjectMemFunUsingMemberSyntax = V;
30523051
// Because the source location may be different for explicit
30533052
// member, we reset the cached values.
3054-
if (CallExprBits.HasTrailingSourceLocs) {
3055-
CallExprBits.HasTrailingSourceLocs = false;
3056-
updateTrailingSourceLocs();
3053+
if (CallExprBits.HasTrailingSourceLoc) {
3054+
CallExprBits.HasTrailingSourceLoc = false;
3055+
updateTrailingSourceLoc();
30573056
}
30583057
}
30593058

@@ -3216,19 +3215,14 @@ class CallExpr : public Expr {
32163215
SourceLocation getRParenLoc() const { return RParenLoc; }
32173216
void setRParenLoc(SourceLocation L) { RParenLoc = L; }
32183217

3219-
template <unsigned N> SourceLocation getTrailingSourceLoc() const {
3220-
static_assert(N <= 1);
3221-
assert(CallExprBits.HasTrailingSourceLocs && "No trailing source loc");
3222-
static_assert(sizeof(CallExpr) <=
3223-
offsetToTrailingObjects + 2 * sizeof(SourceLocation));
3224-
return *reinterpret_cast<const SourceLocation *>(
3225-
reinterpret_cast<const char *>(this) + sizeof(CallExpr) +
3226-
sizeof(SourceLocation) * N);
3227-
}
3228-
32293218
SourceLocation getBeginLoc() const {
3230-
if (CallExprBits.HasTrailingSourceLocs)
3231-
return getTrailingSourceLoc<0>();
3219+
if (CallExprBits.HasTrailingSourceLoc) {
3220+
assert(CallExprBits.HasTrailingSourceLoc && "No trailing source loc");
3221+
static_assert(sizeof(CallExpr) <=
3222+
offsetToTrailingObjects + sizeof(SourceLocation));
3223+
return *reinterpret_cast<const SourceLocation *>(
3224+
reinterpret_cast<const char *>(this) + sizeof(CallExpr));
3225+
}
32323226

32333227
if (usesMemberSyntax()) {
32343228
if (auto FirstArgLoc = getArg(0)->getBeginLoc(); FirstArgLoc.isValid()) {
@@ -3239,22 +3233,17 @@ class CallExpr : public Expr {
32393233
}
32403234

32413235
SourceLocation getEndLoc() const {
3242-
if (CallExprBits.HasTrailingSourceLocs)
3243-
return getTrailingSourceLoc<0>();
3244-
3245-
SourceLocation end = getRParenLoc();
3246-
if (end.isInvalid() && getNumArgs() > 0 && getArg(getNumArgs() - 1))
3247-
end = getArg(getNumArgs() - 1)->getEndLoc();
3248-
return end;
3236+
return getRParenLoc();
32493237
}
32503238

32513239
private:
3240+
friend class ASTStmtReader;
32523241
bool hasTrailingSourceLoc() const {
3253-
return CallExprBits.HasTrailingSourceLocs;
3242+
return CallExprBits.HasTrailingSourceLoc;
32543243
}
32553244

3256-
void updateTrailingSourceLocs() {
3257-
assert(!CallExprBits.HasTrailingSourceLocs &&
3245+
void updateTrailingSourceLoc() {
3246+
assert(!CallExprBits.HasTrailingSourceLoc &&
32583247
"Trailing source loc already set?");
32593248
assert(getStmtClass() == CallExprClass &&
32603249
"Calling setTrailingSourceLocs on a subclass of CallExpr");
@@ -3264,8 +3253,7 @@ class CallExpr : public Expr {
32643253
SourceLocation *Locs = reinterpret_cast<SourceLocation *>(
32653254
reinterpret_cast<char *>(this) + sizeof(CallExpr));
32663255
new (Locs) SourceLocation(getBeginLoc());
3267-
new (Locs + 1) SourceLocation(getEndLoc());
3268-
CallExprBits.HasTrailingSourceLocs = true;
3256+
CallExprBits.HasTrailingSourceLoc = true;
32693257
}
32703258

32713259
public:

clang/include/clang/AST/Stmt.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ class alignas(void *) Stmt {
574574
/// Indicates that SourceLocations are cached as
575575
/// Trailing objects. See the definition of CallExpr.
576576
LLVM_PREFERRED_TYPE(bool)
577-
unsigned HasTrailingSourceLocs : 1;
577+
unsigned HasTrailingSourceLoc : 1;
578578
};
579579

580580
enum { NumCallExprBits = 25 };

clang/lib/AST/Expr.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1494,7 +1494,7 @@ CallExpr::CallExpr(StmtClass SC, Expr *Fn, ArrayRef<Expr *> PreArgs,
14941494
CallExprBits.HasFPFeatures = FPFeatures.requiresTrailingStorage();
14951495
CallExprBits.IsCoroElideSafe = false;
14961496
CallExprBits.ExplicitObjectMemFunUsingMemberSyntax = false;
1497-
CallExprBits.HasTrailingSourceLocs = false;
1497+
CallExprBits.HasTrailingSourceLoc = false;
14981498

14991499
if (hasStoredFPFeatures())
15001500
setStoredFPFeatures(FPFeatures);
@@ -1508,7 +1508,7 @@ CallExpr::CallExpr(StmtClass SC, unsigned NumPreArgs, unsigned NumArgs,
15081508
CallExprBits.HasFPFeatures = HasFPFeatures;
15091509
CallExprBits.IsCoroElideSafe = false;
15101510
CallExprBits.ExplicitObjectMemFunUsingMemberSyntax = false;
1511-
CallExprBits.HasTrailingSourceLocs = false;
1511+
CallExprBits.HasTrailingSourceLoc = false;
15121512
}
15131513

15141514
CallExpr *CallExpr::Create(const ASTContext &Ctx, Expr *Fn,
@@ -1525,7 +1525,7 @@ CallExpr *CallExpr::Create(const ASTContext &Ctx, Expr *Fn,
15251525
CallExpr *E =
15261526
new (Mem) CallExpr(CallExprClass, Fn, /*PreArgs=*/{}, Args, Ty, VK,
15271527
RParenLoc, FPFeatures, MinNumArgs, UsesADL);
1528-
E->updateTrailingSourceLocs();
1528+
E->updateTrailingSourceLoc();
15291529
return E;
15301530
}
15311531

clang/lib/Serialization/ASTReaderStmt.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1049,7 +1049,7 @@ void ASTStmtReader::VisitCallExpr(CallExpr *E) {
10491049
FPOptionsOverride::getFromOpaqueInt(Record.readInt()));
10501050

10511051
if (E->getStmtClass() == Stmt::CallExprClass)
1052-
E->updateTrailingSourceLocs();
1052+
E->updateTrailingSourceLoc();
10531053
}
10541054

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

0 commit comments

Comments
 (0)