diff --git a/gen/dvalue.h b/gen/dvalue.h index a2c99285..aa75ad99 100644 --- a/gen/dvalue.h +++ b/gen/dvalue.h @@ -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 { diff --git a/gen/toir.cpp b/gen/toir.cpp index b8c1f68a..2c83820f 100644 --- a/gen/toir.cpp +++ b/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)); } ////////////////////////////////////////////////////////////////////////////////////////// diff --git a/tangotests/lazy2.d b/tangotests/lazy2.d new file mode 100644 index 00000000..c2e46552 --- /dev/null +++ b/tangotests/lazy2.d @@ -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); +}