D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 4156 - Segfault with array+=array
Summary: Segfault with array+=array
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: Other Windows
: P2 normal
Assignee: No Owner
URL:
Keywords: ice-on-invalid-code, patch
Depends on:
Blocks:
 
Reported: 2010-05-03 14:01 UTC by Don
Modified: 2015-06-09 01:28 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Don 2010-05-03 14:01:06 UTC
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();
Comment 1 Walter Bright 2010-05-16 16:07:35 UTC
changeset 493