GCC Bugzilla has been upgraded from version 4.4.9 to 5.0rc3. If you see any problem, please report it to bug 64968.
Bug 48343 - [4.6/4.7 Regression] ICE compiling i586 linux-2.6.38/drivers/staging/wlan-ng/p80211wep.c: in form_sum, at reload.c:5338
Summary: [4.6/4.7 Regression] ICE compiling i586 linux-2.6.38/drivers/staging/wlan-ng/...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: debug (show other bugs)
Version: 4.6.0
: P3 major
Target Milestone: 4.6.1
Assignee: Jakub Jelinek
URL:
Keywords: ice-on-valid-code
: 48356 (view as bug list)
Depends on:
Blocks:
 
Reported: 2011-03-29 21:38 UTC by Paulo César Pereira de Andrade
Modified: 2011-04-07 18:06 UTC (History)
3 users (show)

See Also:
Host:
Target: i586-mandriva-linux-gnu
Build:
Known to work: 4.5.2
Known to fail:
Last reconfirmed: 2011-03-30 08:54:12


Attachments
sample test case: "gcc -O1 -g test.c" to reproduce the problem (2.76 KB, text/x-c)
2011-03-29 21:38 UTC, Paulo César Pereira de Andrade
Details
gcc46-pr48343.patch (1.88 KB, patch)
2011-03-30 15:51 UTC, Jakub Jelinek
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Paulo César Pereira de Andrade 2011-03-29 21:38:27 UTC
Created attachment 23806 [details]
sample test case: "gcc -O1 -g test.c" to reproduce the problem

The problem happens at -O1 or larger, and only if adding -g to command line.
The problem happened after over 15k lines of kernel compile log.

$ gcc -v -O3 -g test.c
Using built-in specs.
COLLECT_GCC=/usr/bin/gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/i586-mandriva-linux-gnu/4.6.0/lto-wrapper
Target: i586-mandriva-linux-gnu
Configured with: ./configure --build=i586-mandriva-linux-gnu --prefix=/usr --exec-prefix=/usr --bindir=/usr/bin --sbindir=/usr/sbin --sysconfdir=/etc --datadir=/usr/share --includedir=/usr/include --libdir=/usr/lib --libexecdir=/usr/lib --localstatedir=/var --sharedstatedir=/usr/com --mandir=/usr/share/man --infodir=/usr/share/info --x-includes=/usr/include --x-libraries=/usr/lib --disable-libjava-multilib --with-java-home=/usr/lib/jvm/java-rpmbuild --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-java-awt=qt,gtk --enable-gtk-cairo --disable-libssp --disable-libunwind-exceptions --disable-werror --enable-__cxa_atexit --enable-bootstrap --enable-checking=release --enable-gnu-unique-object --enable-languages=c,ada,c++,fortran,go,java,lto,objc,obj-c++ --enable-linker-build-id --enable-plugin --enable-shared --enable-threads=posix --with-system-zlib --with-bugurl=https://qa.mandriva.com/ --with-tune=generic --with-arch=i686 --host=i586-mandriva-linux-gnu --target=i586-mandriva-linux-gnu
Thread model: posix
gcc version 4.6.0 (GCC) 
COLLECT_GCC_OPTIONS='-v' '-O3' '-g' '-mtune=generic' '-march=i686'
 /usr/lib/gcc/i586-mandriva-linux-gnu/4.6.0/cc1 -quiet -v test.c -quiet -dumpbase test.c -mtune=generic -march=i686 -auxbase test -g -O3 -version -o /tmp//ccxHrbNH.s
GNU C (GCC) version 4.6.0 (i586-mandriva-linux-gnu)
        compiled by GNU C version 4.6.0, GMP version 5.0.1, MPFR version 3.0.0-p3, MPC version 0.8.2
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "/usr/lib/gcc/i586-mandriva-linux-gnu/4.6.0/include-fixed"
ignoring nonexistent directory "/usr/lib/gcc/i586-mandriva-linux-gnu/4.6.0/../../../../i586-mandriva-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/lib/gcc/i586-mandriva-linux-gnu/4.6.0/include
 /usr/local/include
 /usr/include
