[Issue 3560] foreach over nested function generates wrong code

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Jul 14 12:41:41 PDT 2010


http://d.puremagic.com/issues/show_bug.cgi?id=3560


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

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Version|2.036                       |D1 & D2
            Summary|foreach on closure          |foreach over nested
                   |corrupted after function    |function generates wrong
                   |call                        |code


--- Comment #3 from Don <clugdbug at yahoo.com.au> 2010-07-14 12:41:39 PDT ---
It doesn't even need a function call, and doesn't need a closure.
Anything which modifies the EAX register before the foreach will do it.
This test case generates bad code (runtime segfault) even on D1 (even old
versions, eg D1.020).
The inner function assumes that EAX contains the context pointer, but the
foreach code doesn't set EAX. Instead, it's passing the context pointer in EBX.
=====================
void main()
{
    int localvar = 7;

    int inner(int delegate(ref int) dg) {
        int k = localvar;
        return 0;
    }

    int a = localvar * localvar; // This modifies the EAX register

    foreach (entry; &inner)
    {
    }
}

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


More information about the Digitalmars-d-bugs mailing list