mirror of
https://github.com/xomboverlord/ldc.git
synced 2026-01-17 13:23:14 +01:00
[svn r356] Fixed problem with array length assignment introduced in [355]
This commit is contained in:
@@ -192,13 +192,6 @@ struct DLRValue : DValue
|
||||
virtual DLRValue* isLRValue() { return this; }
|
||||
};
|
||||
|
||||
// array length d-value
|
||||
struct DArrayLenValue : DLRValue
|
||||
{
|
||||
DArrayLenValue(Type* lt, LLValue* l, Type* rt, LLValue* r) : DLRValue(lt, l, rt, r) {}
|
||||
virtual DArrayLenValue* isArrayLen() { return this; }
|
||||
};
|
||||
|
||||
// complex number immediate d-value (much like slice)
|
||||
struct DComplexValue : DValue
|
||||
{
|
||||
|
||||
38
gen/toir.cpp
38
gen/toir.cpp
@@ -563,27 +563,23 @@ DValue* AssignExp::toElem(IRState* p)
|
||||
Logger::print("AssignExp::toElem: %s | %s = %s\n", toChars(), e1->type->toChars(), e2->type ? e2->type->toChars() : 0);
|
||||
LOG_SCOPE;
|
||||
|
||||
if (e1->op == TOKarraylength)
|
||||
{
|
||||
Logger::println("performing array.length assignment");
|
||||
ArrayLengthExp *ale = (ArrayLengthExp *)e1;
|
||||
DValue* arr = ale->e1->toElem(p);
|
||||
DVarValue arrval(ale->e1->type, arr->getLVal(), true);
|
||||
DValue* newlen = e2->toElem(p);
|
||||
DSliceValue* slice = DtoResizeDynArray(arrval.getType(), &arrval, newlen);
|
||||
DtoAssign(&arrval, slice);
|
||||
return newlen;
|
||||
}
|
||||
|
||||
Logger::println("performing normal assignment");
|
||||
|
||||
DValue* l = e1->toElem(p);
|
||||
DValue* r = e2->toElem(p);
|
||||
|
||||
Logger::println("performing assignment");
|
||||
|
||||
DImValue* im = r->isIm();
|
||||
if (!im || !im->inPlace()) {
|
||||
Logger::println("assignment not inplace");
|
||||
if (DArrayLenValue* al = l->isArrayLen())
|
||||
{
|
||||
DLRValue* arrlenval = l->isLRValue();
|
||||
assert(arrlenval);
|
||||
DVarValue arrval(arrlenval->getLType(), arrlenval->getLVal(), true);
|
||||
DSliceValue* slice = DtoResizeDynArray(arrval.getType(), &arrval, r);
|
||||
DtoAssign(&arrval, slice);
|
||||
}
|
||||
else
|
||||
{
|
||||
DtoAssign(l, r);
|
||||
}
|
||||
}
|
||||
DtoAssign(l, r);
|
||||
|
||||
if (l->isSlice() || l->isComplex())
|
||||
return l;
|
||||
@@ -1945,9 +1941,7 @@ DValue* ArrayLengthExp::toElem(IRState* p)
|
||||
LOG_SCOPE;
|
||||
|
||||
DValue* u = e1->toElem(p);
|
||||
Logger::println("e1 = %s", e1->type->toChars());
|
||||
|
||||
return new DArrayLenValue(e1->type, u->getLVal(), type, DtoArrayLen(u));
|
||||
return new DImValue(type, DtoArrayLen(u));
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
18
tangotests/lazy2.d
Normal file
18
tangotests/lazy2.d
Normal file
@@ -0,0 +1,18 @@
|
||||
module tangotests.lazy2;
|
||||
|
||||
extern(C) int printf(char*, ...);
|
||||
|
||||
void main()
|
||||
{
|
||||
lazy1("hello\n");
|
||||
}
|
||||
|
||||
void lazy1(lazy char[] str)
|
||||
{
|
||||
lazy2(str);
|
||||
}
|
||||
|
||||
void lazy2(lazy char[] msg)
|
||||
{
|
||||
printf("%.*s", msg.length, msg.ptr);
|
||||
}
|
||||
Reference in New Issue
Block a user