diff --git a/gen/arrays.cpp b/gen/arrays.cpp index fdda303b..ba23cdcf 100644 --- a/gen/arrays.cpp +++ b/gen/arrays.cpp @@ -492,15 +492,16 @@ DSliceValue* DtoNewMulDimDynArray(Type* arrayType, DValue** dims, size_t ndims, // 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 @@ DSliceValue* DtoNewMulDimDynArray(Type* arrayType, DValue** dims, size_t ndims, } #endif - return new DSliceValue(arrayType, arrayLen, newptr); + assert(firstDim); + return new DSliceValue(arrayType, firstDim, newptr); } ////////////////////////////////////////////////////////////////////////////////////////// diff --git a/tangotests/marray3.d b/tangotests/marray3.d new file mode 100644 index 00000000..eb668e2e --- /dev/null +++ b/tangotests/marray3.d @@ -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); +}