Consider the following C-Program main.c: /*********************************************/ int f (unsigned* a, int b) { return b ? 1 : __builtin_parity(*a); } int main() { unsigned a = 0; return f(&a, 0); } /*********************************************/ Using GCC 4.3.0: $ /usr/local/gcc-4.3.0/bin/gcc-4.3.0 -v Using built-in specs. Target: i686-pc-linux-gnu Configured with: ../gcc-4.3.0/configure --prefix=/usr/local/gcc-4.3.0 --program-suffix=-4.3.0 --with-mpfr=/usr/local/ --with-tune=pentium4 --with-arch=pentium4 --enable-languages=c,c++,fortran,java,objc Thread model: posix gcc version 4.3.0 (GCC) When compliled with -O0, the program runs successfully: $ /usr/local/gcc-4.3.0/bin/gcc-4.3.0 -O0 main.c $ ./a.out When complied with -O1, the program segfaults. $ /usr/local/gcc-4.3.0/bin/gcc-4.3.0 -O1 main.c $ ./a.out Segmentation fault The program runs successfully when compiled with -O2 or -O3. The program runs successfully with GCC 4.2.3 in all optimization levels.
Created attachment 15297 [details] The C source file triggering the bug
The assembler code for f() (as listed by "objdump -d a.out") is as follows: 0804838c <f>: 804838c: 55 push %ebp 804838d: 89 e5 mov %esp,%ebp 804838f: b8 01 00 00 00 mov $0x1,%eax 8048394: 83 7d 0c 00 cmpl $0x0,0xc(%ebp) 8048398: 75 12 jne 80483ac <f+0x20> 804839a: 8b 45 08 mov 0x8(%ebp),%eax 804839d: 0f b7 40 02 movzwl 0x2(%eax),%eax 80483a1: 66 33 00 xor (%eax),%ax 80483a4: 30 e0 xor %ah,%al 80483a6: 0f 9b c0 setnp %al 80483a9: 0f b6 c0 movzbl %al,%eax 80483ac: 5d pop %ebp 80483ad: c3 ret GDB says that: Program received signal SIGSEGV, Segmentation fault. 0x080483a1 in f ()
Mine.
It was introduced between revisions 121818 and 122326.
Subject: Bug 35540 Author: uros Date: Tue Mar 11 19:18:48 2008 New Revision: 133118 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=133118 Log: PR target/35540 * config/i386/i386.md (paritysi2, paritydi2): Use register_operand constraint for operand 1. (paritysi2_cmp): Use register_operand constraint for operand 2. Use earlyclobber modifier for operand 1. Remove support for memory operands. (paritydi2_cmp): Use register_operand constraint for operand 3. Use earlyclobber modifier for operand 1. Remove support for memory operands. testsuite/ChangeLog: PR target/35540 * gcc.target/i386/pr35540.c: New test. Added: trunk/gcc/testsuite/gcc.target/i386/pr35540.c Modified: trunk/gcc/ChangeLog trunk/gcc/config/i386/i386.md trunk/gcc/testsuite/ChangeLog
Subject: Bug 35540 Author: uros Date: Wed Mar 12 06:37:10 2008 New Revision: 133135 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=133135 Log: PR target/35540 * config/i386/i386.md (paritysi2, paritydi2): Use register_operand constraint for operand 1. (paritysi2_cmp): Use register_operand constraint for operand 2. Use earlyclobber modifier for operand 1. Remove support for memory operands. (paritydi2_cmp): Use register_operand constraint for operand 3. Use earlyclobber modifier for operand 1. Remove support for memory operands. testsuite/ChangeLog: PR target/35540 * gcc.target/i386/pr35540.c: New test. Added: branches/gcc-4_3-branch/gcc/testsuite/gcc.target/i386/pr35540.c - copied unchanged from r133118, trunk/gcc/testsuite/gcc.target/i386/pr35540.c Modified: branches/gcc-4_3-branch/gcc/ChangeLog branches/gcc-4_3-branch/gcc/config/i386/i386.md branches/gcc-4_3-branch/gcc/testsuite/ChangeLog
Fixed.