Bug 3049 – ICE(cod4.c) or segfault: Array operation on void[] array
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
All
OS
All
Creation time
2009-06-03T16:17:00Z
Last change time
2014-04-18T09:12:06Z
Keywords
diagnostic, ice-on-invalid-code, patch
Assigned to
bugzilla
Creator
clugdbug
Comments
Comment #0 by clugdbug — 2009-06-03T16:17:04Z
Array operations involving void[] can either ICE in the backend, segfault in the front-end, or generate error messages without line numbers, which refer to compiler-generated code. All have the same root cause: such operations are nonsensical.
PATCH(tested on DMD1.045+D2.030): Add this code to the start of BinExp::arrayOp(Scope *) in arrayop.c.
---
if (type == Type::terror) { return this; }
if (type->toBasetype()->nextOf()->toBasetype()->ty==Tvoid) {
error("Cannot perform array operations on void[] arrays");
return this;
}
---
// TEST CASE 1: error message with no line number, referring to
// compiler-generated code. The error is so unhelpful, it might
// as well be an ICE.
// Error: 'p0[p]' is not of arithmetic type, it is a const(void)
// Error: expression -(p0[p]) is void and has no value
void bar(){
void [] x;
x[] = -x[];
}
// TEST CASE 2: ICE(backend/cod4.c 353). On D1, it is another
// error message with no line number
void foo(T)() {
T[] a;
a[] = -a[];
}
void main(){
foo!(void)();
}
// Test case 3: segfault D1 + D2
typedef void car;
void baz(){
int [] x;
car [] y;
y[] = -x[];
}
Comment #1 by clugdbug — 2009-06-10T17:31:43Z
There was a bug in the patch I posted, it assumed that Type::terror is a unique type whereas it is currently the same as Tint32.
Fortunately, that line was not necessary anyway (it would just result in nicer error messages).
PATCH: Add this code to the start of
BinExp::arrayOp(Scope *) in arrayop.c.
---
if (type->toBasetype()->nextOf()->toBasetype()->ty==Tvoid) {
error("Cannot perform array operations on void[] arrays");
return this;
}
---