Summary: Optimizer bug results in false if condition being
           Product: D
           Version: unspecified
          Platform: x86
        OS/Version: Linux
            Status: NEW
          Severity: critical
          Priority: P2
         Component: DMD

--- Comment #0 from Janzert <> 2009-11-29 05:28:04 PST ---
I've been chasing a bug for a few days and finally have it narrowed down to the
following example. Basically a condition that should evaluate to false is taken

The printf line below should never be executed, but it is if compiled under
linux with "dmd -release -O -inline badbranch.d".

I first started chasing this while using 1.043 but have since upgraded to 1.052
and still see it. Not surprisingly I also see it with phobos or tango. It has
also been reported to behave the same with 2.034.


extern(C) int printf(char*, ...);

struct Container
    ulong[2] bits = [0UL, 1];

int called(ulong value)
    value = value * 3;
    return value;

int test(Container* c, int[] shift)
    int count = 0;
    if (c.bits[0])
        count = 1;
    count |= called(c.bits[1]) << shift[0];
    // This is always false, but is taken anyway.
    if (c.bits[0])
        printf("Impossible output %lld\n", c.bits[0]);

    return count;

int main(char[][] args)
    int[] shift = [0];
    Container c;
    return test(&c, shift);

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

Reply via email to