Thread overview
[Issue 6337] New: ICE when touching member variable of struct during CTFE
Jul 17, 2011
Johann MacDonagh
[Issue 6337] [CTFE] ICE when touching member variable of struct during CTFE
Jul 22, 2011
Don
Jul 22, 2011
Walter Bright
Jul 28, 2011
Don
Sep 06, 2011
Don
July 17, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6337

           Summary: ICE when touching member variable of struct during
                    CTFE
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: johann.macdonagh@gmail.com


--- Comment #0 from Johann MacDonagh <johann.macdonagh@gmail.com> 2011-07-16 20:37:26 PDT ---
This one is weird. I narrowed it down to this test case, although I admit this is still pretty long.

struct Test
{
    string s;

    this(string s)
    {
        this.s = s;
    }

    string ctfe()
    {
        dchar c = s[0];

        if (test1(c))
        {
            for (c = next(c); test2(c); c = next(c))
            {
            }
        }

        return "ctfe";
    }

    dchar next(dchar curPeek)
    {
        if (curPeek != dchar.init)
        {
            s = s[1..$];

            return s.length > 0 ? s[0] : dchar.init;
        }

        return dchar.init;
    }
}

bool test1(dchar c)
{
    return (c >= 'a' && c <= 'z' ||
            c >= 'A' && c <= 'Z' ||
            c == '_');
}

bool test2(dchar c)
{
    return (test1(c) ||
            c >= '0' && c <= '9' );
}

void main(string[] args)
{
    // If this is auto then this executes just fine at runtime
    enum x = Test("abc").ctfe();
}

This will ICE with an out of memory error. I believe it's going into an infinite loop.

If you replace the body of test2 with "return false", then CTFE runs just fine.

This only happens on 2.054. On 2.053 (when you make appropriate modifications to the test case) it crashes DMD.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 22, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6337


Don <clugdbug@yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |wrong-code
                 CC|                            |clugdbug@yahoo.com.au


--- Comment #1 from Don <clugdbug@yahoo.com.au> 2011-07-22 03:16:07 PDT ---
Reduced test case:

struct Bug6337
{
    int k;
    void six() {
        k = 6;
    }
    int ctfe()
    {
        six();
        return k;
    }
}
static assert( Bug6337().ctfe() == 6);

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 22, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6337


Walter Bright <bugzilla@digitalmars.com> changed:

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


--- Comment #2 from Walter Bright <bugzilla@digitalmars.com> 2011-07-22 13:57:58 PDT ---
https://github.com/D-Programming-Language/dmd/commit/dc787833ee11ec6313503022b64e2a4aec61e7b6

https://github.com/D-Programming-Language/dmd/commit/501222f6d3d21b6b551851176cc6d5510022e737

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 28, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6337


Don <clugdbug@yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla@kyllingen.net


--- Comment #3 from Don <clugdbug@yahoo.com.au> 2011-07-28 00:04:06 PDT ---
*** Issue 6390 has been marked as a duplicate of this issue. ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
September 06, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6337


Don <clugdbug@yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |soywiz@gmail.com


--- Comment #4 from Don <clugdbug@yahoo.com.au> 2011-09-06 00:56:59 PDT ---
*** Issue 6323 has been marked as a duplicate of this issue. ***

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