# HG changeset patch # User lindquist # Date 1214017422 -7200 # Node ID 00eb2c967c3a806a8fcc510cf3dcacaf60e1063f # Parent a3b7c19c866c770f5d0576dcc6353fb8975af1c2 [svn r308] Really fixed multidimensional new expressions. the first length was bad in the resulting slice. diff -r a3b7c19c866c -r 00eb2c967c3a gen/arrays.cpp --- 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; igetRVal(); + 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); } ////////////////////////////////////////////////////////////////////////////////////////// diff -r a3b7c19c866c -r 00eb2c967c3a tangotests/marray3.d --- /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); +}