Tested with: trunk r149624 # ./gcc -v Using built-in specs. Target: x86_64-unknown-linux-gnu Configured with: ../configure --enable-languages=c,c++ --prefix=/mnt/svn/gcc-trunk/build/ Thread model: posix gcc version 4.5.0 20090714 (experimental) (GCC) and gentoo's 4.4.0, 4.5_alpha20090709 The following code is miscompiled ------------------------ // command line: gcc tst.c -c -o tst.o -O1 // or: with -m32 int f3(int i) { return (i < 4 && i >= 0) ? i : 4; } ------------------------ Resulting (relevant) asm is: ------------------------ f3: .LFB0: .cfi_startproc cmpl $4, %edi movl $4, %eax cmovle %edi, %eax ret .cfi_endproc ------------------------ For the following code: ------------------------ // command line: gcc tst.c -c -o tst.o -O1 // or: with -m32 #include <stdio.h> int f3(int i) { return (i < 4 && i >= 0) ? i : 4; } int main() { printf("%d %d %d\n", f3(-1), f3(2), f3(5)); } ------------------------ Result is "-1 2 4", but it should be "4 2 4" (as it is with -O0)
Created attachment 18194 [details] preprocessed source most of that file is content of included <stdio.h>
Also happens with i686-pc-linux-gnu with gcc-4.4.1 (gcc-4_4-branch, r149543).
Confirmed, introduced between r134374 + r134467, looking into it.
Indeed, caused by http://gcc.gnu.org/ml/gcc-patches/2008-04/msg01303.html (r134384).
This bug may result in unreliable binary outputs, why is it targeted for fixing in 4.4.2 and not in 4.4.1?
I'm already bootstrapping/regtesting a fix, will post afterwards. If it gets approved quickly, I'll include it in 4.4.1-rc1 I plan to roll today.
Patch posted: http://gcc.gnu.org/ml/gcc-patches/2009-07/msg00842.html
Subject: Bug 40747 Author: jakub Date: Wed Jul 15 10:17:54 2009 New Revision: 149675 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=149675 Log: PR middle-end/40747 * fold-const.c (fold_cond_expr_with_comparison): When folding < and <= to MIN, make sure the MIN uses the same type as the comparison's operands. * gcc.c-torture/execute/pr40747.c: New test. Added: trunk/gcc/testsuite/gcc.c-torture/execute/pr40747.c Modified: trunk/gcc/ChangeLog trunk/gcc/fold-const.c trunk/gcc/testsuite/ChangeLog
Subject: Bug 40747 Author: jakub Date: Wed Jul 15 11:23:22 2009 New Revision: 149681 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=149681 Log: PR middle-end/40747 * fold-const.c (fold_cond_expr_with_comparison): When folding < and <= to MIN, make sure the MIN uses the same type as the comparison's operands. * gcc.c-torture/execute/pr40747.c: New test. Added: branches/gcc-4_4-branch/gcc/testsuite/gcc.c-torture/execute/pr40747.c Modified: branches/gcc-4_4-branch/gcc/ChangeLog branches/gcc-4_4-branch/gcc/fold-const.c branches/gcc-4_4-branch/gcc/testsuite/ChangeLog
Fixed.
*** Bug 40547 has been marked as a duplicate of this bug. ***