End of search list.
GNU C (GCC) version 4.6.0 (i586-mandriva-linux-gnu)
        compiled by GNU C version 4.6.0, GMP version 5.0.1, MPFR version 3.0.0-p3, MPC version 0.8.2
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: bca5a43bb43969b075940469833a33fd
test.c: In function 'test':
test.c:147:1: internal compiler error: in form_sum, at reload.c:5338
Please submit a full bug report,
with preprocessed source if appropriate.
See <https://qa.mandriva.com/> for instructions.

  This is from an experimental gcc 4.6.0 package for Mandriva. I am already
using a x86_64 kernel in my computer, compiled with gcc 4.6.0.

  Attached is hopefully a small enough cut&paste with minimal changes, that
still reproduces the problem.
Comment 1 Richard Biener 2011-03-30 08:54:12 UTC
Confirmed.  Reduced testcase:

#define swap(a, b) \
        do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while (0)
struct dev {
      int       keylens[4];
};
void test(struct dev *dev, int keynum, unsigned char *iv)
{
  unsigned int i, j, keylen;
  unsigned char s[256], key[64];
  keylen = dev->keylens[keynum];
  key[0] = iv[0];
  for (i = 0; i < 256; i++) 
    {
      j = (j + s[i] + key[i % keylen]) & 0xff;
      swap(i, j);
    }
}

also fails on x86_64-*-* with -O3 -g -m32.
Comment 2 Richard Biener 2011-03-30 09:27:54 UTC
*** Bug 48356 has been marked as a duplicate of this bug. ***
Comment 3 Jakub Jelinek 2011-03-30 13:46:26 UTC
Slightly more reduced testcase (and without uninitialized vars):
void foo (unsigned char *, unsigned char *);

void
test (unsigned int x, int y)
{
  unsigned int i, j = 0, k;
  unsigned char s[256], t[64];
  foo (s, t);
  t[0] = y;
  for (i = 0; i < 256; i++)
    {
      j = (j + s[i] + t[i % x]) & 0xff;
      k = i; i = j; j = k;
    }
}

again, ICEs with -O3 -m32 -g, doesn't with -O3 -m32 -g -fno-var-tracking-assignments.
Comment 4 Jakub Jelinek 2011-03-30 14:11:13 UTC
Seems to be a combiner VTA bug.
try_combine decides to SUBST_MODE, because it has a single (non-debug) use and single set, changes a pseudo from SImode to QImode, which magically changes the mode also in the debug insn which also uses it and nothing afterwards fixes up the debug_insn.
Comment 5 Jakub Jelinek 2011-03-30 15:16:55 UTC
So, before combiner we have:
(insn 23 22 24 3 (parallel [
            (set (reg:SI 98)
                (plus:SI (reg:SI 97 [ prephitmp.9 ])
                    (reg/v:SI 64 [ j ])))
            (clobber (reg:CC 17 flags))
        ]) pr48343.c:12 252 {*addsi_1}
     (expr_list:REG_DEAD (reg:SI 97 [ prephitmp.9 ])
        (expr_list:REG_DEAD (reg/v:SI 64 [ j ])
            (expr_list:REG_UNUSED (reg:CC 17 flags)
                (nil)))))

(insn 24 23 25 3 (parallel [
            (set (reg:SI 99)
                (zero_extend:SI (mem/s/j:QI (plus:SI (plus:SI (reg/f:SI 20 frame)
                                (reg/v:SI 71 [ i ]))
                            (const_int -320 [0xfffffffffffffec0])) [0 s S1 A8])))
            (clobber (reg:CC 17 flags))
        ]) pr48343.c:12 123 {*zero_extendqisi2_movzbl_and}
     (expr_list:REG_UNUSED (reg:CC 17 flags)
        (nil)))

(insn 25 24 27 3 (parallel [
            (set (reg:SI 66 [ D.1999 ])
                (plus:SI (reg:SI 98)
                    (reg:SI 99)))
            (clobber (reg:CC 17 flags))
        ]) pr48343.c:12 252 {*addsi_1}
     (expr_list:REG_DEAD (reg:SI 99)
        (expr_list:REG_DEAD (reg:SI 98)
            (expr_list:REG_UNUSED (reg:CC 17 flags)
                (nil)))))

