Mercurial > projects > ldc
changeset 287:00eb2c967c3a trunk
[svn r308] Really fixed multidimensional new expressions. the first length was bad in the resulting slice.
author | lindquist |
---|---|
date | Sat, 21 Jun 2008 05:03:42 +0200 |
parents | a3b7c19c866c |
children | ba4e4298009a |
files | gen/arrays.cpp tangotests/marray3.d |
diffstat | 2 files changed, 28 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/gen/arrays.cpp Sat Jun 21 04:47:14 2008 +0200 +++ b/gen/arrays.cpp Sat Jun 21 05:03:42 2008 +0200 @@ -492,15 +492,16 @@ // build dims LLValue* dimsArg = new llvm::AllocaInst(DtoSize_t(), DtoConstUint(ndims), ".newdims", gIR->topallocapoint()); + LLValue* firstDim = NULL; for (size_t i=0; i<ndims; ++i) { LLValue* dim = dims[i]->getRVal(); + if (!firstDim) firstDim = dim; DtoStore(dim, DtoGEPi1(dimsArg, i)); } // call allocator - LLConstant* arrayLen = DtoConstSize_t(ndims); - LLValue* newptr = gIR->ir->CreateCall3(fn, arrayTypeInfo, arrayLen, dimsArg, ".gc_mem"); + LLValue* newptr = gIR->ir->CreateCall3(fn, arrayTypeInfo, DtoConstSize_t(ndims), dimsArg, ".gc_mem"); // cast to wanted type const LLType* dstType = DtoType(arrayType)->getContainedType(1); @@ -516,7 +517,8 @@ } #endif - return new DSliceValue(arrayType, arrayLen, newptr); + assert(firstDim); + return new DSliceValue(arrayType, firstDim, newptr); } //////////////////////////////////////////////////////////////////////////////////////////
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tangotests/marray3.d Sat Jun 21 05:03:42 2008 +0200 @@ -0,0 +1,23 @@ +module tangotests.marray3; + +void main() +{ + int[][][] ma = new int[][][](2,4,3); + assert(ma.length == 2); + assert(ma[0].length == 4); + assert(ma[0][0].length == 3); + assert(ma[0][1].length == 3); + assert(ma[0][2].length == 3); + assert(ma[0][3].length == 3); + assert(ma[1].length == 4); + assert(ma[1][0].length == 3); + assert(ma[1][1].length == 3); + assert(ma[1][2].length == 3); + assert(ma[1][3].length == 3); + ma[0][3][1] = 32; + ma[1][2][2] = 123; + ma[0][0][3] = 55; + assert(ma[0][3][1] == 32); + assert(ma[1][2][2] == 123); + assert(ma[0][0][3] == 55); +}