[Issue 13023] New: optimizer produces wrong code for comparision and division of ulong

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Wed Jul 2 10:22:09 PDT 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 at puremagic.com
          Reporter: simon.buerger at 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);
}

--


More information about the Digitalmars-d-bugs mailing list