@@ -667,8 +667,8 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) {
667667 }
668668
669669 case CK_VectorSplat: {
670- assert (!classify (CE->getType ()));
671- assert (classify (SubExpr->getType ()));
670+ assert (!canClassify (CE->getType ()));
671+ assert (canClassify (SubExpr->getType ()));
672672 assert (CE->getType ()->isVectorType ());
673673
674674 if (!Initializing) {
@@ -1932,15 +1932,10 @@ bool Compiler<Emitter>::visitInitList(ArrayRef<const Expr *> Inits,
19321932 dyn_cast<EmbedExpr>(Init->IgnoreParenImpCasts ())) {
19331933 PrimType TargetT = classifyPrim (Init->getType ());
19341934
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))
19381937 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);
19441939 };
19451940 if (!EmbedS->doForEachDataElement (Eval, ElementIndex))
19461941 return false ;
@@ -2062,21 +2057,36 @@ bool Compiler<Emitter>::visitArrayElemInit(unsigned ElemIndex, const Expr *Init,
20622057template <class Emitter >
20632058bool Compiler<Emitter>::visitCallArgs(ArrayRef<const Expr *> Args,
20642059 const FunctionDecl *FuncDecl,
2065- bool Activate) {
2060+ bool Activate, bool IsOperatorCall ) {
20662061 assert (VarScope->getKind () == ScopeKind::Call);
20672062 llvm::BitVector NonNullArgs;
20682063 if (FuncDecl && FuncDecl->hasAttr <NonNullAttr>())
20692064 NonNullArgs = collectNonNullArgs (FuncDecl, Args);
20702065
2066+ bool ExplicitMemberFn = false ;
2067+ if (const auto *MD = dyn_cast_if_present<CXXMethodDecl>(FuncDecl))
2068+ ExplicitMemberFn = MD->isExplicitObjectMemberFunction ();
2069+
20712070 unsigned ArgIndex = 0 ;
20722071 for (const Expr *Arg : Args) {
2073- if (OptPrimType T = classify (Arg)) {
2072+ if (canClassify (Arg)) {
20742073 if (!this ->visit (Arg))
20752074 return false ;
20762075 } else {
20772076
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);
20802090 if (!LocalIndex)
20812091 return false ;
20822092
@@ -3155,7 +3165,7 @@ bool Compiler<Emitter>::VisitCXXNoexceptExpr(const CXXNoexceptExpr *E) {
31553165template <class Emitter >
31563166bool Compiler<Emitter>::VisitCXXConstructExpr(const CXXConstructExpr *E) {
31573167 QualType T = E->getType ();
3158- assert (!classify (T));
3168+ assert (!canClassify (T));
31593169
31603170 if (T->isRecordType ()) {
31613171 const CXXConstructorDecl *Ctor = E->getConstructor ();
@@ -4150,7 +4160,7 @@ template <class Emitter> bool Compiler<Emitter>::visit(const Expr *E) {
41504160
41514161 // Create local variable to hold the return value.
41524162 if (!E->isGLValue () && !E->getType ()->isAnyComplexType () &&
4153- !classify (E->getType ())) {
4163+ !canClassify (E->getType ())) {
41544164 std::optional<unsigned > LocalIndex = allocateLocal (E);
41554165 if (!LocalIndex)
41564166 return false ;
@@ -4170,7 +4180,7 @@ template <class Emitter> bool Compiler<Emitter>::visit(const Expr *E) {
41704180
41714181template <class Emitter >
41724182bool Compiler<Emitter>::visitInitializer(const Expr *E) {
4173- assert (!classify (E->getType ()));
4183+ assert (!canClassify (E->getType ()));
41744184
41754185 OptionScope<Emitter> Scope (this , /* NewDiscardResult=*/ false ,
41764186 /* NewInitializing=*/ true );
@@ -4377,7 +4387,7 @@ bool Compiler<Emitter>::visitZeroArrayInitializer(QualType T, const Expr *E) {
43774387template <class Emitter >
43784388bool Compiler<Emitter>::visitAssignment(const Expr *LHS, const Expr *RHS,
43794389 const Expr *E) {
4380- if (!classify (E->getType ()))
4390+ if (!canClassify (E->getType ()))
43814391 return false ;
43824392
43834393 if (!this ->visit (RHS))
@@ -4489,14 +4499,6 @@ template <class Emitter>
44894499unsigned Compiler<Emitter>::allocateLocalPrimitive(
44904500 DeclTy &&Src, PrimType Ty, bool IsConst, const ValueDecl *ExtendingDecl,
44914501 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-
45004502 // FIXME: There are cases where Src.is<Expr*>() is wrong, e.g.
45014503 // (int){12} in C. Consider using Expr::isTemporaryObject() instead
45024504 // or isa<MaterializeTemporaryExpr>().
@@ -4518,19 +4520,11 @@ std::optional<unsigned>
45184520Compiler<Emitter>::allocateLocal(DeclTy &&Src, QualType Ty,
45194521 const ValueDecl *ExtendingDecl, ScopeKind SC,
45204522 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-
45284523 const ValueDecl *Key = nullptr ;
45294524 const Expr *Init = nullptr ;
45304525 bool IsTemporary = false ;
45314526 if (auto *VD = dyn_cast_if_present<ValueDecl>(Src.dyn_cast <const Decl *>())) {
45324527 Key = VD;
4533- Ty = VD->getType ();
45344528
45354529 if (const auto *VarD = dyn_cast<VarDecl>(VD))
45364530 Init = VarD->getInit ();
@@ -5167,7 +5161,8 @@ bool Compiler<Emitter>::VisitCallExpr(const CallExpr *E) {
51675161 return false ;
51685162 }
51695163
5170- if (!this ->visitCallArgs (Args, FuncDecl, IsAssignmentOperatorCall))
5164+ if (!this ->visitCallArgs (Args, FuncDecl, IsAssignmentOperatorCall,
5165+ isa<CXXOperatorCallExpr>(E)))
51715166 return false ;
51725167
51735168 // Undo the argument reversal we did earlier.
@@ -7140,10 +7135,6 @@ bool Compiler<Emitter>::emitDestruction(const Descriptor *Desc,
71407135 assert (!Desc->isPrimitive ());
71417136 assert (!Desc->isPrimitiveArray ());
71427137
7143- // Can happen if the decl is invalid.
7144- if (Desc->isDummy ())
7145- return true ;
7146-
71477138 // Arrays.
71487139 if (Desc->isArray ()) {
71497140 const Descriptor *ElemDesc = Desc->ElemDesc ;
0 commit comments