public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/51315] New: gcc 4.6.2 miscompilation with -ftree-sra (included in -O2) on Debian/sparc
@ 2011-11-26 19:21 jurij at wooyd dot org
  2011-11-29  4:54 ` [Bug tree-optimization/51315] " jurij at wooyd dot org
                   ` (17 more replies)
  0 siblings, 18 replies; 19+ messages in thread
From: jurij at wooyd dot org @ 2011-11-26 19:21 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51315

             Bug #: 51315
           Summary: gcc 4.6.2 miscompilation with -ftree-sra (included in
                    -O2) on Debian/sparc
    Classification: Unclassified
           Product: gcc
           Version: 4.6.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: jurij@wooyd.org


Created attachment 25914
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=25914
Preprocessed test case code

Hello,

There appears to be a bug in gcc (reproducible with gcc 4.6.2 currently in
Debian unstable), noticed due to Ruby 1.9.x build failures on sparc. The code
gets miscompiled resulting either in bogus results or bus error with -O2,
however the problem goes away when building with -O2 -fno-tree-sra, so tree
optimization is highly suspect. Attached please find a simple standalone case
in preprocessed form, instructions on how to reproduce are included below.

Compiling with -O2, generates broken code:

jurij@debian:~/ftree-sra$ gcc -v -save-temps -g -O2 pack.c -o pack
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/sparc-linux-gnu/4.6/lto-wrapper
Target: sparc-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 4.6.2-5'
--with-bugurl=file:///usr/share/doc/gcc-4.6/README.Bugs
--enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr
--program-suffix=-4.6 --enable-shared --enable-linker-build-id
--with-system-zlib --libexecdir=/usr/lib --without-included-gettext
--enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.6
--libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug
--enable-libstdcxx-time=yes --enable-plugin --enable-objc-gc
--enable-targets=all --with-long-double-128 --enable-checking=release
--build=sparc-linux-gnu --host=sparc-linux-gnu --target=sparc-linux-gnu
Thread model: posix
gcc version 4.6.2 (Debian 4.6.2-5) 
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-g' '-O2' '-o' 'pack'
'-mcpu=ultrasparc'
 /usr/lib/gcc/sparc-linux-gnu/4.6/cc1 -E -quiet -v -imultilib . -imultiarch
sparc-linux-gnu -D__sparc_v9__ pack.c -mcpu=ultrasparc -g -fworking-directory
-O2 -fpch-preprocess -o pack.i
ignoring nonexistent directory "/usr/local/include/sparc-linux-gnu"
ignoring nonexistent directory
"/usr/lib/gcc/sparc-linux-gnu/4.6/../../../../sparc-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/lib/gcc/sparc-linux-gnu/4.6/include
 /usr/local/include
 /usr/lib/gcc/sparc-linux-gnu/4.6/include-fixed
 /usr/include/sparc-linux-gnu
 /usr/include
End of search list.
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-g' '-O2' '-o' 'pack'
'-mcpu=ultrasparc'
 /usr/lib/gcc/sparc-linux-gnu/4.6/cc1 -fpreprocessed pack.i -quiet -dumpbase
pack.c -mcpu=ultrasparc -auxbase pack -g -O2 -version -o pack.s
GNU C (Debian 4.6.2-5) version 4.6.2 (sparc-linux-gnu)
    compiled by GNU C version 4.6.2, GMP version 5.0.2, MPFR version 3.1.0-p3,
MPC version 0.9
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
GNU C (Debian 4.6.2-5) version 4.6.2 (sparc-linux-gnu)
    compiled by GNU C version 4.6.2, GMP version 5.0.2, MPFR version 3.1.0-p3,
MPC version 0.9
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 25439f394be45745a7ad849d22cd1d06
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-g' '-O2' '-o' 'pack'
'-mcpu=ultrasparc'
 as -s -Av9a -32 -relax -o pack.o pack.s
