https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81814

            Bug ID: 81814
           Summary: Incorrect behaviour at -O0 (conditional operator)
           Product: gcc
           Version: 8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: babokin at gmail dot com
  Target Milestone: ---

gcc trunk, x86_64.

The test case is simple and my understanding that the correct result is
0x01000000, while gcc produces 0. Slight massaging of the code (like removal of
"* m2") changes the behaviour to be correct. Not sure whom to blame - front-end
or optimizations (even though it's -O0).

> cat f.cpp
#include <stdio.h>
unsigned long long int m2 = 1;
int xxx = 0x01000000;

int main() {
    int a = ( ( (char) xxx) ? 0 : xxx) * m2;
    printf("0x%x (expected 0x01000000)\n", a);
    return 0;
}

> g++ -O0 f.cpp -o out; ./out;
0x0 (expected 0x01000000)

> clang++ -O0 f.cpp -o out; ./out
0x1000000 (expected 0x01000000)

Reply via email to