@@ -66,16 +66,16 @@ DValue *DtoNestedVariable(Loc &loc, Type *astype, VarDeclaration *vd,
66
66
if (currentCtx) {
67
67
Logger::println (" Using own nested context of current function" );
68
68
ctx = currentCtx;
69
- } else if (irfunc->decl ->isMember2 ()) {
69
+ } else if (AggregateDeclaration *ad = irfunc->decl ->isMember2 ()) {
70
70
Logger::println (
71
71
" Current function is member of nested class, loading vthis" );
72
-
73
- AggregateDeclaration *cd = irfunc-> decl -> isMember2 () ;
74
- LLValue *val = irfunc-> thisArg ;
75
- if (cd-> isClassDeclaration ()) {
76
- val = DtoLoad (val);
72
+ LLValue *val =
73
+ ad-> isClassDeclaration () ? DtoLoad (irfunc-> thisArg ) : irfunc-> thisArg ;
74
+ for (; ad; ad = ad-> toParent2 ()-> isAggregateDeclaration ()) {
75
+ assert (ad-> vthis );
76
+ val = DtoLoad (DtoGEP ( val, 0 , getVthisIdx (ad), " .vthis " ) );
77
77
}
78
- ctx = DtoLoad ( DtoGEP ( val, 0 , getVthisIdx (cd), " .vthis " )) ;
78
+ ctx = val;
79
79
skipDIDeclaration = true ;
80
80
} else {
81
81
Logger::println (" Regular nested function, using context arg" );
@@ -455,17 +455,13 @@ void DtoCreateNestedContext(FuncGenState &funcGen) {
455
455
LLValue *src = irFunc.nestArg ;
456
456
if (!src) {
457
457
assert (irFunc.thisArg );
458
- assert ( fd->isMember2 () );
459
- LLValue *thisval = DtoLoad (irFunc. thisArg );
460
- AggregateDeclaration *cd = fd-> isMember2 ( );
461
- assert (cd);
462
- assert (cd-> vthis ) ;
458
+ AggregateDeclaration *ad = fd->isMember2 ();
459
+ assert (ad );
460
+ assert (ad-> vthis );
461
+ LLValue *thisptr =
462
+ ad-> isClassDeclaration () ? DtoLoad (irFunc. thisArg ) : irFunc. thisArg ;
463
463
IF_LOG Logger::println (" Indexing to 'this'" );
464
- if (cd->isStructDeclaration ()) {
465
- src = DtoExtractValue (thisval, getVthisIdx (cd), " .vthis" );
466
- } else {
467
- src = DtoLoad (DtoGEP (thisval, 0 , getVthisIdx (cd), " .vthis" ));
468
- }
464
+ src = DtoLoad (DtoGEP (thisptr, 0 , getVthisIdx (ad), " .vthis" ));
469
465
}
470
466
if (depth > 1 ) {
471
467
src = DtoBitCast (src, getVoidPtrType ());
0 commit comments