3049 – ICE(cod4.c) or segfault: Array operation on void[] array

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 3049 - ICE(cod4.c) or segfault: Array operation on void[] array
Summary: ICE(cod4.c) or segfault: Array operation on void[] array
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D1 (retired)
Hardware: All All
: P2 normal
Assignee: Walter Bright
URL:
Keywords: diagnostic, ice-on-invalid-code, patch
Depends on:
Blocks:
Reported: 2009年06月03日 16:17 UTC by Don
Modified: 2014年04月18日 09:12 UTC (History)
0 users

See Also:


Attachments
Add an attachment (proposed patch, testcase, etc.)

Note You need to log in before you can comment on or make changes to this issue.
Description Don 2009年06月03日 16:17:04 UTC
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 Don 2009年06月10日 17:31:43 UTC
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;
 }
---
Comment 2 Walter Bright 2009年10月06日 02:16:33 UTC
Fixed dmd 1.048 and 2.033


AltStyle によって変換されたページ (->オリジナル) /