variable is optimized out by mistake

Bug #1250904 reported by Shkarnikov Sergey on 2013-11-13
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
gcc-4.6 (Ubuntu)
Undecided
Unassigned

Bug Description

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.

description: updated
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers