mirror of
https://github.com/xomboverlord/ldc.git
synced 2026-01-17 13:23:14 +01:00
Implemented allocating storage for a slice if its address is taken, fixes #115
This commit is contained in:
17
gen/toir.cpp
17
gen/toir.cpp
@@ -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
5
tests/mini/slices2.d
Normal file
@@ -0,0 +1,5 @@
|
||||
void main()
|
||||
{
|
||||
int[10] arr = void;
|
||||
int[]* ptr = &arr[1..3];
|
||||
}
|
||||
Reference in New Issue
Block a user