[Issue 5581] New: [64-bit] Wrong code with bitwise operations on bools

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Feb 14 20:12:57 PST 2011


http://d.puremagic.com/issues/show_bug.cgi?id=5581

           Summary: [64-bit] Wrong code with bitwise operations on bools
           Product: D
           Version: D2
          Platform: x86_64
        OS/Version: Windows
            Status: NEW
          Keywords: wrong-code
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: dsimcha at yahoo.com


--- Comment #0 from David Simcha <dsimcha at yahoo.com> 2011-02-14 20:10:25 PST ---
The following code produces obviously implausible results on 64-bit builds. 
result ends up being bigger than 0b111, which is the biggest number that
correct code could generate here.  (The correct value, which 32-bit builds
produce, is 3.)  This only happens in this test case when -O and -release are
disabled, though I think it still happens with -O and -release enabled in the
program I reduced this bug from.

import std.stdio;

void screwy(string[] data) {
    immutable size_t mid = data.length / 2;
    immutable uint result = ((cast(uint) (data[0] < data[mid])) << 2) |
                            ((cast(uint) (data[0] < data[$ - 1])) << 1) |
                            (cast(uint) (data[mid] < data[$ - 1]));

    stderr.writefln("%b", result);
}

void main() {
    auto stuff = ["a", "a", "b"];
    screwy(stuff);
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list