# HG changeset patch # User Tomas Lindquist Olsen # Date 1217631039 -7200 # Node ID 30ef3c7bddca93a4aefa26b3af1e4db2f8121045 # Parent 4d9108f1fbf418eecccab54d683fdad386a5846e Fixed problems with nested 'this'. Fixes #39 . Fixed problem with debug info order of intrinsic calls (func.start after declare). diff -r 4d9108f1fbf4 -r 30ef3c7bddca gen/functions.cpp --- a/gen/functions.cpp Fri Aug 01 21:56:13 2008 +0200 +++ b/gen/functions.cpp Sat Aug 02 00:50:39 2008 +0200 @@ -559,6 +559,9 @@ llvm::Instruction* allocaPoint = new llvm::AllocaInst(LLType::Int32Ty, "alloca point", beginbb); gIR->func()->allocapoint = allocaPoint; + // debug info - after all allocas, but before any llvm.dbg.declare etc + if (global.params.symdebug) DtoDwarfFuncStart(fd); + // need result variable? (not nested) if (fd->vresult && !fd->vresult->nestedref) { Logger::println("non-nested vresult value"); @@ -625,9 +628,6 @@ } } - // debug info - if (global.params.symdebug) DtoDwarfFuncStart(fd); - LLValue* parentNested = NULL; if (FuncDeclaration* fd2 = fd->toParent2()->isFuncDeclaration()) { if (!fd->isStatic()) // huh? diff -r 4d9108f1fbf4 -r 30ef3c7bddca gen/llvmhelpers.cpp --- a/gen/llvmhelpers.cpp Fri Aug 01 21:56:13 2008 +0200 +++ b/gen/llvmhelpers.cpp Sat Aug 02 00:50:39 2008 +0200 @@ -485,14 +485,6 @@ LLValue* ptr = DtoNestedContext(func); assert(ptr && "nested var, but no context"); - // if the nested var is a this pointer it's a class member and not a magic struct - // so we're done here! - // this happens since 1.033 for some reason... always correct ? - if (vd->ident == Id::This) - { - return ptr; - } - // handle a "normal" nested variable // we must cast here to be sure. nested classes just have a void* diff -r 4d9108f1fbf4 -r 30ef3c7bddca gen/toir.cpp --- a/gen/toir.cpp Fri Aug 01 21:56:13 2008 +0200 +++ b/gen/toir.cpp Sat Aug 02 00:50:39 2008 +0200 @@ -969,6 +969,7 @@ // this seems to happen for dmd generated assert statements like: // assert(this, "null this"); + // FIXME: check for TOKthis in AssertExp instead if (!var) { LLValue* v = p->func()->thisVar; @@ -978,9 +979,16 @@ // regular this expr else if (VarDeclaration* vd = var->isVarDeclaration()) { LLValue* v; - v = p->func()->decl->ir.irFunc->thisVar; - if (llvm::isa(v)) - v = DtoLoad(v); + if (vd->toParent2() != p->func()->decl) { + Logger::println("nested this exp"); + v = DtoLoad(DtoNestedVariable(vd)); + } + else { + Logger::println("normal this exp"); + v = p->func()->decl->ir.irFunc->thisVar; + if (llvm::isa(v)) + v = DtoLoad(v); + } const LLType* t = DtoType(type); if (v->getType() != t) v = DtoBitCast(v, t); diff -r 4d9108f1fbf4 -r 30ef3c7bddca llvmdc-tango --- a/llvmdc-tango Fri Aug 01 21:56:13 2008 +0200 +++ b/llvmdc-tango Sat Aug 02 00:50:39 2008 +0200 @@ -1,4 +1,4 @@ -profile=tango +ignore=object compiler=llvmdc inifile=llvmdc.conf diff -r 4d9108f1fbf4 -r 30ef3c7bddca tests/mini/nested14.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/mini/nested14.d Sat Aug 02 00:50:39 2008 +0200 @@ -0,0 +1,27 @@ +module mini.nested14; + +extern(C) int printf(char*, ...); + +class C +{ + void foo() + { + void bar() + { + car(); + } + + bar(); + } + + void car() + { + printf("great\n"); + } +} + +void main() +{ + scope c = new C; + c.foo(); +}