From d6e4f659e2a902d4026f5f4129dd95df5f6ca44b Mon Sep 17 00:00:00 2001 From: Christian Kamm Date: Sun, 14 Sep 2008 10:56:01 +0200 Subject: [PATCH] Allocate dynamic array literals on the heap. --- gen/toir.cpp | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/gen/toir.cpp b/gen/toir.cpp index 473f7f39..6a3a080c 100644 --- a/gen/toir.cpp +++ b/gen/toir.cpp @@ -2168,14 +2168,25 @@ DValue* ArrayLiteralExp::toElem(IRState* p) } // dst pointer - // FIXME: dynamic array literals should be allocated with the GC - LLValue* dstMem = DtoAlloca(llStoType, "arrayliteral"); + LLValue* dstMem; + DSliceValue* dynSlice = NULL; + if(dyn) + { + dynSlice = DtoNewDynArray(loc, arrayType, new DConstValue(Type::tsize_t, DtoConstSize_t(len)), false); + dstMem = dynSlice->ptr; + } + else + dstMem = DtoAlloca(llStoType, "arrayliteral"); // store elements for (size_t i=0; idata[i]; - LLValue* elemAddr = DtoGEPi(dstMem,0,i,"tmp",p->scopebb()); + LLValue* elemAddr; + if(dyn) + elemAddr = DtoGEPi1(dstMem, i, "tmp", p->scopebb()); + else + elemAddr = DtoGEPi(dstMem,0,i,"tmp",p->scopebb()); // emulate assignment DVarValue* vv = new DVarValue(expr->type, elemAddr); @@ -2187,8 +2198,8 @@ DValue* ArrayLiteralExp::toElem(IRState* p) if (!dyn) return new DImValue(type, dstMem); - // wrap in a slice - return new DSliceValue(type, DtoConstSize_t(len), DtoGEPi(dstMem,0,0,"tmp")); + // return slice + return dynSlice; } //////////////////////////////////////////////////////////////////////////////////////////