Bug 13023 – optimizer produces wrong code for comparision and division of ulong
Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
All
Creation time
2014-07-02T17:22:00Z
Last change time
2014-08-22T08:05:00Z
Keywords
pull, wrong-code
Assigned to
yebblies
Creator
simon.buerger
Comments
Comment #0 by simon.buerger — 2014-07-02T17:22:09Z
The following code fails when compiling with -O on a 64-bit system. Note that the problem does not appear when removing the writefln() or not passing n as a parameter. Using long instead of ulong solves the problem as well.
import std.stdio;
void foo(ulong n)
{
ulong k = 0;
writefln("%s", k>=n/2); // correctly print 'false'
if(k>=n/2) // triggers with -O
assert(false);
}
void main()
{
ulong n = (1UL<<32)*2;
foo(n);
}
Comment #1 by safety0ff.bugz — 2014-07-15T22:59:08Z
This looks like another REX issue, dmd is comparing 4 bytes instead of 8 against zero. The lower 4 bytes of (1UL<<32)*2/2 are all zero.