diff --git a/gen/classes.cpp b/gen/classes.cpp index bfc97832..7d5539ed 100644 --- a/gen/classes.cpp +++ b/gen/classes.cpp @@ -828,7 +828,8 @@ DValue* DtoNewClass(TypeClass* tc, NewExp* newexp) Logger::println("Resolving nested context"); LOG_SCOPE; - LLValue* gep = DtoGEPi(mem,0,2,"tmp"); + size_t idx = 2 + tc->sym->vthis->ir.irField->index; + LLValue* gep = DtoGEPi(mem,0,idx,"tmp"); // this value might be zero if it was not necessary to generate it ... LLValue* nest = gIR->func()->nestedVar; diff --git a/gen/llvmhelpers.cpp b/gen/llvmhelpers.cpp index c9735c50..4e0337d1 100644 --- a/gen/llvmhelpers.cpp +++ b/gen/llvmhelpers.cpp @@ -382,7 +382,7 @@ static LLValue* get_frame_ptr_impl(FuncDeclaration* func, Dsymbol* sc, LLValue* } else if (ClassDeclaration* cd = fd->toParent2()->isClassDeclaration()) { - v = DtoGEPi(v,0,2,"tmp"); + v = DtoGEPi(v,0,2+cd->vthis->ir.irField->index,"tmp"); v = DtoLoad(v); } else diff --git a/tests/mini/nested6a.d b/tests/mini/nested6a.d new file mode 100644 index 00000000..9b70419f --- /dev/null +++ b/tests/mini/nested6a.d @@ -0,0 +1,39 @@ +module nested6a; +extern(C) int printf(char*, ...); + +void main() +{ + int i = 42; + + printf("main() %d\n", i++); + + class C + { + int j; + void func() + { + int k; + printf("C.func() %d\n", i++); + + class C2 + { + int l; + void func2() + { + printf("C2.func2() %d\n", i++); + } + int m; + } + + { + scope c2 = new C2; + c2.func2(); + } + int n; + } + int o; + } + + scope c = new C; + c.func(); +}