From aef7e0ee36e5f8392e309701c3c68ebf51dfd581 Mon Sep 17 00:00:00 2001 From: Alexey Prokhin Date: Tue, 19 Jul 2011 10:14:12 +0400 Subject: [PATCH] Fix array append with dollar op --- gen/arrays.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/gen/arrays.cpp b/gen/arrays.cpp index ed75177e..475807b1 100644 --- a/gen/arrays.cpp +++ b/gen/arrays.cpp @@ -734,6 +734,10 @@ void DtoCatAssignElement(Loc& loc, Type* arrayType, DValue* array, Expression* e LLValue *oldLength = DtoArrayLen(array); + // Do not move exp->toElem call after creating _d_arrayappendcTX, + // otherwise a ~= a[$-i] won't work correctly + DValue *expVal = exp->toElem(gIR); + LLFunction* fn = LLVM_D_GetRuntimeFunction(gIR->module, "_d_arrayappendcTX"); LLSmallVector args; args.push_back(DtoTypeInfoOf(arrayType)); @@ -746,7 +750,7 @@ void DtoCatAssignElement(Loc& loc, Type* arrayType, DValue* array, Expression* e LLValue* val = DtoExtractValue(appendedArray, 1, ".ptr"); val = DtoGEP1(val, oldLength, "lastElem"); val = DtoBitCast(val, DtoType(arrayType->nextOf()->pointerTo())); - DtoAssign(loc, new DVarValue(arrayType->nextOf(), val), exp->toElem(gIR)); + DtoAssign(loc, new DVarValue(arrayType->nextOf(), val), expVal); } #else