[Issue 4443] New: Optimizer produces wrong code for statements after loop

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Jul 10 01:27:45 PDT 2010


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

           Summary: Optimizer produces wrong code for statements after
                    loop
           Product: D
           Version: D1 & D2
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Keywords: wrong-code
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: r.sagitario at gmx.de


--- Comment #0 from Rainer Schuetze <r.sagitario at gmx.de> 2010-07-10 01:27:42 PDT ---
The code compiled from this source crashes when compiled with "dmd -O -release
test.d":

module test;

struct TokenInfo
{
    // seems important to have a "complicated" struct size (so a calculation is
necessary)
    int type;
    int StartIndex;
    int EndIndex;
}

int GetTokenInfoAt(TokenInfo[] infoArray, int col, ref TokenInfo info)
{
    for (int i = 0; i < infoArray.length; i++)
    {
        int start = infoArray[i].StartIndex;
        int end = infoArray[i].EndIndex;

        if (i == 0 && start > col)
            return -1;

        if (col >= start && col < end)
        {
            info = infoArray[i];
            return i;
        }
    }
    if (infoArray.length > 0 && col == infoArray[$-1].EndIndex)
    {
        info = infoArray[$-1];
        return infoArray.length-1;
    /* code generated for the 2 statements above:
        ov    ECX,024h[ESP]  // infoArray.ptr
        mov    EBX,020h[ESP]  // infoArray.length
        mov    EDX,ECX
        lea    ESI,[ECX*2][ECX] // uses pointer instead of length!!!
        mov    EAX,EBX
        lea    ESI,-0Ch[ESI*4][EDX] // crashes here!
        mov    EDI,014h[ESP]
        movsd
        movsd
        movsd
        lea    EAX,-1[EBX]
    */
    }
    return -1;
}

int main()
{
    TokenInfo[] arr = new TokenInfo[9];
    arr[8].EndIndex = 11;
    TokenInfo info;

    return GetTokenInfoAt(arr, 11, info);
}

The crash goes away if 
- one of the conditions in the loop are removed
- the struct size of TokenInfo is reduced to 8 bytes
- dmd is executed without "-O"
- dmd is executed without "-release"

happens for all dmd version back to 2.032 and also in dmd 1.056

-- 
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