[Issue 8091] New: Optimizer generates wrong code when reducing comparisons.

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat May 12 13:22:52 PDT 2012


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

           Summary: Optimizer generates wrong code when reducing
                    comparisons.
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: wrong-code
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: k.hanazuki at gmail.com


--- Comment #0 from Kasumi Hanazuki <k.hanazuki at gmail.com> 2012-05-12 13:24:17 PDT ---
DMD optimizer generates a wrong code for the program below.
The second assertion unexpectedly fails if you specify -O flag to DMD,
while it passes as expected without optimization.

 $ dmd -m32 -run test.d      # fine
 $ dmd -m32 -O -run test.d   # AssertError at test(8): Assertion failure

Tested against DMDv2.060 (git HEAD) on 32-bit Linux.
Found by hos_lyric
<https://twitter.com/#!/hos_lyric_/status/201270597265793024>.

----

int solve(int n) {
    int a = (n % 3 == 0) ? 1 : (n % 3 == 1) ? 1 : 0;
    return (a != 0) ? a : 0;
}

void main() {
    assert(solve(0) ==  1);
    assert(solve(1) ==  1); // line 8, fails with -O
    assert(solve(2) ==  0);
}

-- 
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