www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 13023] New: optimizer produces wrong code for comparision and


          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

void main()
  ulong n = (1UL<<32)*2;

Jul 02 2014