3522 – ICE(cg87.c): variable*array[].

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 3522 - ICE(cg87.c): variable*array[].
Summary: ICE(cg87.c): variable*array[].
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D1 (retired)
Hardware: Other Windows
: P2 normal
Assignee: No Owner
URL:
Keywords: ice-on-invalid-code, patch
Depends on:
Blocks:
Reported: 2009年11月18日 07:13 UTC by Don
Modified: 2014年04月18日 09:12 UTC (History)
2 users (show)

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年11月18日 07:13:26 UTC
void main() {
 double[] foo = [1.0, 2.0, 3.0];
 double y = 2.0;
 double[] c = y * foo[];
}
Internal error: backend\cg87.c 1363
Related to bug 2549.
Doesn't ICE with foo[]*y; generates bad code instead. Applies to both D1 and D2.
Comment 1 Don 2010年04月28日 20:55:10 UTC
This patch also fixes:
bug 2549 Segfault on array multiplication.
bug 3066 Array operation without a slice as the lvalue accepted, bad codegen
bug 3817 Array op: wrong error message
The root cause is that array operations which require memory allocations are not handled in the front-end. At entry to the backend, no array ops should still exist inside expressions. Currently, only arr[]+arr[] and arr[]-arr[] generate error messages; all other cases get passed through to the backend, resulting in bad code generation or an ICE.
The error messages just need to be expanded to cover the other cases.
(Note that when the front-end supports these types of operations, this test is still useful -- it acts as an assert for the backend).
PATCH:
e2ir.c, around line 2098. AddExp, MinExp catch errors, but the other array ops don't.
They all need to catch var*arr, arr*var as well as arr*arr.
(The var+arr check is required for the example in the comments in 3066).
The error message is confusing (this is bug 3817), for all of them should be something like:
Should be "Array operation %s not implemented (requires memory allocation)"
NegExp needs to be treated, as well. For each of AddExp, MinExp, MulExp, DivExp,
the code should be of this form (with only the OPmul line changing).
elem *MulExp::toElem(IRState *irs)
{ elem *e;
 Type *tb1 = e1->type->toBasetype();
 Type *tb2 = e2->type->toBasetype();
 if ((tb1->ty == Tarray || tb1->ty == Tsarray) ||
 (tb2->ty == Tarray || tb2->ty == Tsarray)
 )
 {
 error("Array operation %s not implemented (requires memory allocation)", toChars());
 e = el_long(type->totym(), 0); // error recovery
 }
 else
 e = toElemBin(irs, OPmul);
 return e;
}
Comment 2 bearophile_hugs 2010年04月29日 02:28:23 UTC
> The error message is confusing (this is bug 3817), for all of them should be
> something like:
> Should be "Array operation %s not implemented (requires memory allocation)"
I don't understand.
In a program like:
void main() {
 int[] a1 = [1];
 int[] a2 = [2];
 int[] a3;
 a3 = a1 + a2;
}
I think the compiler has to write an error message like:
test.d(5): Error: Array operator + not supported (have you forgotten the []?)
So this is more correct code:
void main() {
 int[] a1 = [1];
 int[] a2 = [2];
 int[] a3;
 a3[] = a1[] + a2[];
}
But array ops don't allocate memory, so the a3 array can't be filled. This prints nothing:
import std.stdio: writeln;
void main() {
 int[] a1 = [1];
 int[] a2 = [2];
 int[] a3;
 a3[] = a1[] + a2[];
 writeln(a3);
}
This other error can be found at runtime...
Comment 3 Walter Bright 2010年04月29日 21:05:19 UTC
Changeset 460
Comment 4 Don 2010年05月05日 19:07:20 UTC
Fixed DMD2.044


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