www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 14829] New: wrong code with -O -inline

https://issues.dlang.org/show_bug.cgi?id=14829

          Issue ID: 14829
           Summary: wrong code with -O -inline
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Keywords: wrong-code
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: ag0aep6g gmail.com

Reduced from issue 14827.

----
int[] save(int[] a) {return a;}
bool isWhite(int c) {return c != 1;}

int decodeImpl(int[] str)
{
    if (true) return 1;
}

int[] stripLeft(int[] str)
{
    while (true)
    {
        int[] s = str.save;
        int dc = decodeImpl(str);
        str = str[1 .. $];
        bool w = isWhite(dc);
        assert(!w); /* passes */
        if (!w) return s;
    }
}

void main ()
{
    assert ([2].stripLeft == [2]); /* fails with -O -inline */
}
----

--
Jul 26 2015