Bug 2829 – ICE(expression.c) static array block-initialized in struct literal
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
All
Creation time
2009-04-10T03:59:00Z
Last change time
2014-04-18T09:12:04Z
Keywords
ice-on-invalid-code, patch, rejects-valid
Assigned to
bugzilla
Creator
kamm-removethis
Comments
Comment #0 by kamm-removethis — 2009-04-10T03:59:18Z
struct S { int[3] i; }
const S s = S(5);
const int i = s.i[10];
generates
int[3u] 0x82ee4e0
dmd: expression.c:1352: virtual dinteger_t IntegerExp::toInteger(): Assertion `0' failed.
Aborted
Comment #1 by clugdbug — 2009-06-02T16:25:14Z
Title was: ICE(expression.c) accessing out of bounds element in a static array constant initialized through struct literal
Changed since it is more general. Applies to D2 as well as D1.
-- ANALYSIS --
This is crashing in constfold.c, line 1218, crashing while doing e1->toChars() while printing the error message. But there are also rejects-valid bugs with the
same root cause: block assignment of arrays is buggy.
The root cause is expression.c, StructLiteralExp::getField().
In the line e->type=type is incorrect if e->type is of type K, and 'type'
is a static array of type K.
PATCH: in such cases, create and populate an array literal.
--- expression.c (revision 27)
+++ expression.c (working copy)
@@ -3236,7 +3236,18 @@
if (e)
{
e = e->copy();
+ if (e->type != type && type->ty == Tsarray)
+ { TypeSArray *tsa = (TypeSArray *)type;
+ uinteger_t length = tsa->dim->toInteger();
+ Expressions * z = new Expressions;
+ z->setDim(length);
+ for (int q=0; q<length; ++q) z->data[q] = e->copy();
+ ArrayLiteralExp * ac = new ArrayLiteralExp(loc, z);
+ ac -> type = type;
+ e = ac;
+ } else {
e->type = type;
+ }
}
}
return e;
== TEST CASE 2 -- ICE(expression.c) == For D2, change 'enum' to 'const' for D1.
struct S { int i[3]; }
enum S s = S(8);
int * p = & s.i;
// Test case 3 -- rejects-valid
struct Q { double i[3]; }
enum Q q = Q(8.0*real.min);
const x = q.i[2];