changeset 68:c4b3f5d2cd9b trunk

[svn r72] Calling a nested function that is not a delegate was not working.
author lindquist
date Sun, 28 Oct 2007 03:14:29 +0100
parents f918f3e2e99e
children 2b5a2eaa88be
files gen/toir.c gen/toobj.c test/nested3.d
diffstat 3 files changed, 23 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/gen/toir.c	Sun Oct 28 02:46:06 2007 +0200
+++ b/gen/toir.c	Sun Oct 28 03:14:29 2007 +0100
@@ -1036,6 +1036,7 @@
     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 @@
         ++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) {
--- a/gen/toobj.c	Sun Oct 28 02:46:06 2007 +0200
+++ b/gen/toobj.c	Sun Oct 28 03:14:29 2007 +0100
@@ -789,6 +789,7 @@
                         VarDeclaration* vd = *i;
                         if (vd->isParameter()) {
                             gIR->ir->CreateStore(vd->llvmValue, LLVM_DtoGEPi(llvmNested, 0, vd->llvmNestedIndex, "tmp"));
+                            vd->llvmValue = llvmNested;
                         }
                     }
                 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/nested3.d	Sun Oct 28 03:14:29 2007 +0100
@@ -0,0 +1,12 @@
+module nested3;
+
+void main()
+{
+    int i;
+    void test()
+    {
+        i = 3;
+    }
+    test();
+    assert(i == 3);
+}