Mercurial > projects > ldc
comparison gen/llvmhelpers.cpp @ 1185:8baf611f0009
Fix nested references to 'ref' foreach variables.
These "walk around" the array being iterated over, so they're a bit trickier
than other variables to get right.
author | Frits van Bommel <fvbommel wxs.nl> |
---|---|
date | Wed, 01 Apr 2009 00:01:44 +0200 |
parents | ed4b050ada45 |
children | c0091f3b72f1 |
comparison
equal
deleted
inserted
replaced
1183:df386fd4030e | 1185:8baf611f0009 |
---|---|
1073 } | 1073 } |
1074 return NULL; | 1074 return NULL; |
1075 } | 1075 } |
1076 | 1076 |
1077 // does pretty much the same as DtoDeclarationExp, except it doesn't initialize, and only handles var declarations | 1077 // does pretty much the same as DtoDeclarationExp, except it doesn't initialize, and only handles var declarations |
1078 LLValue* DtoRawVarDeclaration(VarDeclaration* var) | 1078 LLValue* DtoRawVarDeclaration(VarDeclaration* var, LLValue* addr) |
1079 { | 1079 { |
1080 // we don't handle globals with this one | 1080 // we don't handle globals with this one |
1081 assert(!var->isDataseg()); | 1081 assert(!var->isDataseg()); |
1082 | 1082 |
1083 // we don't handle aliases either | 1083 // we don't handle aliases either |
1084 assert(!var->aliassym); | 1084 assert(!var->aliassym); |
1085 | 1085 |
1086 // if this already has storage, it must've been handled already | |
1087 if (var->ir.irLocal && var->ir.irLocal->value) | |
1088 return var->ir.irLocal->value; | |
1089 | |
1090 // referenced by nested function? | 1086 // referenced by nested function? |
1091 #if DMDV2 | 1087 #if DMDV2 |
1092 if (var->nestedrefs.dim) | 1088 if (var->nestedrefs.dim) |
1093 #else | 1089 #else |
1094 if (var->nestedref) | 1090 if (var->nestedref) |
1095 #endif | 1091 #endif |
1096 { | 1092 { |
1097 assert(var->ir.irLocal); | 1093 assert(var->ir.irLocal); |
1098 assert(!var->ir.irLocal->value); | 1094 if(!var->ir.irLocal->value) |
1099 | 1095 var->ir.irLocal->value = addr ? addr : DtoAlloca(DtoType(var->type), var->toChars()); |
1100 // alloca | 1096 else |
1101 var->ir.irLocal->value = DtoAlloca(DtoType(var->type), var->toChars()); | 1097 assert(!addr || addr == var->ir.irLocal->value); |
1102 | 1098 |
1103 // store the address into the nested vars array | 1099 // store the address into the nested vars array |
1104 assert(var->ir.irLocal->nestedIndex >= 0); | 1100 assert(var->ir.irLocal->nestedIndex >= 0); |
1105 LLValue* gep = DtoGEPi(gIR->func()->decl->ir.irFunc->nestedVar, 0, var->ir.irLocal->nestedIndex); | 1101 LLValue* gep = DtoGEPi(gIR->func()->decl->ir.irFunc->nestedVar, 0, var->ir.irLocal->nestedIndex); |
1106 assert(isaPointer(var->ir.irLocal->value)); | 1102 assert(isaPointer(var->ir.irLocal->value)); |
1108 DtoStore(val, gep); | 1104 DtoStore(val, gep); |
1109 } | 1105 } |
1110 // normal local variable | 1106 // normal local variable |
1111 else | 1107 else |
1112 { | 1108 { |
1109 // if this already has storage, it must've been handled already | |
1110 if (var->ir.irLocal && var->ir.irLocal->value) { | |
1111 assert(!addr || addr == var->ir.irLocal->value); | |
1112 return var->ir.irLocal->value; | |
1113 } | |
1114 | |
1113 assert(!var->ir.isSet()); | 1115 assert(!var->ir.isSet()); |
1114 var->ir.irLocal = new IrLocal(var); | 1116 var->ir.irLocal = new IrLocal(var); |
1115 var->ir.irLocal->value = DtoAlloca(DtoType(var->type), var->toChars()); | 1117 var->ir.irLocal->value = addr ? addr : DtoAlloca(DtoType(var->type), var->toChars()); |
1116 } | 1118 } |
1117 | 1119 |
1118 // add debug info | 1120 // add debug info |
1119 if (global.params.symdebug) | 1121 if (global.params.symdebug) |
1120 DtoDwarfLocalVariable(var->ir.irLocal->value, var); | 1122 DtoDwarfLocalVariable(var->ir.irLocal->value, var); |