From 59d1ec5e0b19b4e3916e1bc49a21ef766040922f Mon Sep 17 00:00:00 2001 From: Alexey Prokhin Date: Fri, 5 Nov 2010 11:55:23 +0300 Subject: [PATCH] Another fix for nested context in structs. --- gen/nested.cpp | 4 ++-- gen/nested.h | 2 +- gen/toir.cpp | 4 ++++ 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/gen/nested.cpp b/gen/nested.cpp index 1bd252c1..27a9d47d 100644 --- a/gen/nested.cpp +++ b/gen/nested.cpp @@ -68,7 +68,7 @@ static FuncDeclaration* getParentFunc(Dsymbol* sym, bool stopOnStatic) { return (parent ? parent->isFuncDeclaration() : NULL); } -DValue* DtoNestedVariable(Loc loc, Type* astype, VarDeclaration* vd) +DValue* DtoNestedVariable(Loc loc, Type* astype, VarDeclaration* vd, bool byref) { Logger::println("DtoNestedVariable for %s @ %s", vd->toChars(), loc.toChars()); LOG_SCOPE; @@ -150,7 +150,7 @@ DValue* DtoNestedVariable(Loc loc, Type* astype, VarDeclaration* vd) val = DtoGEPi(val, 0, vd->ir.irLocal->nestedIndex, vd->toChars()); Logger::cout() << "Addr: " << *val << '\n'; Logger::cout() << "of type: " << *val->getType() << '\n'; - if (vd->ir.irLocal->byref) { + if (vd->ir.irLocal->byref || byref) { val = DtoAlignedLoad(val); Logger::cout() << "Was byref, now: " << *val << '\n'; Logger::cout() << "of type: " << *val->getType() << '\n'; diff --git a/gen/nested.h b/gen/nested.h index 088bafa4..ea3c6746 100644 --- a/gen/nested.h +++ b/gen/nested.h @@ -28,6 +28,6 @@ LLValue* DtoResolveNestedContext(Loc loc, ClassDeclaration *decl, LLValue *value llvm::Value* DtoNestedContext(Loc loc, Dsymbol* sym); /// Gets the DValue of a nested variable with arbitrary nesting. -DValue* DtoNestedVariable(Loc loc, Type* astype, VarDeclaration* vd); +DValue* DtoNestedVariable(Loc loc, Type* astype, VarDeclaration* vd, bool byref = false); #endif diff --git a/gen/toir.cpp b/gen/toir.cpp index 3bea4b55..78d4bbf4 100644 --- a/gen/toir.cpp +++ b/gen/toir.cpp @@ -1202,7 +1202,11 @@ DValue* ThisExp::toElem(IRState* p) LLValue* v; if (vd->toParent2() != p->func()->decl) { Logger::println("nested this exp"); +#if STRUCTTHISREF + return DtoNestedVariable(loc, type, vd, type->ty == Tstruct); +#else return DtoNestedVariable(loc, type, vd); +#endif } else { Logger::println("normal this exp");