mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-05-08 03:46:02 +03:00
Traverse full chain of nested aggregates when resolving a nested variable (#3558)
Fixes #3556.
This commit is contained in:
parent
f1295903f2
commit
1700e30c20
2 changed files with 64 additions and 17 deletions
|
@ -66,16 +66,16 @@ DValue *DtoNestedVariable(Loc &loc, Type *astype, VarDeclaration *vd,
|
|||
if (currentCtx) {
|
||||
Logger::println("Using own nested context of current function");
|
||||
ctx = currentCtx;
|
||||
} else if (irfunc->decl->isMember2()) {
|
||||
} else if (AggregateDeclaration *ad = irfunc->decl->isMember2()) {
|
||||
Logger::println(
|
||||
"Current function is member of nested class, loading vthis");
|
||||
|
||||
AggregateDeclaration *cd = irfunc->decl->isMember2();
|
||||
LLValue *val = irfunc->thisArg;
|
||||
if (cd->isClassDeclaration()) {
|
||||
val = DtoLoad(val);
|
||||
LLValue *val =
|
||||
ad->isClassDeclaration() ? DtoLoad(irfunc->thisArg) : irfunc->thisArg;
|
||||
for (; ad; ad = ad->toParent2()->isAggregateDeclaration()) {
|
||||
assert(ad->vthis);
|
||||
val = DtoLoad(DtoGEP(val, 0, getVthisIdx(ad), ".vthis"));
|
||||
}
|
||||
ctx = DtoLoad(DtoGEP(val, 0, getVthisIdx(cd), ".vthis"));
|
||||
ctx = val;
|
||||
skipDIDeclaration = true;
|
||||
} else {
|
||||
Logger::println("Regular nested function, using context arg");
|
||||
|
@ -455,17 +455,13 @@ void DtoCreateNestedContext(FuncGenState &funcGen) {
|
|||
LLValue *src = irFunc.nestArg;
|
||||
if (!src) {
|
||||
assert(irFunc.thisArg);
|
||||
assert(fd->isMember2());
|
||||
LLValue *thisval = DtoLoad(irFunc.thisArg);
|
||||
AggregateDeclaration *cd = fd->isMember2();
|
||||
assert(cd);
|
||||
assert(cd->vthis);
|
||||
AggregateDeclaration *ad = fd->isMember2();
|
||||
assert(ad);
|
||||
assert(ad->vthis);
|
||||
LLValue *thisptr =
|
||||
ad->isClassDeclaration() ? DtoLoad(irFunc.thisArg) : irFunc.thisArg;
|
||||
IF_LOG Logger::println("Indexing to 'this'");
|
||||
if (cd->isStructDeclaration()) {
|
||||
src = DtoExtractValue(thisval, getVthisIdx(cd), ".vthis");
|
||||
} else {
|
||||
src = DtoLoad(DtoGEP(thisval, 0, getVthisIdx(cd), ".vthis"));
|
||||
}
|
||||
src = DtoLoad(DtoGEP(thisptr, 0, getVthisIdx(ad), ".vthis"));
|
||||
}
|
||||
if (depth > 1) {
|
||||
src = DtoBitCast(src, getVoidPtrType());
|
||||
|
|
51
tests/codegen/nested_gh3556.d
Normal file
51
tests/codegen/nested_gh3556.d
Normal file
|
@ -0,0 +1,51 @@
|
|||
// https://github.com/ldc-developers/ldc/issues/3556
|
||||
// RUN: %ldc -run %s
|
||||
|
||||
class C {
|
||||
int counter = 1;
|
||||
|
||||
void test1() {
|
||||
assert(counter == 1);
|
||||
++counter;
|
||||
}
|
||||
|
||||
void run1() {
|
||||
class C2 {
|
||||
int counter2 = 11;
|
||||
|
||||
class C3 {
|
||||
void run3() {
|
||||
test1();
|
||||
test2();
|
||||
++counter;
|
||||
++counter2;
|
||||
}
|
||||
}
|
||||
|
||||
void test2() {
|
||||
assert(counter == 2);
|
||||
++counter;
|
||||
assert(counter2 == 11);
|
||||
++counter2;
|
||||
}
|
||||
|
||||
void run2() {
|
||||
auto c3 = new C3;
|
||||
c3.run3();
|
||||
++counter;
|
||||
++counter2;
|
||||
}
|
||||
}
|
||||
|
||||
auto c2 = new C2;
|
||||
c2.run2();
|
||||
assert(c2.counter2 == 14);
|
||||
++counter;
|
||||
}
|
||||
}
|
||||
|
||||
void main() {
|
||||
auto c = new C;
|
||||
c.run1();
|
||||
assert(c.counter == 6);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue