changeset 520:73e41129b7f3

Fix function literals. They never carry a context. Fixes: run/f/foreach_36_A
author Christian Kamm <kamm incasoftware de>
date Sat, 16 Aug 2008 13:33:37 +0200
parents bc0835cd3440
children 99e95dae90d5
files gen/toir.cpp
diffstat 1 files changed, 24 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/gen/toir.cpp	Sat Aug 16 12:38:53 2008 +0200
+++ b/gen/toir.cpp	Sat Aug 16 13:33:37 2008 +0200
@@ -2064,22 +2064,31 @@
 
     DtoForceDefineDsymbol(fd);
 
-    const LLType* dgty = DtoType(type);
-    LLValue* lval = DtoAlloca(dgty,"dgstorage");
-
-    LLValue* context = DtoGEPi(lval,0,0);
-    LLValue* cval;
-    IrFunction* irfn = p->func();
-    if (irfn->nestedVar)
-        cval = irfn->nestedVar;
-    else if (irfn->nestArg)
-        cval = irfn->nestArg;
+    LLValue *lval, *fptr;
+    if(fd->tok == TOKdelegate) {
+        const LLType* dgty = DtoType(type);
+        lval = DtoAlloca(dgty,"dgstorage");
+
+        LLValue* context = DtoGEPi(lval,0,0);
+        LLValue* cval;
+        IrFunction* irfn = p->func();
+        if (irfn->nestedVar)
+            cval = irfn->nestedVar;
+        else if (irfn->nestArg)
+            cval = irfn->nestArg;
+        else
+            cval = getNullPtr(getVoidPtrType());
+        cval = DtoBitCast(cval, context->getType()->getContainedType(0));
+        DtoStore(cval, context);
+
+        fptr = DtoGEPi(lval,0,1,"tmp",p->scopebb());
+    } else if(fd->tok == TOKfunction) {
+        const LLType* fnty = DtoType(type);
+        lval = DtoAlloca(fnty,"fnstorage");
+        fptr = lval;
+    }
     else
-        cval = getNullPtr(getVoidPtrType());
-    cval = DtoBitCast(cval, context->getType()->getContainedType(0));
-    DtoStore(cval, context);
-    
-    LLValue* fptr = DtoGEPi(lval,0,1,"tmp",p->scopebb());
+        assert(0 && "fd->tok must be TOKfunction or TOKdelegate");
 
     assert(fd->ir.irFunc->func);
     LLValue* castfptr = DtoBitCast(fd->ir.irFunc->func, fptr->getType()->getContainedType(0));