[Bug 1250904] [NEW] variable is optimized out by mistake
Shkarnikov Sergey
s.shkarnikov at samsung.com
Wed Nov 13 15:54:10 UTC 2013
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
Foundations Bugs, which is subscribed to gcc-4.6 in Ubuntu.
https://bugs.launchpad.net/bugs/1250904
Title:
variable is optimized out by mistake
Status in “gcc-4.6” package in Ubuntu:
New
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.
To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/gcc-4.6/+bug/1250904/+subscriptions
More information about the foundations-bugs
mailing list