COMPILER_PATH=/usr/lib/gcc/sparc-linux-gnu/4.6/:/usr/lib/gcc/sparc-linux-gnu/4.6/:/usr/lib/gcc/sparc-linux-gnu/:/usr/lib/gcc/sparc-linux-gnu/4.6/:/usr/lib/gcc/sparc-linux-gnu/
LIBRARY_PATH=/usr/lib/gcc/sparc-linux-gnu/4.6/:/usr/lib/gcc/sparc-linux-gnu/4.6/../../../sparc-linux-gnu/:/usr/lib/gcc/sparc-linux-gnu/4.6/../../../../lib/:/lib/sparc-linux-gnu/:/lib/../lib/:/usr/lib/sparc-linux-gnu/:/usr/lib/../lib/:/usr/lib/gcc/sparc-linux-gnu/4.6/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-g' '-O2' '-o' 'pack'
'-mcpu=ultrasparc'
 /usr/lib/gcc/sparc-linux-gnu/4.6/collect2 --build-id --no-add-needed
--eh-frame-hdr -m elf32_sparc -Y P,/usr/lib -dynamic-linker /lib/ld-linux.so.2
-relax -o pack /usr/lib/gcc/sparc-linux-gnu/4.6/../../../sparc-linux-gnu/crt1.o
/usr/lib/gcc/sparc-linux-gnu/4.6/../../../sparc-linux-gnu/crti.o
/usr/lib/gcc/sparc-linux-gnu/4.6/crtbegin.o -L/usr/lib/gcc/sparc-linux-gnu/4.6
-L/usr/lib/gcc/sparc-linux-gnu/4.6/../../../sparc-linux-gnu
-L/usr/lib/gcc/sparc-linux-gnu/4.6/../../../../lib -L/lib/sparc-linux-gnu
-L/lib/../lib -L/usr/lib/sparc-linux-gnu -L/usr/lib/../lib
-L/usr/lib/gcc/sparc-linux-gnu/4.6/../../.. pack.o -lgcc --as-needed -lgcc_s
--no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed
/usr/lib/gcc/sparc-linux-gnu/4.6/crtend.o
/usr/lib/gcc/sparc-linux-gnu/4.6/../../../sparc-linux-gnu/crtn.o
jurij@debian:~/ftree-sra$ 

Resulting binary crashes with a 'bus error':

jurij@debian:~/ftree-sra$ gdb pack
GNU gdb (GDB) 7.3-debian
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "sparc-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/jurij/ftree-sra/pack...done.
(gdb) run
Starting program: /home/jurij/ftree-sra/pack 
do_something called with item=-32767

Program received signal SIGBUS, Bus error.
pack_unpack (s=0x1068a "\377\376\035\300", p=0x10692 "") at pack.c:62
62            memcpy (v.a, s, sizeof (int32_t));
(gdb) disass
Dump of assembler code for function pack_unpack:
   0x000104a0 <+0>:    save  %sp, -96, %sp
   0x000104a4 <+4>:    call  0x207d0 <strlen@plt>
   0x000104a8 <+8>:    mov  %i1, %o0
   0x000104ac <+12>:    add  %i1, %o0, %i5
   0x000104b0 <+16>:    cmp  %i1, %i5
   0x000104b4 <+20>:    bcs,a   %icc, 0x104e0 <pack_unpack+64>
   0x000104b8 <+24>:    ldub  [ %i1 ], %g1
   0x000104bc <+28>:    rett  %i7 + 8
   0x000104c0 <+32>:    ldsb  [ %o0 ], %o0
   0x000104c4 <+36>:    cmp  %g1, 0x73
   0x000104c8 <+40>:    be,a,pn   %icc, 0x10518 <pack_unpack+120>
   0x000104cc <+44>:    lduh  [ %i0 ], %o0
   0x000104d0 <+48>:    cmp  %i1, %i5
   0x000104d4 <+52>:    be,a,pn   %icc, 0x10510 <pack_unpack+112>
   0x000104d8 <+56>:    ldsb  [ %i0 ], %i0
   0x000104dc <+60>:    ldub  [ %i1 ], %g1
   0x000104e0 <+64>:    sll  %g1, 0x18, %g1
   0x000104e4 <+68>:    sra  %g1, 0x18, %g1
   0x000104e8 <+72>:    cmp  %g1, 0x6c
   0x000104ec <+76>:    bne  %icc, 0x104c4 <pack_unpack+36>
   0x000104f0 <+80>:    inc  %i1
