www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 4156] New: Segfault with array+=array

reply d-bugmail puremagic.com writes:
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 puremagic.com
        ReportedBy: clugdbug yahoo.com.au



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: -------
May 03 2010
parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4156


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla digitalmars.com
         Resolution|                            |FIXED



16:07:35 PDT ---
changeset 493

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