changeset 211:f66219e0d530 trunk

[svn r227] Fixed: crash in lifetime.d when resizing array of AAs by .length assignment.
author lindquist
date Tue, 27 May 2008 19:53:29 +0200
parents 1d6cfdbc97f0
children 4c2689d57ba4
files dmd/mtype.c dmd/mtype.h gen/arrays.cpp tango/lib/compiler/llvmdc/lifetime.d
diffstat 4 files changed, 18 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/dmd/mtype.c	Wed May 14 02:00:23 2008 +0200
+++ b/dmd/mtype.c	Tue May 27 19:53:29 2008 +0200
@@ -2333,6 +2333,11 @@
     return e;
 }
 
+int TypeAArray::isZeroInit()
+{
+    return 1;
+}
+
 int TypeAArray::checkBoolean()
 {
     return TRUE;
--- a/dmd/mtype.h	Wed May 14 02:00:23 2008 +0200
+++ b/dmd/mtype.h	Tue May 27 19:53:29 2008 +0200
@@ -360,6 +360,7 @@
     Expression *dotExp(Scope *sc, Expression *e, Identifier *ident);
     Expression *defaultInit(Loc loc);
     MATCH deduceType(Scope *sc, Type *tparam, TemplateParameters *parameters, Objects *dedtypes);
+    int isZeroInit();
     int checkBoolean();
     TypeInfoDeclaration *getTypeInfoDeclaration();
     int hasPointers();
--- a/gen/arrays.cpp	Wed May 14 02:00:23 2008 +0200
+++ b/gen/arrays.cpp	Tue May 27 19:53:29 2008 +0200
@@ -545,7 +545,10 @@
     assert(arrayType);
     assert(arrayType->toBasetype()->ty == Tarray);
 
-    bool zeroInit = arrayType->toBasetype()->nextOf()->isZeroInit();
+    // decide on what runtime function to call based on whether the type is zero initialized
+    bool zeroInit = arrayType->toBasetype()->next->isZeroInit();
+
+    // call runtime
     llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, zeroInit ? "_d_arraysetlengthT" : "_d_arraysetlengthiT" );
 
     llvm::SmallVector<llvm::Value*,4> args;
--- a/tango/lib/compiler/llvmdc/lifetime.d	Wed May 14 02:00:23 2008 +0200
+++ b/tango/lib/compiler/llvmdc/lifetime.d	Tue May 27 19:53:29 2008 +0200
@@ -514,9 +514,8 @@
 
     debug(PRINTF)
     {
-        printf("_d_arraysetlengthT(p = %p, sizeelem = %d, newlength = %d)\n", p, sizeelem, newlength);
-        if (p)
-            printf("\tp.data = %p, p.length = %d\n", pdata, plength);
+        printf("_d_arraysetlengthT(sizeelem = %d, newlength = %d)\n", sizeelem, newlength);
+        printf("\tp.data = %p, p.length = %d\n", pdata, plength);
     }
 
     if (newlength)
@@ -602,8 +601,9 @@
 body
 {
     byte* newdata;
-    size_t sizeelem = ti.next.tsize();
-    void[] initializer = ti.next.init();
+    TypeInfo tinext = ti.next;
+    size_t sizeelem = tinext.tsize();
+    void[] initializer = tinext.init();
     size_t initsize = initializer.length;
 
     assert(sizeelem);
@@ -613,9 +613,8 @@
 
     debug(PRINTF)
     {
-        printf("_d_arraysetlengthiT(p = %p, sizeelem = %d, newlength = %d, initsize = %d)\n", p, sizeelem, newlength, initsize);
-        if (p)
-            printf("\tp.data = %p, p.length = %d\n", pdata, plength);
+        printf("_d_arraysetlengthiT(sizeelem = %d, newlength = %d, initsize = %d)\n", sizeelem, newlength, initsize);
+        printf("\tp.data = %p, p.length = %d\n", pdata, plength);
     }
 
     if (newlength)
@@ -668,7 +667,7 @@
         }
         else
         {
-            newdata = cast(byte *)gc_malloc(newsize + 1, !(ti.next.flags() & 1) ? BlkAttr.NO_SCAN : 0);
+            newdata = cast(byte *)gc_malloc(newsize + 1, !(tinext.flags() & 1) ? BlkAttr.NO_SCAN : 0);
         }
 
         auto q = initializer.ptr; // pointer to initializer