Public bug reported:
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.
** Affects: gcc-4.6 (Ubuntu)
Importance: Undecided
Status: New
** Tags: optimizer
** Description changed:
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;
+ 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.
--
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/1250904
Title:
variable is optimized out by mistake
To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/gcc-4.6/+bug/1250904/+subscriptions
--
ubuntu-bugs mailing list
[email protected]
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs