Bug 3176 – Compiler hangs on poorly formed mixin in variadic template

Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86_64
OS
All
Creation time
2009-07-14T20:29:00Z
Last change time
2014-04-18T09:12:06Z
Keywords
ice-on-invalid-code, patch
Assigned to
nobody
Creator
Jesse.K.Phillips+D

Comments

Comment #0 by Jesse.K.Phillips+D — 2009-07-14T20:29:18Z
The code below will cause the compiler to exit with "Error: out of memory" import std.range; void main() { auto sequence = recurrence!("a[n-1] + a[n-2")(0,1); } There is a missing ] Expected a compilation error stating a malformed mixin.
Comment #1 by clugdbug — 2009-08-05T07:15:26Z
Massively reduced test case: ---- struct C(T){ ref T opIndex(size_t n) { T t; return t[0]; } } void foo(S...)(S u) { alias typeof(mixin("{ C!(void) a; return a[1;}()")) z; } void main() { foo!()(0); }
Comment #2 by clugdbug — 2009-08-05T08:18:18Z
Gets into an infinite loop while parsing the mixin. Here's a superficial patch, which turns it into an ICE with line number. Doesn't fix the root cause, but still an improvement. parse.c, line 3358: while (token.value != TOKrcurly) { + if (token.value==TOKeof) { + printf("%s Internal Compiler Error: } expected, not EOF\n", + loc.toChars()); + assert(0); + }
Comment #3 by clugdbug — 2009-08-05T19:07:57Z
/* Actually it's not so complicated as I thought -- it's just that after fixing this, it falls foul of bug #3196. On D1, this is a complete fix. PATCH: parse.c, line 2899 in DMD1.046, line 3358 in DMD2. - while (token.value != TOKrcurly) + while (token.value != TOKrcurly && token.value != TOKeof) */ // Even smaller test case: void foo(S...)(S u) { alias typeof(mixin("{ return a[1;}()")) z; } void main() { foo!()(0); }
Comment #4 by bugzilla — 2009-10-13T13:46:24Z
Fixed dmd 1.049 and 2.034