Bug 18534 – Wrong code for ?: operator when compiling with -O
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2018-02-27T19:53:28Z
Last change time
2018-03-20T11:26:41Z
Keywords
wrong-code
Assigned to
No Owner
Creator
hsteoh
Comments
Comment #0 by hsteoh — 2018-02-27T19:53:28Z
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.