@@ -85,8 +85,12 @@ bool InitLink::emit(Compiler<Emitter> *Ctx, const Expr *E) const {
85
85
case K_Field:
86
86
// We're assuming there's a base pointer on the stack already.
87
87
return Ctx->emitGetPtrFieldPop (Offset, E);
88
+ case K_Temp:
89
+ return Ctx->emitGetPtrLocal (Offset, E);
88
90
case K_Decl:
89
91
return Ctx->visitDeclRef (D, E);
92
+ default :
93
+ llvm_unreachable (" Unhandled InitLink kind" );
90
94
}
91
95
return true ;
92
96
}
@@ -1330,6 +1334,7 @@ bool Compiler<Emitter>::visitInitList(ArrayRef<const Expr *> Inits,
1330
1334
1331
1335
auto initCompositeField = [=](const Record::Field *FieldToInit,
1332
1336
const Expr *Init) -> bool {
1337
+ InitLinkScope<Emitter> ILS (this , InitLink::Field (FieldToInit->Offset ));
1333
1338
// Non-primitive case. Get a pointer to the field-to-initialize
1334
1339
// on the stack and recurse into visitInitializer().
1335
1340
if (!this ->emitGetPtrField (FieldToInit->Offset , Init))
@@ -2271,6 +2276,7 @@ bool Compiler<Emitter>::VisitMaterializeTemporaryExpr(
2271
2276
const Expr *Inner = E->getSubExpr ()->skipRValueSubobjectAdjustments ();
2272
2277
if (std::optional<unsigned > LocalIndex =
2273
2278
allocateLocal (Inner, E->getExtendingDecl ())) {
2279
+ InitLinkScope<Emitter> ILS (this , InitLink::Temp (*LocalIndex));
2274
2280
if (!this ->emitGetPtrLocal (*LocalIndex, E))
2275
2281
return false ;
2276
2282
return this ->visitInitializer (SubExpr);
@@ -2449,6 +2455,7 @@ bool Compiler<Emitter>::VisitCXXConstructExpr(const CXXConstructExpr *E) {
2449
2455
2450
2456
// Trivial copy/move constructor. Avoid copy.
2451
2457
if (Ctor->isDefaulted () && Ctor->isCopyOrMoveConstructor () &&
2458
+ Ctor->isTrivial () &&
2452
2459
E->getArg (0 )->isTemporaryObject (Ctx.getASTContext (),
2453
2460
T->getAsCXXRecordDecl ()))
2454
2461
return this ->visitInitializer (E->getArg (0 ));
@@ -3583,6 +3590,7 @@ VarCreationState Compiler<Emitter>::visitVarDecl(const VarDecl *VD, bool Topleve
3583
3590
return !Init || (checkDecl () && initGlobal (*GlobalIndex));
3584
3591
} else {
3585
3592
VariableScope<Emitter> LocalScope (this , VD);
3593
+ InitLinkScope<Emitter> ILS (this , InitLink::Decl (VD));
3586
3594
3587
3595
if (VarT) {
3588
3596
unsigned Offset = this ->allocateLocalPrimitive (
@@ -3917,7 +3925,8 @@ bool Compiler<Emitter>::VisitCXXDefaultInitExpr(const CXXDefaultInitExpr *E) {
3917
3925
SourceLocScope<Emitter> SLS (this , E);
3918
3926
3919
3927
bool Old = InitStackActive;
3920
- InitStackActive = !isa<FunctionDecl>(E->getUsedContext ());
3928
+ InitStackActive =
3929
+ !(E->getUsedContext ()->getDeclKind () == Decl::CXXConstructor);
3921
3930
bool Result = this ->delegate (E->getExpr ());
3922
3931
InitStackActive = Old;
3923
3932
return Result;
@@ -3979,8 +3988,14 @@ bool Compiler<Emitter>::VisitCXXThisExpr(const CXXThisExpr *E) {
3979
3988
// currently being initialized. Here we emit the necessary instruction(s) for
3980
3989
// this scenario.
3981
3990
if (InitStackActive && !InitStack.empty ()) {
3982
- for (const InitLink &IL : InitStack) {
3983
- if (!IL.emit <Emitter>(this , E))
3991
+ unsigned StartIndex = 0 ;
3992
+ for (StartIndex = InitStack.size () - 1 ; StartIndex > 0 ; --StartIndex) {
3993
+ if (InitStack[StartIndex].Kind != InitLink::K_Field)
3994
+ break ;
3995
+ }
3996
+
3997
+ for (unsigned I = StartIndex, N = InitStack.size (); I != N; ++I) {
3998
+ if (!InitStack[I].emit <Emitter>(this , E))
3984
3999
return false ;
3985
4000
}
3986
4001
return true ;
0 commit comments