Skip to content

Commit 16077ed

Browse files
committed
remove call to getCalleeDecl
1 parent 381c221 commit 16077ed

File tree

7 files changed

+25
-14
lines changed

7 files changed

+25
-14
lines changed

clang/include/clang/AST/Expr.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3028,6 +3028,9 @@ class CallExpr : public Expr {
30283028

30293029
bool hasStoredFPFeatures() const { return CallExprBits.HasFPFeatures; }
30303030

3031+
bool usesMemberSyntax() const { return CallExprBits.ExplicitObjectMemFunUsingMemberSyntax; }
3032+
void setUsesMemberSyntax(bool V = true) { CallExprBits.ExplicitObjectMemFunUsingMemberSyntax = V; }
3033+
30313034
bool isCoroElideSafe() const { return CallExprBits.IsCoroElideSafe; }
30323035
void setCoroElideSafe(bool V = true) { CallExprBits.IsCoroElideSafe = V; }
30333036

@@ -3220,6 +3223,8 @@ class CallExpr : public Expr {
32203223
}
32213224
};
32223225

3226+
static_assert(sizeof(CallExpr) == 24);
3227+
32233228
/// MemberExpr - [C99 6.5.2.3] Structure and Union Members. X->F and X.F.
32243229
///
32253230
class MemberExpr final

