July 02, 2014
https://issues.dlang.org/show_bug.cgi?id=13023

          Issue ID: 13023
           Summary: optimizer produces wrong code for comparision and
                    division of ulong
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: major
          Priority: P1
         Component: DMD
          Assignee: nobody@puremagic.com
          Reporter: simon.buerger@rwth-aachen.de

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);
}

--