For the program below, gcc optimization produces wrong result. g++ does the same for a cpp version of this program. gcc 1.c -Wall 1 0 1
gcc 1.c -Wall -O ./a.out 1 1 1 The program is as following #include <stdio.h> int f(unsigned int x) { return x>>31||(-x)>>31; } int main() { printf("%d\n", f(1)); printf("%d\n", f(0)); printf("%d\n", f(-1)); return 0; } -- Summary: Optimization results in wrong result on expression x>>31||(-x)>>31 Product: gcc Version: 4.4.3 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: ylsdd at tttan dot com GCC build triplet: x86_64-linux-gnu GCC host triplet: x86_64-linux-gnu GCC target triplet: x86_64-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45262