diff gen/toobj.c @ 67:f918f3e2e99e trunk

[svn r71] Fixed accessing parent function arguments from inside nested delegates. Some cleanups in VarExp::toElem.
author lindquist
date Sun, 28 Oct 2007 02:46:06 +0200
parents b688ad419f8c
children c4b3f5d2cd9b
line wrap: on
line diff
--- a/gen/toobj.c	Sun Oct 28 02:03:42 2007 +0200
+++ b/gen/toobj.c	Sun Oct 28 02:46:06 2007 +0200
@@ -769,7 +769,13 @@
                     for (std::set<VarDeclaration*>::iterator i=llvmNestedVars.begin(); i!=llvmNestedVars.end(); ++i) {
                         VarDeclaration* vd = *i;
                         vd->llvmNestedIndex = j++;
-                        nestTypes.push_back(LLVM_DtoType(vd->type));
+                        if (vd->isParameter()) {
+                            assert(vd->llvmValue);
+                            nestTypes.push_back(vd->llvmValue->getType());
+                        }
+                        else {
+                            nestTypes.push_back(LLVM_DtoType(vd->type));
+                        }
                     }
                     const llvm::StructType* nestSType = llvm::StructType::get(nestTypes);
                     Logger::cout() << "nested var struct has type:" << '\n' << *nestSType;
@@ -779,6 +785,12 @@
                         llvm::Value* ptr = gIR->ir->CreateBitCast(llvmThisVar, parentNested->getType(), "tmp");
                         gIR->ir->CreateStore(ptr, LLVM_DtoGEPi(llvmNested, 0,0, "tmp"));
                     }
+                    for (std::set<VarDeclaration*>::iterator i=llvmNestedVars.begin(); i!=llvmNestedVars.end(); ++i) {
+                        VarDeclaration* vd = *i;
+                        if (vd->isParameter()) {
+                            gIR->ir->CreateStore(vd->llvmValue, LLVM_DtoGEPi(llvmNested, 0, vd->llvmNestedIndex, "tmp"));
+                        }
+                    }
                 }
 
                 // copy _argptr to a memory location