D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 3176 - Compiler hangs on poorly formed mixin in variadic template
Summary: Compiler hangs on poorly formed mixin in variadic template
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D1 (retired)
Hardware: x86_64 All
: P2 major
Assignee: No Owner
URL:
Keywords: ice-on-invalid-code, patch
Depends on:
Blocks:
 
Reported: 2009-07-14 20:29 UTC by Jesse Phillips
Modified: 2014-04-18 09:12 UTC (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Jesse Phillips 2009-07-14 20:29:18 UTC
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 Don 2009-08-05 07:15:26 UTC
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 Don 2009-08-05 08:18:18 UTC
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 Don 2009-08-05 19:07:57 UTC
/*
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 Walter Bright 2009-10-13 13:46:24 UTC
Fixed dmd 1.049 and 2.034