changeset 1593:b0dfdd5f6006

Make ref vars work with nesting.
author Christian Kamm <kamm incasoftware de>
date Sat, 07 Nov 2009 14:06:11 +0100
parents 91af6d05338c
children 9f7151d890ff
files gen/llvmhelpers.cpp
diffstat 1 files changed, 17 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/gen/llvmhelpers.cpp	Sat Nov 07 13:51:05 2009 +0100
+++ b/gen/llvmhelpers.cpp	Sat Nov 07 14:06:11 2009 +0100
@@ -896,6 +896,21 @@
 
             Logger::println("vdtype = %s", vd->type->toChars());
 
+            // ref vardecls are generated when DMD lowers foreach to a for statement,
+            // and this is a hack to support them for this case only
+            if(vd->isRef())
+            {
+                if (!vd->ir.irLocal)
+                    vd->ir.irLocal = new IrLocal(vd);
+
+                ExpInitializer* ex = vd->init->isExpInitializer();
+                assert(ex && "ref vars must have expression initializer");
+                assert(ex->exp);
+                AssignExp* as = dynamic_cast<AssignExp*>(ex->exp);
+                assert(as && "ref vars must be initialized by an assign exp");
+                vd->ir.irLocal->value = as->e2->toElem(gIR)->getLVal();
+            }
+            
             // referenced by nested delegate?
         #if DMDV2
             if (vd->nestedrefs.dim) {
@@ -927,21 +942,6 @@
                     DtoDwarfLocalVariable(allocainst, vd);
                 }
             }
-            else if(vd->isRef())
-            {
-                // ref vardecls are generated when DMD lowers foreach to a for statement,
-                // and this is a hack to support them for this case only
-                if (!vd->ir.irLocal)
-                    vd->ir.irLocal = new IrLocal(vd);
-                    
-                ExpInitializer* ex = vd->init->isExpInitializer();
-                assert(ex && "ref vars must have expression initializer");
-                assert(ex->exp);
-                AssignExp* as = dynamic_cast<AssignExp*>(ex->exp);
-                assert(as && "ref vars must be initialized by an assign exp");
-                vd->ir.irLocal->value = as->e2->toElem(gIR)->getLVal();
-                return new DVarValue(vd->type, vd, vd->ir.getIrValue());
-            }
             else
             {
                 assert(vd->ir.irLocal->value);
@@ -949,7 +949,8 @@
 
             if (Logger::enabled())
                 Logger::cout() << "llvm value for decl: " << *vd->ir.irLocal->value << '\n';
-            DValue* ie = DtoInitializer(vd->ir.irLocal->value, vd->init);
+            if (!vd->isRef())
+                DValue* ie = DtoInitializer(vd->ir.irLocal->value, vd->init);
         }
 
         return new DVarValue(vd->type, vd, vd->ir.getIrValue());