@@ -1842,7 +1842,6 @@ bool Compiler<Emitter>::visitInitList(ArrayRef<const Expr *> Inits,
18421842 const Expr *Init, PrimType T,
18431843 bool Activate = false ) -> bool {
18441844 InitStackScope<Emitter> ISS (this , isa<CXXDefaultInitExpr>(Init));
1845- InitLinkScope<Emitter> ILS (this , InitLink::Field (FieldToInit->Offset ));
18461845 if (!this ->visit (Init))
18471846 return false ;
18481847
@@ -5385,55 +5384,57 @@ bool Compiler<Emitter>::VisitCXXThisExpr(const CXXThisExpr *E) {
53855384 // instance pointer of the current function frame, but e.g. to the declaration
53865385 // currently being initialized. Here we emit the necessary instruction(s) for
53875386 // this scenario.
5388- if (!InitStackActive)
5387+ if (!InitStackActive || InitStack. empty () )
53895388 return this ->emitThis (E);
53905389
5391- if (!InitStack.empty ()) {
5392- // If our init stack is, for example:
5393- // 0 Stack: 3 (decl)
5394- // 1 Stack: 6 (init list)
5395- // 2 Stack: 1 (field)
5396- // 3 Stack: 6 (init list)
5397- // 4 Stack: 1 (field)
5398- //
5399- // We want to find the LAST element in it that's an init list,
5400- // which is marked with the K_InitList marker. The index right
5401- // before that points to an init list. We need to find the
5402- // elements before the K_InitList element that point to a base
5403- // (e.g. a decl or This), optionally followed by field, elem, etc.
5404- // In the example above, we want to emit elements [0..2].
5405- unsigned StartIndex = 0 ;
5406- unsigned EndIndex = 0 ;
5407- // Find the init list.
5408- for (StartIndex = InitStack.size () - 1 ; StartIndex > 0 ; --StartIndex) {
5409- if (InitStack[StartIndex].Kind == InitLink::K_InitList ||
5410- InitStack[StartIndex].Kind == InitLink::K_This) {
5411- EndIndex = StartIndex;
5412- --StartIndex;
5413- break ;
5414- }
5390+ // If our init stack is, for example:
5391+ // 0 Stack: 3 (decl)
5392+ // 1 Stack: 6 (init list)
5393+ // 2 Stack: 1 (field)
5394+ // 3 Stack: 6 (init list)
5395+ // 4 Stack: 1 (field)
5396+ //
5397+ // We want to find the LAST element in it that's an init list,
5398+ // which is marked with the K_InitList marker. The index right
5399+ // before that points to an init list. We need to find the
5400+ // elements before the K_InitList element that point to a base
5401+ // (e.g. a decl or This), optionally followed by field, elem, etc.
5402+ // In the example above, we want to emit elements [0..2].
5403+ unsigned StartIndex = 0 ;
5404+ unsigned EndIndex = 0 ;
5405+ // Find the init list.
5406+ for (StartIndex = InitStack.size () - 1 ; StartIndex > 0 ; --StartIndex) {
5407+ if (InitStack[StartIndex].Kind == InitLink::K_InitList ||
5408+ InitStack[StartIndex].Kind == InitLink::K_This) {
5409+ EndIndex = StartIndex;
5410+ --StartIndex;
5411+ break ;
54155412 }
5413+ }
54165414
5417- // Walk backwards to find the base.
5418- for (; StartIndex > 0 ; --StartIndex) {
5419- if (InitStack[StartIndex].Kind == InitLink::K_InitList)
5420- continue ;
5415+ // Walk backwards to find the base.
5416+ for (; StartIndex > 0 ; --StartIndex) {
5417+ if (InitStack[StartIndex].Kind == InitLink::K_InitList)
5418+ continue ;
54215419
5422- if (InitStack[StartIndex].Kind != InitLink::K_Field &&
5423- InitStack[StartIndex].Kind != InitLink::K_Elem)
5424- break ;
5425- }
5420+ if (InitStack[StartIndex].Kind != InitLink::K_Field &&
5421+ InitStack[StartIndex].Kind != InitLink::K_Elem)
5422+ break ;
5423+ }
54265424
5427- // Emit the instructions.
5428- for (unsigned I = StartIndex; I != EndIndex; ++I) {
5429- if (InitStack[I].Kind == InitLink::K_InitList)
5430- continue ;
5431- if (!InitStack[I].template emit <Emitter>(this , E))
5432- return false ;
5433- }
5434- return true ;
5425+ if (StartIndex == 0 && EndIndex == 0 )
5426+ EndIndex = InitStack.size () - 1 ;
5427+
5428+ assert (StartIndex < EndIndex);
5429+
5430+ // Emit the instructions.
5431+ for (unsigned I = StartIndex; I != (EndIndex + 1 ); ++I) {
5432+ if (InitStack[I].Kind == InitLink::K_InitList)
5433+ continue ;
5434+ if (!InitStack[I].template emit <Emitter>(this , E))
5435+ return false ;
54355436 }
5436- return this -> emitThis (E) ;
5437+ return true ;
54375438}
54385439
54395440template <class Emitter > bool Compiler<Emitter>::visitStmt(const Stmt *S) {
@@ -6295,6 +6296,10 @@ bool Compiler<Emitter>::compileConstructor(const CXXConstructorDecl *Ctor) {
62956296 }
62966297 assert (NestedField);
62976298
6299+ unsigned FirstLinkOffset =
6300+ R->getField (cast<FieldDecl>(IFD->chain ()[0 ]))->Offset ;
6301+ InitStackScope<Emitter> ISS (this , isa<CXXDefaultInitExpr>(InitExpr));
6302+ InitLinkScope<Emitter> ILS (this , InitLink::Field (FirstLinkOffset));
62986303 if (!emitFieldInitializer (NestedField, NestedFieldOffset, InitExpr,
62996304 IsUnion))
63006305 return false ;
0 commit comments