Implemented allocating storage for a slice if its address is taken, fixes #115

This commit is contained in:
Tomas Lindquist Olsen
2008-12-02 01:20:22 +01:00
parent c62b31a357
commit 91a2c257b0
2 changed files with 20 additions and 2 deletions

View File

@@ -888,10 +888,23 @@ DValue* AddrExp::toElem(IRState* p)
return v;
}
Logger::println("is nothing special");
LLValue* lval = v->getLVal();
// we special case here, since apparently taking the address of a slice is ok
LLValue* lval;
if (v->isLVal())
lval = v->getLVal();
else
{
assert(v->isSlice());
LLValue* rval = v->getRVal();
lval = DtoAlloca(rval->getType(), ".tmp_slice_storage");
DtoStore(rval, lval);
}
if (Logger::enabled())
Logger::cout() << "lval: " << *lval << '\n';
return new DImValue(type, DtoBitCast(v->getLVal(), DtoType(type)));
return new DImValue(type, DtoBitCast(lval, DtoType(type)));
}
LLConstant* AddrExp::toConstElem(IRState* p)

5
tests/mini/slices2.d Normal file
View File

@@ -0,0 +1,5 @@
void main()
{
int[10] arr = void;
int[]* ptr = &arr[1..3];
}