[Issue 4156] New: Segfault with array+=array

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon May 3 14:01:07 PDT 2010


http://d.puremagic.com/issues/show_bug.cgi?id=4156

           Summary: Segfault with array+=array
           Product: D
           Version: 2.034
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Keywords: ice-on-invalid-code, patch
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: clugdbug at yahoo.com.au


--- Comment #0 from Don <clugdbug at yahoo.com.au> 2010-05-03 14:01:06 PDT ---
void main() {
    int[] a = [1,2];
    int[] b = [1,2];
    a+= b;
}

arr.d(5): Error: Array operations not implemented
<segfault>

For any assign operation other than +=, it creates wrong code.


It crashes because AddAssignExp::toElem (e2ir.c line 2934) returns an
uninitialized variable.

        error("Array operations not implemented");
+        e = el_long(type->totym(), 0);  // error recovery

But actually I think it's better to put the check into BinExp::toElemBin
(e2ir.c line 1968), since this test should be performed for all operations,
and then remove the check from AddAssignExp.

line 1930:

elem *AddAssignExp::toElem(IRState *irs)
{
    return toElemBin(irs,OPaddass);
}

line 1968:

elem *BinExp::toElemBin(IRState *irs,int op)
{
    //printf("toElemBin() '%s'\n", toChars());
+    Type *tb1 = e1->type->toBasetype();
+    Type *tb2 = e2->type->toBasetype();
+
+    if ((tb1->ty == Tarray || tb1->ty == Tsarray) &&
+        (tb2->ty == Tarray || tb2->ty == Tsarray) && 
+        (op == OPadd || op == OPmin || op == OPmul ||
+         op == OPdiv || op == OPmod ||
+         op == OPaddass || op == OPminass || op == OPmulass ||
+         op == OPdivass || op == OPmodass)
+       )
+    {
+        error("Array operation %s not implemented", toChars());
+        return el_long(type->totym(), 0);  // error recovery
+    }

    tym_t tym = type->totym();

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list