Bug 35540 - [4.3/4.4 Regression]: Segmentation fault with __builtin_parity() and -O1
Summary: [4.3/4.4 Regression]: Segmentation fault with __builtin_parity() and -O1
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 4.3.0
: P3 normal
Target Milestone: 4.3.1
Assignee: Uroš Bizjak
URL:
Keywords:
Depends on: 37197
Blocks:
  Show dependency treegraph
 
Reported: 2008-03-11 15:11 UTC by Rudolf Schürer
Modified: 2008-03-12 06:42 UTC (History)
3 users (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
Known to work: 4.2.3
Known to fail: 4.3.0 4.4.0
Last reconfirmed: 2008-03-11 15:43:20


Attachments
The C source file triggering the bug (114 bytes, text/plain)
2008-03-11 15:13 UTC, Rudolf Schürer
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Rudolf Schürer 2008-03-11 15:11:24 UTC
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.
Comment 1 Rudolf Schürer 2008-03-11 15:13:11 UTC
Created attachment 15297 [details]
The C source file triggering the bug
Comment 2 Rudolf Schürer 2008-03-11 15:23:44 UTC
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 ()
Comment 3 Uroš Bizjak 2008-03-11 15:43:20 UTC
Mine.
Comment 4 H.J. Lu 2008-03-11 15:53:14 UTC
It was introduced between revisions 121818 and 122326.
Comment 5 uros 2008-03-11 19:19:31 UTC
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

Comment 6 uros 2008-03-12 06:37:50 UTC
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

Comment 7 Uroš Bizjak 2008-03-12 06:42:16 UTC
Fixed.