comparison gen/llvmhelpers.cpp @ 1592:91af6d05338c

Fix codegen for foreach with ref value being lowered to for.
author Christian Kamm <kamm incasoftware de>
date Sat, 07 Nov 2009 13:51:05 +0100
parents 8d086d552909
children b0dfdd5f6006
comparison
equal deleted inserted replaced
1591:eaf87e36ce0d 1592:91af6d05338c
906 assert(vd->ir.irLocal); 906 assert(vd->ir.irLocal);
907 907
908 DtoNestedInit(vd); 908 DtoNestedInit(vd);
909 } 909 }
910 // normal stack variable, allocate storage on the stack if it has not already been done 910 // normal stack variable, allocate storage on the stack if it has not already been done
911 else if(!vd->ir.irLocal) { 911 else if(!vd->ir.irLocal && !vd->isRef()) {
912 vd->ir.irLocal = new IrLocal(vd);
913
912 const LLType* lltype = DtoType(vd->type); 914 const LLType* lltype = DtoType(vd->type);
913 915
914 llvm::Value* allocainst; 916 llvm::Value* allocainst;
915 if(gTargetData->getTypeSizeInBits(lltype) == 0) 917 if(gTargetData->getTypeSizeInBits(lltype) == 0)
916 allocainst = llvm::ConstantPointerNull::get(getPtrToType(lltype)); 918 allocainst = llvm::ConstantPointerNull::get(getPtrToType(lltype));
917 else 919 else
918 allocainst = DtoAlloca(vd->type, vd->toChars()); 920 allocainst = DtoAlloca(vd->type, vd->toChars());
919 921
920 //allocainst->setAlignment(vd->type->alignsize()); // TODO 922 //allocainst->setAlignment(vd->type->alignsize()); // TODO
921 vd->ir.irLocal = new IrLocal(vd);
922 vd->ir.irLocal->value = allocainst; 923 vd->ir.irLocal->value = allocainst;
923 924
924 if (global.params.symdebug) 925 if (global.params.symdebug)
925 { 926 {
926 DtoDwarfLocalVariable(allocainst, vd); 927 DtoDwarfLocalVariable(allocainst, vd);
927 } 928 }
929 }
930 else if(vd->isRef())
931 {
932 // ref vardecls are generated when DMD lowers foreach to a for statement,
933 // and this is a hack to support them for this case only
934 if (!vd->ir.irLocal)
935 vd->ir.irLocal = new IrLocal(vd);
936
937 ExpInitializer* ex = vd->init->isExpInitializer();
938 assert(ex && "ref vars must have expression initializer");
939 assert(ex->exp);
940 AssignExp* as = dynamic_cast<AssignExp*>(ex->exp);
941 assert(as && "ref vars must be initialized by an assign exp");
942 vd->ir.irLocal->value = as->e2->toElem(gIR)->getLVal();
943 return new DVarValue(vd->type, vd, vd->ir.getIrValue());
928 } 944 }
929 else 945 else
930 { 946 {
931 assert(vd->ir.irLocal->value); 947 assert(vd->ir.irLocal->value);
932 } 948 }