Bug 40493 - [4.5 Regression] New SRA miscompiled binutils
Summary: [4.5 Regression] New SRA miscompiled binutils
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.5.0
: P3 blocker
Target Milestone: 4.5.0
Assignee: Martin Jambor
URL:
Keywords:
Depends on: 40500
Blocks:
  Show dependency treegraph
 
Reported: 2009-06-19 15:32 UTC by H.J. Lu
Modified: 2009-06-25 14:21 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2009-06-22 18:57:00


Attachments
A patch to avoid warning from -Wall (466 bytes, patch)
2009-06-20 13:21 UTC, H.J. Lu
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description H.J. Lu 2009-06-19 15:32:33 UTC
New SRA, revision 147980:

http://gcc.gnu.org/ml/gcc-cvs/2009-05/msg00959.html

miscompiled binutils in CVS on Linux/x86-64:

FAIL: CFI on x86-64
FAIL: CFI on i386
FAIL: i386 general
FAIL: i386 naked reg
FAIL: i386 opcodes
FAIL: i386 opcodes (Intel disassembly)
FAIL: i386 opcodes (w/ suffix)
FAIL: i386 intel
FAIL: i386 intel-ok
FAIL: i386 katmai
FAIL: i386 ssemmx2
FAIL: i386 sse2
FAIL: i386 sub
FAIL: i386 immed
FAIL: i386 equates
FAIL: i386 amdfam10
FAIL: i386 merom
FAIL: i386 SSE4.1
FAIL: i386 SSE4.1 (Intel disassembly)
FAIL: i386 SSE4.2
FAIL: i386 SSE4.2 (Intel disassembly)
FAIL: i386 SIMD
FAIL: i386 SIMD (Intel mode)
FAIL: i386 SIMD (with suffixes)
FAIL: i386 reg
FAIL: i386 reg (Intel mode)
FAIL: i386 arch 1
FAIL: i386 arch 2
FAIL: i386 arch 3
FAIL: i386 arch 10
FAIL: i386 AES
FAIL: i386 AES (Intel mode)
FAIL: i386 PCLMUL
FAIL: i386 PCLMUL (Intel mode)
FAIL: i386 AVX
FAIL: i386 AVX (Intel disassembly)
FAIL: i386 SSE with AVX encoding
FAIL: i386 SSE without AVX equivalent
FAIL: i386 arch avx 1
FAIL: i386 arch-avx-1-5
FAIL: i386 reloc
FAIL: i386 white
FAIL: i386 gotpc
FAIL: i386 dynamic tls
FAIL: i386 pic tls
FAIL: i386 non-pic tls
FAIL: i386 relocs
FAIL: i386 reloc32
FAIL: x86_64
FAIL: x86-64 opcode
FAIL: x86-64 pcrel
FAIL: x86-64 amdfam10
FAIL: x86-64 immed
FAIL: x86-64 merom
FAIL: x86-64 SSE4.1
FAIL: x86-64 SSE4.1 (Intel disassembly)
FAIL: Run with libdwarf1.so first
FAIL: x86-64 SSE4.2
FAIL: x86-64 SSE4.2 (Intel disassembly)
FAIL: Run with libdwarf1.so last
FAIL: x86-64 SIMD
FAIL: x86-64 SIMD (Intel mode)
FAIL: x86-64 SIMD (with suffixes)
FAIL: x86-64 reg
FAIL: x86-64 reg (Intel mode)
FAIL: 64bit illegal opcodes
FAIL: 64bit illegal opcodes (Intel mode)
FAIL: x86-64 REX.W optimization
FAIL: ld-elf/eh4
FAIL: x86-64 arch 1
FAIL: x86-64 arch 2
FAIL: x86-64 AES
FAIL: x86-64 AES (Intel mode)
FAIL: x86-64 PCLMUL
FAIL: x86-64 PCLMUL (Intel mode)
FAIL: x86-64 AVX
FAIL: x86-64 AVX (Intel mode)
FAIL: x86-64 SSE with AVX encoding
FAIL: x86-64 SSE without AVX equivalent
FAIL: x86-64 relocs
FAIL: i386 reloc64
FAIL: preinit array
FAIL: static preinit array
FAIL: init array
FAIL: static init array
FAIL: fini array
FAIL: static fini array
FAIL: Build libcomm1.o
FAIL: Run normal with libfoo.so
FAIL: Run protected with libfoo.so
FAIL: Run hidden with libfoo.so
FAIL: Run normal with versioned libfoo.so
FAIL: Run warn with versioned libfoo.so
FAIL: Run protected with versioned libfoo.so
FAIL: Run hidden with versioned libfoo.so
FAIL: Run normal libbar.so with libfoo.so
FAIL: Run protected libbar.so with libfoo.so
FAIL: Run hidden libbar.so with libfoo.so
FAIL: Run normal libbar.so with versioned libfoo.so
FAIL: Run protected libbar.so with versioned libfoo.so
FAIL: Run hidden libbar.so with versioned libfoo.so
FAIL: Run dl1a with --dynamic-list=dl1.list and dlopen on libdl1.so
FAIL: Run dl1b with --dynamic-list-data and dlopen on libdl1.so
FAIL: Run dl6a1 with --dynamic-list-data and dlopen on libdl6a.so
FAIL: Run dl6a2 with -Bsymbolic-functions and dlopen on libdl6a.so
FAIL: Run dl6a3 with -Bsymbolic and dlopen on libdl6a.so
FAIL: Run dl6a4 with -Bsymbolic --dynamic-list-data and dlopen on libdl6a.so
FAIL: Run dl6a5 with -Bsymbolic-functions --dynamic-list-cpp-new and dlopen on libdl6a.so
FAIL: Run dl6a6 with --dynamic-list-cpp-new -Bsymbolic-functions and dlopen on libdl6a.so
FAIL: Run dl6a7 with --dynamic-list-data -Bsymbolic and dlopen on libdl6a.so
FAIL: Run dl6b1 with --dynamic-list-data and dlopen on libdl6b.so
FAIL: Run dl6b2 with dlopen on libdl6b.so
FAIL: Run dl6c1 with --dynamic-list-data and dlopen on libdl6c.so
FAIL: Run dl6d1 with --dynamic-list-data and dlopen on libdl6d.so
FAIL: Run with libdata1.so
FAIL: Run with libfunc1.so comm1.o
FAIL: Run with comm1.o libfunc1.so
FAIL: Run with libdl3a.so
FAIL: Run with libdl3b.so
FAIL: Run with libdl3c.so
FAIL: Run with libwrap1a.so and libwrap1b.so
FAIL: Run with libwrap1b.so and libwrap1a.so
FAIL: visibility (hidden)
FAIL: visibility (hidden_normal) (PIC main)
FAIL: visibility (hidden_undef) (PIC main)
FAIL: visibility (protected)
FAIL: visibility (protected) (PIC main)
FAIL: visibility (protected_undef_def)
FAIL: visibility (protected_undef_def) (PIC main)
FAIL: visibility (normal)
FAIL: visibility (normal) (PIC main)
FAIL: TLS -fpic -shared transitions
FAIL: TLS descriptor -fpic -shared transitions
FAIL: TLS -fpic and -fno-pic exec transitions
FAIL: TLS descriptor -fpic and -fno-pic exec transitions
FAIL: TLS -fno-pic -shared
FAIL: TLS with global dynamic and descriptors
FAIL: Absolute non-overflowing relocs
FAIL: PCREL8 overflow
FAIL: PCREL16 overflow
FAIL: ld-ifunc/ifunc-2-i386
FAIL: ld-ifunc/ifunc-2-local-i386
FAIL: weak undefined
FAIL: weak undefined data
FAIL: shared
FAIL: shared -Bsymbolic
FAIL: shared (PIC main)
FAIL: TLS -fpic and -fno-pic exec transitions
FAIL: TLS descriptor -fpic and -fno-pic exec transitions
FAIL: Absolute non-overflowing relocs
FAIL: PCREL8 overflow
FAIL: PCREL16 overflow
Comment 1 Martin Jambor 2009-06-19 18:09:59 UTC
I will look into this next week.  However, I have never compiled binutils before, so unless it is obvious, please describe how to reproduce the problem.
Comment 2 H.J. Lu 2009-06-19 18:24:14 UTC
(In reply to comment #1)
> I will look into this next week.  However, I have never compiled binutils
> before, so unless it is obvious, please describe how to reproduce the problem.
> 

Just download the current Linux binutils:

http://www.kernel.org/pub/linux/devel/binutils/binutils-2.19.51.0.10.tar.bz2

on Linux/x86-64 and do

1. Untar
2. mkdir build
3. cd build
4. ....../configure
5. make
6. make check

There should be no failures in testsuite.
Comment 3 Alan Modra 2009-06-19 23:38:45 UTC
With 148536 and current mainline cvs binutils I see no failures in the gas testsuite.  I do see a bunch of failures in the ld testsuite, which are all because /usr/bin/ld is being run despite a -B option being passed to gcc that should cause the newly built ld to be used.
Comment 4 H.J. Lu 2009-06-20 01:11:00 UTC
(In reply to comment #3)
> With 148536 and current mainline cvs binutils I see no failures in the gas
> testsuite.  I do see a bunch of failures in the ld testsuite, which are all
> because /usr/bin/ld is being run despite a -B option being passed to gcc that
> should cause the newly built ld to be used.
> 

With revision 148536, I got

cc1: warnings being treated as errors
/export/gnu/import/svn/binutils/src/bfd/elflink.c: In function ‘elf_link_add_object_symbols’:
/export/gnu/import/svn/binutils/src/bfd/elflink.c:3552:6: error: jump skips variable initialization
/export/gnu/import/svn/binutils/src/bfd/elflink.c:3637:7: note: label ‘error_free_dyn’ defined here
/export/gnu/import/svn/binutils/src/bfd/elflink.c:3626:18: note: ‘tagv’ declared here

It won't even compile.
Comment 5 Alan Modra 2009-06-20 03:26:03 UTC
Oops, you're correct.  I wan't using the compiler I thought I was.  make CC=... wasn't passing $CC down to the bfd dir for some reason.
Comment 6 H.J. Lu 2009-06-20 04:11:26 UTC
Revision 148512 failed to build binutils. You may need to remove -Werror
from CFLAGS in Makefile by hand when building binutils.  See PR 40500.
Comment 7 H.J. Lu 2009-06-20 13:21:32 UTC
Created attachment 18032 [details]
A patch to avoid warning from -Wall

You can apply this patch to binutils to avoid
warning from -Wall in gcc 4.5.0.
Comment 8 Dmitry Gorbachev 2009-06-22 10:05:52 UTC
This is probably the same bug: binutils 2.19.51.20090616 (build, host: i686-pc-linux-gnu, target: i686-pc-mingw32), compiled with GCC 4.5.0 20090618.

GAS aborts when tries to assemble this instruction:

  imull   $-1431655765, %eax, %eax

Internal error, aborting at ../../binutils-2.19.51/gas/config/tc-i386.c line 4917 in build_modrm_byte


To avoid errors when compiling binutils, simply pass --disable-werror to configure script.
Comment 9 Martin Jambor 2009-06-22 18:57:00 UTC
Right, now I can reproduce the problem and it indeed is introduced by the new SRA commit.  None of the fixes I have done so far deals with this one either. I am investigating this further (but don't hold your breath, it is going to take me a while).
Comment 10 Martin Jambor 2009-06-23 13:21:37 UTC
The miscompiled file seems to be gas/tc-i386.o.  Early SRA is enough to trigger the problem.  Digging deeper...
Comment 11 H.J. Lu 2009-06-23 13:40:12 UTC
(In reply to comment #10)
> The miscompiled file seems to be gas/tc-i386.o.  Early SRA is enough to trigger
> the problem.  Digging deeper...
> 

tc-i386.c uses union with bit fields. See opcodes/i386-opc.h
for details.
Comment 12 Martin Jambor 2009-06-23 16:45:40 UTC
Reduced testcase:

extern void abort (void);

typedef union i386_operand_type
{
  struct
    {
      unsigned int reg8:1;
      unsigned int reg16:1;
      unsigned int reg32:1;
      unsigned int reg64:1;
      unsigned int floatreg:1;
      unsigned int regmmx:1;
      unsigned int regxmm:1;
      unsigned int regymm:1;
      unsigned int control:1;
      unsigned int debug:1;
      unsigned int test:1;
      unsigned int sreg2:1;
      unsigned int sreg3:1;
      unsigned int imm1:1;
      unsigned int imm8:1;
      unsigned int imm8s:1;
      unsigned int imm16:1;
      unsigned int imm32:1;
      unsigned int imm32s:1;
      unsigned int imm64:1;
      unsigned int disp8:1;
      unsigned int disp16:1;
      unsigned int disp32:1;
      unsigned int disp32s:1;
      unsigned int disp64:1;
      unsigned int acc:1;
      unsigned int floatacc:1;
      unsigned int baseindex:1;
      unsigned int inoutportreg:1;
      unsigned int shiftcount:1;
      unsigned int jumpabsolute:1;
      unsigned int esseg:1;
      unsigned int regmem:1;
      unsigned int mem:1;
      unsigned int byte:1;
      unsigned int word:1;
      unsigned int dword:1;
      unsigned int fword:1;
      unsigned int qword:1;
      unsigned int tbyte:1;
      unsigned int xmmword:1;
      unsigned int ymmword:1;
      unsigned int unspecified:1;
      unsigned int anysize:1;
    } bitfield;
  unsigned int array[2];
} i386_operand_type;

unsigned int x00, x01, y00, y01;

int main (int argc, char *argv[])
{
  i386_operand_type a,b,c,d;

  a.bitfield.reg16 = 1;
  a.bitfield.imm16 = 0;
  a.array[1] = 22;

  b = a;
  x00 = b.array[0];
  x01 = b.array[1];

  c = b;
  y00 = c.array[0];
  y01 = c.array[1];

  d = c;
  if (d.bitfield.reg16 != 1)
    abort();
  if (d.bitfield.imm16 != 0)
    abort();
  if (d.array[1] != 22)
    abort();

  return 0;
}
Comment 13 Martin Jambor 2009-06-24 16:38:28 UTC
Fix submitted to the mailing list, pending maintainer approval: http://gcc.gnu.org/ml/gcc-patches/2009-06/msg01918.html
Comment 14 Martin Jambor 2009-06-25 10:38:26 UTC
Subject: Bug 40493

Author: jamborm
Date: Thu Jun 25 10:38:13 2009
New Revision: 148941

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=148941
Log:
2009-06-25  Martin Jambor  <mjambor@suse.cz>

	PR tree-optimization/40493
	* tree-sra.c (sra_modify_expr): Correct BIT_FIELD_REF argument numbers.
	(enum unscalarized_data_handling): New type.
	(handle_unscalarized_data_in_subtree): Return what has been done.
	(load_assign_lhs_subreplacements): Handle left flushes differently.
	(sra_modify_assign): Use unscalarized_data_handling, simplified
	condition determining whether to remove the statement.

	* testsuite/gcc.c-torture/execute/pr40493.c: New test.


Added:
    trunk/gcc/testsuite/gcc.c-torture/execute/pr40493.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/tree-sra.c

Comment 15 Martin Jambor 2009-06-25 14:21:08 UTC
I have checked out trunk 148941, compiled binutils with it (configured
with --disable-werror), ran the testsuite and there were no failures.
Thus I consider this fixed.
Comment 16 hjl@gcc.gnu.org 2009-06-30 13:56:03 UTC
Subject: Bug 40493

Author: hjl
Date: Tue Jun 30 13:55:43 2009
New Revision: 149097

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=149097
Log:
2009-06-30  H.J. Lu  <hongjiu.lu@intel.com>

	Backport from mainline:
	2009-06-30  Martin Jambor  <mjambor@suse.cz>

	PR tree-optimization/40582
	* gcc.c-torture/compile/pr40582.c: New test.

	2009-06-29  Jason Merrill  <jason@redhat.com>

	PR c++/40274
	* g++.dg/template/debug1.C: New.

	2009-06-25  Martin Jambor  <mjambor@suse.cz>

	PR tree-optimization/40493
	* gcc.c-torture/execute/pr40493.c: New test.

Added:
    branches/gcc-4_4-branch/gcc/testsuite/g++.dg/template/debug1.C
      - copied unchanged from r149095, trunk/gcc/testsuite/g++.dg/template/debug1.C
    branches/gcc-4_4-branch/gcc/testsuite/gcc.c-torture/compile/pr40582.c
      - copied unchanged from r149095, trunk/gcc/testsuite/gcc.c-torture/compile/pr40582.c
    branches/gcc-4_4-branch/gcc/testsuite/gcc.c-torture/execute/pr40493.c
      - copied unchanged from r149096, trunk/gcc/testsuite/gcc.c-torture/execute/pr40493.c
Modified:
    branches/gcc-4_4-branch/gcc/testsuite/ChangeLog