# HG changeset patch # User lindquist # Date 1215875076 -7200 # Node ID 17b84410202358321d34823241c71e52183632a6 # Parent 20446d22f83262add6b8f50fab4ca9d407b4c2d4 [svn r356] Fixed problem with array length assignment introduced in [355] diff -r 20446d22f832 -r 17b844102023 gen/dvalue.h --- a/gen/dvalue.h Sat Jul 12 15:43:13 2008 +0200 +++ b/gen/dvalue.h Sat Jul 12 17:04:36 2008 +0200 @@ -192,13 +192,6 @@ 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 -r 20446d22f832 -r 17b844102023 gen/toir.cpp --- a/gen/toir.cpp Sat Jul 12 15:43:13 2008 +0200 +++ b/gen/toir.cpp Sat Jul 12 17:04:36 2008 +0200 @@ -563,27 +563,23 @@ 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 @@ 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 -r 20446d22f832 -r 17b844102023 tangotests/lazy2.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tangotests/lazy2.d Sat Jul 12 17:04:36 2008 +0200 @@ -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); +}