www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 6510] New: [CTFE] internal error: illegal stack value stack

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

           Summary: [CTFE] internal error: illegal stack value stack
           Product: D
           Version: D2
          Platform: Other
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: dmitry.olsh gmail.com



13:39:07 PDT ---
Recently found this one in my GSOC project. As this involves compilation of
regex at CTFE, I'm not yet able to produce small test case.

dmd spits this:
..\..\fred.d(2020): Error: CTFE internal error: illegal stack value stack

Assertion failure: 'isStackValueValid(newval)' on line 5452 in file
'interpret.c'

abnormal program termination

But anyway, what kind of situation is supposed to trigger that assert?

My dmd is 2.055 compiled form github with last commit being:

 4a1c9e7646ed9152f9644cd29d07968583888cb2

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


Don <clugdbug yahoo.com.au> changed:

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




 Recently found this one in my GSOC project. As this involves compilation of
 regex at CTFE, I'm not yet able to produce small test case.
 
 dmd spits this:
 ..\..\fred.d(2020): Error: CTFE internal error: illegal stack value stack
 
 Assertion failure: 'isStackValueValid(newval)' on line 5452 in file
 'interpret.c'
 
 abnormal program termination
 
 But anyway, what kind of situation is supposed to trigger that assert?
Any kind of CTFE assignment involving a non-reference type, that wasn't tested. The few lines involving the variable 'stack' around line 2020 will be the only ones involved in the bug. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Aug 16 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6510




02:52:42 PDT ---
Created an attachment (id=1018)
test case, stripped down parser

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




02:55:11 PDT ---
I've managed to get a resonably sized test case.
Apparently it has soemthing to do with -inline:

dmd fred.d  // Ok
dmd -inline fred.d //same error as before

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


Dmitry Olshansky <dmitry.olsh gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|[CTFE] internal error:      |[CTFE] "internal error:
                   |illegal stack value stack   |illegal stack value" when
                   |                            |compiled with -inline



02:57:06 PDT ---
I haven't made this point clear enough I think: the full source also fails only
with -inline.

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




Partially reduced test case. The UNUSED static function seems to be necessary.

struct Stack(U) {
    struct Proxy { 
        int[] data;
        void shrink(){   data = data[0..0]; }
    }
    Proxy stack;
    void pop() {
        stack.shrink();
    }
}

int bug6510() {
    static void UNUSED() {
        Stack!(int) junk;
        junk.pop();
    }
    Stack!(int) opstk;
    opstk.pop();
    return 3;
}

 static assert(bug6510());

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


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |ice-on-valid-code



Reduced slightly further. If you uncomment the alias, everything works. So this
is a bug which only happens when the semantic pass, and the inlining, is run on
Stack!int *during* CTFE.
The stack.shrink() call gets translated into:
ref Proxy ths = this.stack;
which CTFE chokes on. Note that this is a local reference variable, which isn't
legal D (it can only happen in compiler-generated code).

When the alias is present, the inline scan of bug6510() doesn't happen until
after CTFE has finished. But interestingly an inline scan of UNUSED() still
happens during CTFE.

---

struct Stack(U) {
    struct Proxy { 
        void shrink() {}
    }
    Proxy stack;
    void pop() {
        stack.shrink();
    }
}

alias Stack!int Stuck;

int bug6510() {
    static void UNUSED() {
        Stack!(int) junk;
        junk.pop();
    }
    Stack!(int) opstk;
    opstk.pop();
    return 3;
}

static assert(bug6510());

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




08:52:15 PDT ---
Thanks for getting a workaround so fast, it's just awesome.
I confirm that the full source works after I added aliases to Stack!(x).

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




Further reduced, showing that templates are not required. Seems to require an
inlined member function call to a member of a nested struct, called from a
nested function. No alias trick works in this case.

struct Stack6510 {
    struct Proxy { 
        void shrink() {}
    }
    Proxy stack;    
    void pop() {
        stack.shrink();        
    }
}

int bug6510() {
    static int used() {
        Stack6510 junk;
        junk.pop();
        return 3;
    }
    return used();
}

void main() {
    static assert(bug6510()==3);
}

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


Walter Bright <bugzilla digitalmars.com> changed:

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



22:47:32 PDT ---
https://github.com/D-Programming-Language/dmd/commit/563a291a5c7757fca87685909afa37100e3b44f6

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