mirror of
https://github.com/xomboverlord/ldc.git
synced 2026-01-11 18:33:14 +01:00
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:
@@ -559,6 +559,9 @@ void DtoDefineFunc(FuncDeclaration* fd)
|
||||
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 @@ void DtoDefineFunc(FuncDeclaration* fd)
|
||||
}
|
||||
}
|
||||
|
||||
// debug info
|
||||
if (global.params.symdebug) DtoDwarfFuncStart(fd);
|
||||
|
||||
LLValue* parentNested = NULL;
|
||||
if (FuncDeclaration* fd2 = fd->toParent2()->isFuncDeclaration()) {
|
||||
if (!fd->isStatic()) // huh?
|
||||
|
||||
@@ -485,14 +485,6 @@ LLValue* DtoNestedVariable(VarDeclaration* vd)
|
||||
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*
|
||||
|
||||
14
gen/toir.cpp
14
gen/toir.cpp
@@ -969,6 +969,7 @@ DValue* ThisExp::toElem(IRState* p)
|
||||
|
||||
// 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 @@ DValue* ThisExp::toElem(IRState* p)
|
||||
// regular this expr
|
||||
else if (VarDeclaration* vd = var->isVarDeclaration()) {
|
||||
LLValue* v;
|
||||
v = p->func()->decl->ir.irFunc->thisVar;
|
||||
if (llvm::isa<llvm::AllocaInst>(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<llvm::AllocaInst>(v))
|
||||
v = DtoLoad(v);
|
||||
}
|
||||
const LLType* t = DtoType(type);
|
||||
if (v->getType() != t)
|
||||
v = DtoBitCast(v, t);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
profile=tango
|
||||
ignore=object
|
||||
|
||||
compiler=llvmdc
|
||||
inifile=llvmdc.conf
|
||||
|
||||
27
tests/mini/nested14.d
Normal file
27
tests/mini/nested14.d
Normal 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();
|
||||
}
|
||||
Reference in New Issue
Block a user