[svn r72] Calling a nested function that is not a delegate was not working.

This commit is contained in:
Tomas Lindquist Olsen
2007-10-28 03:14:29 +01:00
parent feea94424c
commit b5433b6054
3 changed files with 23 additions and 0 deletions

View File

@@ -1036,6 +1036,7 @@ elem* CallExp::toElem(IRState* p)
if (fn->arg || delegateCall) n++;
if (retinptr) n++;
if (tf->linkage == LINKd && tf->varargs == 1) n+=2;
if (fn->funcdecl && fn->funcdecl->isNested()) n++;
llvm::Value* funcval = fn->getValue();
assert(funcval != 0);
@@ -1127,6 +1128,15 @@ elem* CallExp::toElem(IRState* p)
++j;
++argiter;
}
// nested call
else if (fn->funcdecl && fn->funcdecl->isNested()) {
Logger::println("Nested Call");
llvm::Value* contextptr = p->func().decl->llvmNested;
assert(contextptr);
llargs[j] = p->ir->CreateBitCast(contextptr, llvm::PointerType::get(llvm::Type::Int8Ty), "tmp");
++j;
++argiter;
}
// va arg function special argument passing
if (va_magic) {

View File

@@ -789,6 +789,7 @@ void FuncDeclaration::toObjFile()
VarDeclaration* vd = *i;
if (vd->isParameter()) {
gIR->ir->CreateStore(vd->llvmValue, LLVM_DtoGEPi(llvmNested, 0, vd->llvmNestedIndex, "tmp"));
vd->llvmValue = llvmNested;
}
}
}

12
test/nested3.d Normal file
View File

@@ -0,0 +1,12 @@
module nested3;
void main()
{
int i;
void test()
{
i = 3;
}
test();
assert(i == 3);
}