[svn r308] Really fixed multidimensional new expressions. the first length was bad in the resulting slice.

This commit is contained in:
Tomas Lindquist Olsen
2008-06-21 05:03:42 +02:00
parent 67dd564222
commit ffd38d355d
2 changed files with 28 additions and 3 deletions

View File

@@ -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; 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 @@ DSliceValue* DtoNewMulDimDynArray(Type* arrayType, DValue** dims, size_t ndims,
}
#endif
return new DSliceValue(arrayType, arrayLen, newptr);
assert(firstDim);
return new DSliceValue(arrayType, firstDim, newptr);
}
//////////////////////////////////////////////////////////////////////////////////////////

23
tangotests/marray3.d Normal file
View File

@@ -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);
}