Comment 0 for bug 1250904

Revision history for this message
Shkarnikov Sergey (s-shkarnikov) wrote :

OS: Ubuntu 12.04.3 LTS
gcc version: 4.6.3-1ubuntu5

It's a modificated test case from gcc-4.6.3 testsuite (reassoc-11.c):

int main(int a, int b, int c, int d){
 int e = (a ^ b) ^ (c ^ d);
 int f = (c ^ a) ^ (b ^ d);
 return ( * ((int *)(((long unsigned ) & c) + (((long unsigned ) & e) - ((long unsigned ) & c)) *
                                                                                                                            (f <= (~(f ^ (~((b << 2 | f << 2) - (( b | f) << 2))))))))) ^ f;
}

Those terrifying expression in braces should be evaluated to "e" ( "(f <= (~(f ^ (~((b << 2 | f << 2) - (( b | f) << 2))))))" is a predicate and always equal to 1) and so test should return 0. But if the optimization is applied (O1 and greater) test returns some other value. Decompilation shows that "e" and "f" are optimized out. "f" value is evaluated in place, but evaluation of "e" is also optimized out. Then expression in braces is evaluated to some garbage value (interesting that compiler handles somehow dereferencing of "e" even after it was optimized out).

Example is quite exotic, but, in my opinion, reveals incorrect optimizer's behavior.