Bug 3006 – ICE(e2ir.c, tocsym.c) template module using array operation

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
Windows
Creation time
2009-05-17T22:55:00Z
Last change time
2014-04-18T09:12:05Z
Keywords
ice-on-valid-code, patch
Assigned to
bugzilla
Creator
rinick

Comments

Comment #0 by rinick — 2009-05-17T22:55:04Z
dmd testmodule.d test.d -oftest Internal error: e2ir.c 632 testmodule.d: ----------------------------------- module testmodule; template foo(T) { void foo() { T[3] a,b,c; a[] = b[] + c[]; } } ----------------------------------- test.d: ----------------------------------- import testmodule; void main() { foo!ulong(); // long, double, real, cfloat etc. have this bug // int, short, float etc. work fine } -----------------------------------
Comment #1 by clugdbug — 2009-05-19T01:18:11Z
Fails also on D1 with a bizarre error message. Where the heck did variable 'p' come from? dmd bug2.d bug.d (order is important). ================ Error: variable p forward referenced Error: variable p forward referenced linkage = 0 Assertion failure: '0' on line 262 in file 'tocsym.c' abnormal program termination =========== bug.d ------ import bug2; void main() { foo!(long)(); } ------ bug2.d ------ void foo(T)() { long[] a; a[] = -a[]; }
Comment #2 by clugdbug — 2009-06-03T16:07:40Z
Root cause: semantic3 never gets run on the function which is created, if it's compiled in a module which doesn't instantiate the template it's in. To fix this, we can run its semantic3 immediately, since we're already in semantic3 for this module. BTW: It also seems to me that the back-end should have assert(FuncDeclaration->semanticRun==4) before running toObj(), to ensure semantic3 has been run (it would be a better place to ICE). BTW: FuncDeclaration::toObj() is declared but never defined or used. PATCH: Add this code to arrayop.c, BinExp::arrayOp, line 393. sc->linkage = LINKc; fd->semantic(sc); + fd->semantic2(sc); + fd->semantic3(sc); sc->pop(); // TEST CASE 1. Compilation order is important. dmd bugx.d bug.d ------ bug.d ------ import bugx; void main(){ foo!(long)(); } ------ bugx.d ------ void foo(T)() { long[] a; a[] = -a[]; } // TEST CASE 2: replace bugx with: void foo(T)() { T[] a; a[] = -a[]; }
Comment #3 by hskwk — 2009-08-20T13:06:22Z
(In reply to comment #2) Much thanks for your analysis, Don. I met almost the same error today. // bugx.d void foo() { real[3] s, a, b; s[] = a[] + b[]; } // bug.d void bar() { foo; // p2 Internal error: e2ir.c 632 @ DMD 2.031 } This ICE occurs without template in this case. Compiling bugx.d cause no error, calling foo from OTHER module cause ICE. Besides, compiler switchs affect: ( -release && !-unittest ) cause this ICE. Anyway the root cause is obviously the same.
Comment #4 by bugzilla — 2009-10-13T13:45:08Z
Fixed dmd 1.049 and 2.034