Fixed problems with nested 'this'. Fixes #39 .

Fixed problem with debug info order of intrinsic calls (func.start after declare).
This commit is contained in:
Tomas Lindquist Olsen 2008-08-02 00:50:39 +02:00
parent 3c5e28d6c7
commit e31070a437
5 changed files with 42 additions and 15 deletions

View file

@ -559,6 +559,9 @@ void DtoDefineFunc(FuncDeclaration* fd)
llvm::Instruction* allocaPoint = new llvm::AllocaInst(LLType::Int32Ty, "alloca point", beginbb); llvm::Instruction* allocaPoint = new llvm::AllocaInst(LLType::Int32Ty, "alloca point", beginbb);
gIR->func()->allocapoint = allocaPoint; 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) // need result variable? (not nested)
if (fd->vresult && !fd->vresult->nestedref) { if (fd->vresult && !fd->vresult->nestedref) {
Logger::println("non-nested vresult value"); Logger::println("non-nested vresult value");
@ -625,9 +628,6 @@ void DtoDefineFunc(FuncDeclaration* fd)
} }
} }
// debug info
if (global.params.symdebug) DtoDwarfFuncStart(fd);
LLValue* parentNested = NULL; LLValue* parentNested = NULL;
if (FuncDeclaration* fd2 = fd->toParent2()->isFuncDeclaration()) { if (FuncDeclaration* fd2 = fd->toParent2()->isFuncDeclaration()) {
if (!fd->isStatic()) // huh? if (!fd->isStatic()) // huh?

View file

@ -485,14 +485,6 @@ LLValue* DtoNestedVariable(VarDeclaration* vd)
LLValue* ptr = DtoNestedContext(func); LLValue* ptr = DtoNestedContext(func);
assert(ptr && "nested var, but no context"); 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 // handle a "normal" nested variable
// we must cast here to be sure. nested classes just have a void* // we must cast here to be sure. nested classes just have a void*

View file

@ -969,6 +969,7 @@ DValue* ThisExp::toElem(IRState* p)
// this seems to happen for dmd generated assert statements like: // this seems to happen for dmd generated assert statements like:
// assert(this, "null this"); // assert(this, "null this");
// FIXME: check for TOKthis in AssertExp instead
if (!var) if (!var)
{ {
LLValue* v = p->func()->thisVar; LLValue* v = p->func()->thisVar;
@ -978,9 +979,16 @@ DValue* ThisExp::toElem(IRState* p)
// regular this expr // regular this expr
else if (VarDeclaration* vd = var->isVarDeclaration()) { else if (VarDeclaration* vd = var->isVarDeclaration()) {
LLValue* v; LLValue* 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; v = p->func()->decl->ir.irFunc->thisVar;
if (llvm::isa<llvm::AllocaInst>(v)) if (llvm::isa<llvm::AllocaInst>(v))
v = DtoLoad(v); v = DtoLoad(v);
}
const LLType* t = DtoType(type); const LLType* t = DtoType(type);
if (v->getType() != t) if (v->getType() != t)
v = DtoBitCast(v, t); v = DtoBitCast(v, t);

View file

@ -1,4 +1,4 @@
profile=tango ignore=object
compiler=llvmdc compiler=llvmdc
inifile=llvmdc.conf inifile=llvmdc.conf

27
tests/mini/nested14.d Normal file
View file

@ -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();
}