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

--- Comment #0 from David Simcha <> 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"];

Configure issuemail:
------- You are receiving this mail because: -------

Reply via email to