www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 3176] New: Out of Memory error on poorly formed recurrence function

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3176

           Summary: Out of Memory error on poorly formed recurrence
                    function
           Product: D
           Version: 2.031
          Platform: x86_64
        OS/Version: Linux
            Status: NEW
          Severity: minor
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: Jesse.K.Phillips+D gmail.com
                CC: Jesse.K.Phillips+D gmail.com


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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 14 2009
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3176


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |clugdbug yahoo.com.au





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);
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 05 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3176


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|Out of Memory error on      |Compiler hangs on poorly
                   |poorly formed recurrence    |formed recurrence function
                   |function                    |
         OS/Version|Linux                       |All
           Severity|minor                       |major





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);
 +           }

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 05 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3176


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch
            Version|2.031                       |1.045
            Summary|Compiler hangs on poorly    |Compiler hangs on poorly
                   |formed recurrence function  |formed mixin in variadic
                   |                            |template





/*
Actually it's not so complicated as I thought -- it's just that after fixing


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);
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 05 2009
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3176


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla digitalmars.com
         Resolution|                            |FIXED



13:46:24 PDT ---
Fixed dmd 1.049 and 2.034

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 13 2009