@@ -1932,15 +1932,10 @@ bool Compiler<Emitter>::visitInitList(ArrayRef<const Expr *> Inits,
1932
1932
dyn_cast<EmbedExpr>(Init->IgnoreParenImpCasts ())) {
1933
1933
PrimType TargetT = classifyPrim (Init->getType ());
1934
1934
1935
- auto Eval = [&](const Expr *Init, unsigned ElemIndex) {
1936
- PrimType InitT = classifyPrim (Init->getType ());
1937
- if (!this ->visit (Init))
1935
+ auto Eval = [&](const IntegerLiteral *IL, unsigned ElemIndex) {
1936
+ if (!this ->emitConst (IL->getValue (), Init))
1938
1937
return false ;
1939
- if (InitT != TargetT) {
1940
- if (!this ->emitCast (InitT, TargetT, E))
1941
- return false ;
1942
- }
1943
- return this ->emitInitElem (TargetT, ElemIndex, Init);
1938
+ return this ->emitInitElem (TargetT, ElemIndex, IL);
1944
1939
};
1945
1940
if (!EmbedS->doForEachDataElement (Eval, ElementIndex))
1946
1941
return false ;
@@ -2062,21 +2057,36 @@ bool Compiler<Emitter>::visitArrayElemInit(unsigned ElemIndex, const Expr *Init,
2062
2057
template <class Emitter >
2063
2058
bool Compiler<Emitter>::visitCallArgs(ArrayRef<const Expr *> Args,
2064
2059
const FunctionDecl *FuncDecl,
2065
- bool Activate) {
2060
+ bool Activate, bool IsOperatorCall ) {
2066
2061
assert (VarScope->getKind () == ScopeKind::Call);
2067
2062
llvm::BitVector NonNullArgs;
2068
2063
if (FuncDecl && FuncDecl->hasAttr <NonNullAttr>())
2069
2064
NonNullArgs = collectNonNullArgs (FuncDecl, Args);
2070
2065
2066
+ bool ExplicitMemberFn = false ;
2067
+ if (const auto *MD = dyn_cast_if_present<CXXMethodDecl>(FuncDecl))
2068
+ ExplicitMemberFn = MD->isExplicitObjectMemberFunction ();
2069
+
2071
2070
unsigned ArgIndex = 0 ;
2072
2071
for (const Expr *Arg : Args) {
2073
2072
if (canClassify (Arg)) {
2074
2073
if (!this ->visit (Arg))
2075
2074
return false ;
2076
2075
} else {
2077
2076
2078
- std::optional<unsigned > LocalIndex = allocateLocal (
2079
- Arg, Arg->getType (), /* ExtendingDecl=*/ nullptr , ScopeKind::Call);
2077
+ DeclTy Source = Arg;
2078
+ if (FuncDecl) {
2079
+ // Try to use the parameter declaration instead of the argument
2080
+ // expression as a source.
2081
+ unsigned DeclIndex = ArgIndex - IsOperatorCall + ExplicitMemberFn;
2082
+ if (DeclIndex < FuncDecl->getNumParams ())
2083
+ Source = FuncDecl->getParamDecl (ArgIndex - IsOperatorCall +
2084
+ ExplicitMemberFn);
2085
+ }
2086
+
2087
+ std::optional<unsigned > LocalIndex =
2088
+ allocateLocal (std::move (Source), Arg->getType (),
2089
+ /* ExtendingDecl=*/ nullptr , ScopeKind::Call);
2080
2090
if (!LocalIndex)
2081
2091
return false ;
2082
2092
@@ -4489,14 +4499,6 @@ template <class Emitter>
4489
4499
unsigned Compiler<Emitter>::allocateLocalPrimitive(
4490
4500
DeclTy &&Src, PrimType Ty, bool IsConst, const ValueDecl *ExtendingDecl,
4491
4501
ScopeKind SC, bool IsConstexprUnknown) {
4492
- // Make sure we don't accidentally register the same decl twice.
4493
- if (const auto *VD =
4494
- dyn_cast_if_present<ValueDecl>(Src.dyn_cast <const Decl *>())) {
4495
- assert (!P.getGlobal (VD));
4496
- assert (!Locals.contains (VD));
4497
- (void )VD;
4498
- }
4499
-
4500
4502
// FIXME: There are cases where Src.is<Expr*>() is wrong, e.g.
4501
4503
// (int){12} in C. Consider using Expr::isTemporaryObject() instead
4502
4504
// or isa<MaterializeTemporaryExpr>().
@@ -4518,19 +4520,11 @@ std::optional<unsigned>
4518
4520
Compiler<Emitter>::allocateLocal(DeclTy &&Src, QualType Ty,
4519
4521
const ValueDecl *ExtendingDecl, ScopeKind SC,
4520
4522
bool IsConstexprUnknown) {
4521
- // Make sure we don't accidentally register the same decl twice.
4522
- if ([[maybe_unused]] const auto *VD =
4523
- dyn_cast_if_present<ValueDecl>(Src.dyn_cast <const Decl *>())) {
4524
- assert (!P.getGlobal (VD));
4525
- assert (!Locals.contains (VD));
4526
- }
4527
-
4528
4523
const ValueDecl *Key = nullptr ;
4529
4524
const Expr *Init = nullptr ;
4530
4525
bool IsTemporary = false ;
4531
4526
if (auto *VD = dyn_cast_if_present<ValueDecl>(Src.dyn_cast <const Decl *>())) {
4532
4527
Key = VD;
4533
- Ty = VD->getType ();
4534
4528
4535
4529
if (const auto *VarD = dyn_cast<VarDecl>(VD))
4536
4530
Init = VarD->getInit ();
@@ -5167,7 +5161,8 @@ bool Compiler<Emitter>::VisitCallExpr(const CallExpr *E) {
5167
5161
return false ;
5168
5162
}
5169
5163
5170
- if (!this ->visitCallArgs (Args, FuncDecl, IsAssignmentOperatorCall))
5164
+ if (!this ->visitCallArgs (Args, FuncDecl, IsAssignmentOperatorCall,
5165
+ isa<CXXOperatorCallExpr>(E)))
5171
5166
return false ;
5172
5167
5173
5168
// Undo the argument reversal we did earlier.
0 commit comments