Bug 4156 – Segfault with array+=array

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
Windows
Creation time
2010-05-03T14:01:00Z
Last change time
2015-06-09T01:28:30Z
Keywords
ice-on-invalid-code, patch
Assigned to
nobody
Creator
clugdbug

Comments

Comment #0 by clugdbug — 2010-05-03T14:01:06Z
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 by bugzilla — 2010-05-16T16:07:35Z
changeset 493