(debug_insn 27 25 28 3 (var_location:SI k (reg/v:SI 71 [ i ])) pr48343.c:13 -1
     (nil))

(debug_insn 28 27 29 3 (var_location:SI i (and:SI (reg:SI 66 [ D.1999 ])
        (const_int 255 [0xff]))) pr48343.c:13 -1
     (nil))

and SUBST_MODE is applied to pseudo 98 when i2 is insn 23 and i3 is insn 25, after a previous propagate_for_debug set of changes which were with i3 insn 30.

So, IMHO we don't want to stop at i3 for propagate_for_debug if we are retrying (goto retry in combine_instructions), instead we want to stop at the last i3 we've been processing in the current BB.

I'll try to write a patch.
Comment 6 Jakub Jelinek 2011-03-30 15:51:30 UTC
Created attachment 23821 [details]
gcc46-pr48343.patch

Untested fix.
Comment 7 Ernst Molitor 2011-03-30 17:02:26 UTC
With the patch gcc46-pr48343.patch applied to the gcc-4.6.0 sources and after a "make bootstrap; make install", I have arrived at a version of gcc-4.6.0 that both compiles the testcase kindly provided by Jakub Jelinek and the current (git commit 0ce790e7d736cedc563e1fb4e998babf5a4dbc3d) Linux kernel (Linux 2.6.39-rc1) flawlessly. Very impressive!!
Comment 8 Paulo César Pereira de Andrade 2011-03-31 18:06:05 UTC
(In reply to comment #6)
> Created attachment 23821 [details]
> gcc46-pr48343.patch
> 
> Untested fix.

  I also confirm gcc built with this patch compiles the i586
kernel, and after installing the generated kernel, and running
several lmbench tests I see no problems.

  Feel free to close the bug report if appropriate.

Thanks.
Comment 9 Jakub Jelinek 2011-04-07 17:57:29 UTC
Author: jakub
Date: Thu Apr  7 17:57:26 2011
New Revision: 172108

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=172108
Log:
	PR debug/48343
	* combine.c (combine_instructions): Add last_combined_insn,
	update it if insn is after it, pass it to all try_combine
	calls.
	(try_combine): Add last_combined_insn parameter, pass it instead of
	i3 to propagate_for_debug.

	* gcc.dg/torture/pr48343.c: New test.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/combine.c
    trunk/gcc/testsuite/ChangeLog
Comment 10 Jakub Jelinek 2011-04-07 17:58:07 UTC
Author: jakub
Date: Thu Apr  7 17:58:05 2011
New Revision: 172109

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=172109
Log:
	PR debug/48343
	* combine.c (combine_instructions): Add last_combined_insn,
	update it if insn is after it, pass it to all try_combine
	calls.
	(try_combine): Add last_combined_insn parameter, pass it instead of
	i3 to propagate_for_debug.

	* gcc.dg/torture/pr48343.c: New test.

Added:
    trunk/gcc/testsuite/gcc.dg/torture/pr48343.c
Comment 11 Jakub Jelinek 2011-04-07 18:05:11 UTC
Author: jakub
Date: Thu Apr  7 18:05:08 2011
New Revision: 172110

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=172110
Log:
	PR debug/48343
	* combine.c (combine_instructions): Add last_combined_insn,
	update it if insn is after it, pass it to all try_combine
	calls.
	(try_combine): Add last_combined_insn parameter, pass it instead of
	i3 to propagate_for_debug.

	* gcc.dg/torture/pr48343.c: New test.

Added:
    branches/gcc-4_6-branch/gcc/testsuite/gcc.dg/torture/pr48343.c
Modified:
    branches/gcc-4_6-branch/gcc/ChangeLog
    branches/gcc-4_6-branch/gcc/combine.c
    branches/gcc-4_6-branch/gcc/testsuite/ChangeLog
Comment 12 Jakub Jelinek 2011-04-07 18:06:50 UTC
Fixed.