=> 0x000104f4 <+84>:    ld  [ %i0 ], %o0
   0x000104f8 <+88>:    call  0x10480 <do_something>
   0x000104fc <+92>:    add  %i0, 4, %i0
   0x00010500 <+96>:    cmp  %i1, %i5
   0x00010504 <+100>:    bne,a   %icc, 0x104e0 <pack_unpack+64>
   0x00010508 <+104>:    ldub  [ %i1 ], %g1
   0x0001050c <+108>:    ldsb  [ %i0 ], %i0
   0x00010510 <+112>:    rett  %i7 + 8
   0x00010514 <+116>:    nop 
   0x00010518 <+120>:    add  %i0, 2, %i0
   0x0001051c <+124>:    sll  %o0, 0x10, %o0
   0x00010520 <+128>:    call  0x10480 <do_something>
   0x00010524 <+132>:    sra  %o0, 0x10, %o0
   0x00010528 <+136>:    b  %xcc, 0x104d4 <pack_unpack+52>
   0x0001052c <+140>:    cmp  %i1, %i5
End of assembler dump.
(gdb) info reg i0
i0             0x1068a    67210
(gdb) 

Building with -fno-tree-sra fixes the problem:

jurij@debian:~/ftree-sra$ gcc -g -O2 -fno-tree-sra pack.c -o pack
jurij@debian:~/ftree-sra$ ./pack 
do_something called with item=-32767
do_something called with item=-123456
jurij@debian:~/ftree-sra$ 

This bug is tracked in Debian as http://bugs.debian.org/635126. Please let me
know if you would like any other information.

Thanks.


^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2012-01-05 22:25 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-11-26 19:21 [Bug tree-optimization/51315] New: gcc 4.6.2 miscompilation with -ftree-sra (included in -O2) on Debian/sparc jurij at wooyd dot org
2011-11-29  4:54 ` [Bug tree-optimization/51315] " jurij at wooyd dot org
2011-11-29  9:58 ` mikpe at it dot uu.se
2011-11-29 10:34 ` mikpe at it dot uu.se
2011-12-01  9:27 ` jurij at wooyd dot org
2011-12-03 18:37 ` mikpe at it dot uu.se
2011-12-04 18:21 ` [Bug tree-optimization/51315] [4.6 regression] unaligned memory accesses generated with -ftree-sra ebotcazou at gcc dot gnu.org
2011-12-06 14:17 ` [Bug tree-optimization/51315] [4.6/4.7 " rguenth at gcc dot gnu.org
2011-12-06 16:42 ` ebotcazou at gcc dot gnu.org
2011-12-07 11:38 ` rguenther at suse dot de
2011-12-08  9:11 ` ebotcazou at gcc dot gnu.org
2011-12-08  9:15 ` ebotcazou at gcc dot gnu.org
2011-12-08  9:26 ` ebotcazou at gcc dot gnu.org
2011-12-08 13:24 ` gjl at gcc dot gnu.org
2011-12-08 14:22 ` gjl at gcc dot gnu.org
2011-12-10 12:01 ` jurij at wooyd dot org
2011-12-10 12:10 ` ebotcazou at gcc dot gnu.org
2012-01-05 22:22 ` ebotcazou at gcc dot gnu.org
2012-01-05 22:25 ` ebotcazou at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).