clang/include/clang/AST/Stmt.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -563,10 +563,11 @@ class alignas(void *) Stmt {
563563
unsigned HasFPFeatures : 1;
564564

565565
/// True if the call expression is a must-elide call to a coroutine.
566+
LLVM_PREFERRED_TYPE(bool)
566567
unsigned IsCoroElideSafe : 1;
567568

568-
/// Padding used to align OffsetToTrailingObjects to a byte multiple.
569-
unsigned : 24 - 4 - NumExprBits;
569+
LLVM_PREFERRED_TYPE(bool)
570+
unsigned ExplicitObjectMemFunUsingMemberSyntax : 1;
570571

571572
/// The offset in bytes from the this pointer to the start of the
572573
/// trailing objects belonging to CallExpr. Intentionally byte sized

clang/lib/AST/Expr.cpp

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1484,6 +1484,8 @@ CallExpr::CallExpr(StmtClass SC, Expr *Fn, ArrayRef<Expr *> PreArgs,
14841484

14851485
CallExprBits.HasFPFeatures = FPFeatures.requiresTrailingStorage();
14861486
CallExprBits.IsCoroElideSafe = false;
1487+
CallExprBits.ExplicitObjectMemFunUsingMemberSyntax = false;
1488+
14871489
if (hasStoredFPFeatures())
14881490
setStoredFPFeatures(FPFeatures);
14891491
}
@@ -1549,12 +1551,15 @@ Decl *Expr::getReferencedDeclOfCallee() {
15491551
// (simple function or member function call)
15501552
// then try more exotic possibilities
15511553
Expr *CEE = IgnoreImpCasts();
1554+
15521555
if (auto *DRE = dyn_cast<DeclRefExpr>(CEE))
15531556
return DRE->getDecl();
15541557

15551558
if (auto *ME = dyn_cast<MemberExpr>(CEE))
15561559
return ME->getMemberDecl();
15571560

1561+
CEE = CEE->IgnoreParens();
1562+
15581563
while (auto *NTTP = dyn_cast<SubstNonTypeTemplateParmExpr>(CEE))
15591564
CEE = NTTP->getReplacement()->IgnoreParenImpCasts();
15601565

@@ -1658,20 +1663,14 @@ SourceLocation CallExpr::getBeginLoc() const {
16581663
// begin location should come from the first argument.
16591664
// This does not apply to dependent calls, which are modelled with `o.f`
16601665
// being the callee.
1661-
if (!isTypeDependent()) {
1662-
if (const auto *Method =
1663-
dyn_cast_if_present<const CXXMethodDecl>(getCalleeDecl());
1664-
Method && Method->isExplicitObjectMemberFunction()) {
1665-
if (auto FirstArgLoc = getArg(0)->getBeginLoc(); FirstArgLoc.isValid()) {
1666-
return FirstArgLoc;
1667-
}
1666+
// Because this check is expennsive, we cache the result.
1667+
if (usesMemberSyntax()) {
1668+
if (auto FirstArgLoc = getArg(0)->getBeginLoc(); FirstArgLoc.isValid()) {
1669+
return FirstArgLoc;
16681670
}
16691671
}
16701672

1671-
SourceLocation begin = getCallee()->getBeginLoc();
1672-
if (begin.isInvalid() && getNumArgs() > 0 && getArg(0))
1673-
begin = getArg(0)->getBeginLoc();
1674-
return begin;
1673+
return getCallee()->getBeginLoc();
16751674
}
16761675

16771676
SourceLocation CallExpr::getEndLoc() const {

clang/lib/Sema/SemaOpenCL.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ bool SemaOpenCL::checkBuiltinToAddr(unsigned BuiltinID, CallExpr *Call) {
542542
auto RT = Call->getArg(0)->getType();
543543
if (!RT->isPointerType() ||
544544
RT->getPointeeType().getAddressSpace() == LangAS::opencl_constant) {
545-
Diag(Call->getBeginLoc(), diag::err_opencl_builtin_to_addr_invalid_arg)
545+
Diag(Call->getArg(0)->getBeginLoc(), diag::err_opencl_builtin_to_addr_invalid_arg)
546546
<< Call->getArg(0) << Call->getDirectCallee() << Call->getSourceRange();
547547
return true;
548548
}

clang/lib/Sema/SemaOverload.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14832,6 +14832,7 @@ ExprResult Sema::BuildCXXMemberCallExpr(Expr *E, NamedDecl *FoundDecl,
1483214832
CE = CallExpr::Create(Context, FnExpr.get(), MultiExprArg(&ObjectParam, 1),
1483314833
ResultType, VK, Exp.get()->getEndLoc(),
1483414834
CurFPFeatureOverrides());
14835+
CE->setUsesMemberSyntax(true);
1483514836
} else {
1483614837
MemberExpr *ME =
1483714838
BuildMemberExpr(Exp.get(), /*IsArrow=*/false, SourceLocation(),
@@ -16159,6 +16160,7 @@ ExprResult Sema::BuildCallToMemberFunction(Scope *S, Expr *MemExprE,
1615916160
TheCall =
1616016161
CallExpr::Create(Context, FnExpr.get(), Args, ResultType, VK, RParenLoc,
1616116162
CurFPFeatureOverrides(), Proto->getNumParams());
16163+
TheCall->setUsesMemberSyntax(true);
1616216164
} else {
1616316165
// Convert the object argument (for a non-static member function call).
1616416166
ExprResult ObjectArg = PerformImplicitObjectArgumentInitialization(

clang/lib/Serialization/ASTReaderStmt.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,6 +1036,8 @@ void ASTStmtReader::VisitCallExpr(CallExpr *E) {
10361036
E->setADLCallKind(
10371037
static_cast<CallExpr::ADLCallKind>(CurrentUnpackingBits->getNextBit()));
10381038
bool HasFPFeatures = CurrentUnpackingBits->getNextBit();
1039+
E->setCoroElideSafe(CurrentUnpackingBits->getNextBit());
1040+
E->setUsesMemberSyntax(CurrentUnpackingBits->getNextBit());
10391041
assert((NumArgs == E->getNumArgs()) && "Wrong NumArgs!");
10401042
E->setRParenLoc(readSourceLocation());
10411043
E->setCallee(Record.readSubExpr());

clang/lib/Serialization/ASTWriterStmt.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -959,6 +959,8 @@ void ASTStmtWriter::VisitCallExpr(CallExpr *E) {
959959
CurrentPackingBits.updateBits();
960960
CurrentPackingBits.addBit(static_cast<bool>(E->getADLCallKind()));
961961
CurrentPackingBits.addBit(E->hasStoredFPFeatures());
962+
CurrentPackingBits.addBit(E->isCoroElideSafe());
963+
CurrentPackingBits.addBit(E->usesMemberSyntax());
962964

963965
Record.AddSourceLocation(E->getRParenLoc());
964966
Record.AddStmt(E->getCallee());

0 commit comments

Comments
 (0)