# HG changeset patch # User Tomas Lindquist Olsen # Date 1228177222 -3600 # Node ID bb4a81e68ddb6e2c43320d5eac880bae98c9e5bc # Parent 446263a8a30dfa486754a6e0d9cdc7df6e0009da Implemented allocating storage for a slice if its address is taken, fixes #115 diff -r 446263a8a30d -r bb4a81e68ddb gen/toir.cpp --- a/gen/toir.cpp Tue Dec 02 01:07:22 2008 +0100 +++ b/gen/toir.cpp Tue Dec 02 01:20:22 2008 +0100 @@ -888,10 +888,23 @@ 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) diff -r 446263a8a30d -r bb4a81e68ddb tests/mini/slices2.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/mini/slices2.d Tue Dec 02 01:20:22 2008 +0100 @@ -0,0 +1,5 @@ +void main() +{ + int[10] arr = void; + int[]* ptr = &arr[1..3]; +}