Skip to content

Commit c9563a4

Browse files
authored
[Clang][NFC] Remove CallExpr::CreateTemporary (#130919)
`CallExpr::CreateTemporary` was only used to deduce a conversion sequence from a conversion operator. We only need a type/value category for that, so we can use a dummy Expression such as a `OpaqueValueExpr`. This simplify the code and avoid partially-formed `CallExpr` with incorrect invariants (see #130725) Fixes #130824
1 parent 369c0a7 commit c9563a4

File tree

3 files changed

+6
-37
lines changed

3 files changed

+6
-37
lines changed

clang/include/clang/AST/Expr.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3005,18 +3005,6 @@ class CallExpr : public Expr {
30053005
FPOptionsOverride FPFeatures, unsigned MinNumArgs = 0,
30063006
ADLCallKind UsesADL = NotADL);
30073007

3008-
/// Create a temporary call expression with no arguments in the memory
3009-
/// pointed to by Mem. Mem must points to at least sizeof(CallExpr)
3010-
/// + sizeof(Stmt *) bytes of storage, aligned to alignof(CallExpr):
3011-
///
3012-
/// \code{.cpp}
3013-
/// alignas(CallExpr) char Buffer[sizeof(CallExpr) + sizeof(Stmt *)];
3014-
/// CallExpr *TheCall = CallExpr::CreateTemporary(Buffer, etc);
3015-
/// \endcode
3016-
static CallExpr *CreateTemporary(void *Mem, Expr *Fn, QualType Ty,
3017-
ExprValueKind VK, SourceLocation RParenLoc,
3018-
ADLCallKind UsesADL = NotADL);
3019-
30203008
/// Create an empty call expression, for deserialization.
30213009
static CallExpr *CreateEmpty(const ASTContext &Ctx, unsigned NumArgs,
30223010
bool HasFPFeatures, EmptyShell Empty);

clang/lib/AST/Expr.cpp

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1509,16 +1509,6 @@ CallExpr *CallExpr::Create(const ASTContext &Ctx, Expr *Fn,
15091509
RParenLoc, FPFeatures, MinNumArgs, UsesADL);
15101510
}
15111511

1512-
CallExpr *CallExpr::CreateTemporary(void *Mem, Expr *Fn, QualType Ty,
1513-
ExprValueKind VK, SourceLocation RParenLoc,
1514-
ADLCallKind UsesADL) {
1515-
assert(!(reinterpret_cast<uintptr_t>(Mem) % alignof(CallExpr)) &&
1516-
"Misaligned memory in CallExpr::CreateTemporary!");
1517-
return new (Mem) CallExpr(CallExprClass, Fn, /*PreArgs=*/{}, /*Args=*/{}, Ty,
1518-
VK, RParenLoc, FPOptionsOverride(),
1519-
/*MinNumArgs=*/0, UsesADL);
1520-
}
1521-
15221512
CallExpr *CallExpr::CreateEmpty(const ASTContext &Ctx, unsigned NumArgs,
15231513
bool HasFPFeatures, EmptyShell Empty) {
15241514
unsigned SizeOfTrailingObjects =
@@ -1655,14 +1645,8 @@ SourceLocation CallExpr::getBeginLoc() const {
16551645
if (!isTypeDependent()) {
16561646
if (const auto *Method =
16571647
dyn_cast_if_present<const CXXMethodDecl>(getCalleeDecl());
1658-
Method && Method->isExplicitObjectMemberFunction()) {
1659-
// Note: while we typically expect the call to have a first argument
1660-
// here, we can't assert it because in some cases it does not, e.g.
1661-
// calls created with CallExpr::CreateTemporary() during overload
1662-
// resolution.
1663-
if (getNumArgs() > 0 && getArg(0))
1664-
return getArg(0)->getBeginLoc();
1665-
}
1648+
Method && Method->isExplicitObjectMemberFunction())
1649+
return getArg(0)->getBeginLoc();
16661650
}
16671651

16681652
SourceLocation begin = getCallee()->getBeginLoc();

clang/lib/Sema/SemaOverload.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8147,17 +8147,14 @@ void Sema::AddConversionCandidate(
81478147

81488148
ExprValueKind VK = Expr::getValueKindForType(ConversionType);
81498149

8150-
// Note that it is safe to allocate CallExpr on the stack here because
8151-
// there are 0 arguments (i.e., nothing is allocated using ASTContext's
8152-
// allocator).
81538150
QualType CallResultType = ConversionType.getNonLValueExprType(Context);
81548151

8155-
alignas(CallExpr) char Buffer[sizeof(CallExpr) + sizeof(Stmt *)];
8156-
CallExpr *TheTemporaryCall = CallExpr::CreateTemporary(
8157-
Buffer, &ConversionFn, CallResultType, VK, From->getBeginLoc());
8152+
// Introduce a temporary expression with the right type and value category
8153+
// that we can use for deduction purposes.
8154+
OpaqueValueExpr FakeCall(From->getBeginLoc(), CallResultType, VK);
81588155

81598156
ImplicitConversionSequence ICS =
8160-
TryCopyInitialization(*this, TheTemporaryCall, ToType,
8157+
TryCopyInitialization(*this, &FakeCall, ToType,
81618158
/*SuppressUserConversions=*/true,
81628159
/*InOverloadResolution=*/false,
81638160
/*AllowObjCWritebackConversion=*/false);

0 commit comments

Comments
 (0)