www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 18534] New: Wrong code for ?: operator when compiling with -O

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

          Issue ID: 18534
           Summary: Wrong code for ?: operator when compiling with -O
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: hsteoh quickfur.ath.cx

Code:
-------
auto foo(int invert)
{
    import std.format : format;
    return format("%c", invert ? 'A' : 'A');
}
void main()
{
    auto s = foo(0);
    assert(s == "A"); // assertion fails
}
-------

Compile command:
-------
dmd -O -run test.d
-------

Inspecting the contents of s reveals that instead of containing the character
'A', it contains 0xFF instead.

Compiling without -O fixes the problem.  Replacing the conditional with just
'A' also makes the problem go away.  Seems like -O generates wrong code for the
?: operator.

--
Feb 27 2018