Bug 36466 - internal compiler error: in choose_reload_regs, at reload1.c:6190
Summary: internal compiler error: in choose_reload_regs, at reload1.c:6190
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 4.3.0
: P3 normal
Target Milestone: 4.6.0
Assignee: Not yet assigned to anyone
URL:
Keywords: ice-on-invalid-code
Depends on:
Blocks:
 
Reported: 2008-06-08 14:31 UTC by Aurelien Jarno
Modified: 2013-08-05 23:04 UTC (History)
6 users (show)

See Also:
Host: arm-linux-gnueabi
Target: arm-linux-gnueabi
Build: arm-linux-gnueabi
Known to work:
Known to fail: 4.3.2
Last reconfirmed: 2010-08-16 14:34:29


Attachments
reduced testcase (241 bytes, text/x-csrc)
2008-06-08 14:31 UTC, Aurelien Jarno
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Aurelien Jarno 2008-06-08 14:31:05 UTC
gcc fails to build the attached testcase with optimization levels above -O0. The problem occurs with all versions from the gcc 4.x branch. Versions gcc 3.x do not expose the problem. Note that the ICE occurs on both old-ABI and EABI.

Using built-in specs.
Target: arm-linux-gnueabi
Configured with: ../src/configure -v --with-pkgversion='Debian 4.3.0-5' --with-bugurl=file:///usr/share/doc/gcc-4.3/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --enable-shared --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --enable-nls --with-gxx-include-dir=/usr/include/c++/4.3 --program-suffix=-4.3 --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --enable-mpfr --disable-libssp --disable-sjlj-exceptions --enable-checking=release --build=arm-linux-gnueabi --host=arm-linux-gnueabi --target=arm-linux-gnueabi
Thread model: posix
gcc version 4.3.1 20080523 (prerelease) (Debian 4.3.0-5)
Comment 1 Aurelien Jarno 2008-06-08 14:31:50 UTC
Created attachment 15731 [details]
reduced testcase
Comment 2 Laurent GUERBY 2009-01-02 11:50:36 UTC
Confirmed with gcc-4.3.2-1 Debian gnueabi:
$ gcc -c -O1 pr36466.c
pr36466.c: In function ‘ReadCfgFile’:
pr36466.c:19: internal compiler error: in choose_reload_regs, at reload1.c:6190

And on trunk rev 142984:
pr36466.c: In function 'ReadCfgFile':
pr36466.c:19: internal compiler error: in choose_reload_regs, at reload1.c:6470
Comment 3 Laurent GUERBY 2009-01-02 11:53:40 UTC
backtrace on trunk:

(gdb) bt
#0  fancy_abort (file=0x786084 "../../trunk/gcc/reload1.c", line=6470, function=0x785f8c "choose_reload_regs") at ../../trunk/gcc/diagnostic.c:712
#1  0x002ba378 in choose_reload_regs (chain=<value optimized out>) at ../../trunk/gcc/reload1.c:6470
#2  0x002baf08 in reload_as_needed (live_known=<value optimized out>) at ../../trunk/gcc/reload1.c:4240
#3  0x002bf868 in reload (first=<value optimized out>, global=<value optimized out>) at ../../trunk/gcc/reload1.c:1169
#4  0x0068815c in rest_of_handle_ira () at ../../trunk/gcc/ira.c:2018
#5  0x0026ebc8 in execute_one_pass (pass=0x91fa54) at ../../trunk/gcc/passes.c:1279
#6  0x0026ee34 in execute_pass_list (pass=0x91fa54) at ../../trunk/gcc/passes.c:1328
#7  0x0026ee4c in execute_pass_list (pass=0x91a390) at ../../trunk/gcc/passes.c:1329
#8  0x003726f4 in tree_rest_of_compilation (fndecl=0x40232780) at ../../trunk/gcc/tree-optimize.c:419
#9  0x004e92d4 in cgraph_expand_function (node=0x401b0900) at ../../trunk/gcc/cgraphunit.c:1047
#10 0x004eb35c in cgraph_optimize () at ../../trunk/gcc/cgraphunit.c:1106
#11 0x0001cabc in c_write_global_declarations () at ../../trunk/gcc/c-decl.c:8074
#12 0x0031e58c in toplev_main (argc=<value optimized out>, argv=<value optimized out>) at ../../trunk/gcc/toplev.c:981
#13 0x40095dfc in __libc_start_main () from /lib/libc.so.6
#14 0x0000aa7c in _start ()
Comment 4 SK 2009-08-04 06:52:10 UTC
I see the same problem when I try to compile transmission release 1.73. The error happens with file libtransmission/fdlimit.c. Works till -O1 but fails with -O2 or -O3. Seeing this error with gcc 4.21.

Transmission was configured with:
./configure --host=arm-none-linux-gnueabi --target=arm-none-linux-gnueabi \
                        --build=i686-pc-linux \
                        --disable-gtk --disable-nls \
                        --prefix=/usr/local \
                        CFLAGS="-I/home/user/proj/syno-packager/precomp/88f6281/arm-none-linux-gnueabi/include -I/home/user/proj/syno-packager/out/88f6281/temproot/usr/local/include -I/home/user/proj/syno-packager/out/88f6281/root/usr/local/include" LDFLAGS="-L/home/user/proj/syno-packager/precomp/88f6281/arm-none-linux-gnueabi/lib -L/home/user/proj/syno-packager/out/88f6281/temproot/usr/local/lib -L/home/user/proj/syno-packager/out/88f6281/root/usr/local/lib"

Transmission needs openssl and curl to compile. So if you want to reproduce this issue, you might have to compile them first.

Please email me if you need further data.

Thanks,
SK
Comment 5 Mikael Pettersson 2009-08-04 13:58:58 UTC
Confirmed with gcc-4.3-20090802, gcc-4.4-20090728, and gcc-4.5-20090730. Passing -mtune=xscale to gcc prevents the ICE.
Comment 6 Mikael Pettersson 2009-08-04 14:07:34 UTC
Hang on, the test case looks invalid:

> ReadCfgFile (char *cfg_file)
> {
>   void *conf_handler;
>   int i;
>   struct sockaddr_in nsaddr_list[0];
>   char *nserver_str;
>   qp_getconf_array_str (conf_handler, "Nameservers", i, &nserver_str, 0);
>   (*__res_state ()).nsaddr_list[(*__res_state ()).nscount++] = nsaddr_list[0];
> }

This has a zero-element array as a local variable, which it then fetches an element from. That's clearly invalid. Changing it as follows

-  struct sockaddr_in nsaddr_list[0];
+  struct sockaddr_in nsaddr_list[1];

makes the test case work for me, even without -mtune=xscale.
Comment 7 Ramana Radhakrishnan 2009-08-05 16:42:08 UTC
Invalid testcase as per comment #6. 

(In reply to comment #4)
> I see the same problem when I try to compile transmission release 1.73. The
> error happens with file libtransmission/fdlimit.c. Works till -O1 but fails
> with -O2 or -O3. Seeing this error with gcc 4.21.
> 

Please file a separate bug report about this as per  http://gcc.gnu.org/bugs.html if you can reproduce this for trunk or any of the current release branches.
Comment 8 Loïc Minier 2010-08-16 14:21:06 UTC
I'm not sure how the .i ends up with a zero-length array; resolv.h has:
# define MAXNS                  3       /* max # name servers we'll track */
[...]
struct __res_state {
[...]
        struct sockaddr_in
                nsaddr_list[MAXNS];     /* address of name server */

so it should be [3], but it's [0] in the .i file attached here.
Comment 9 Loïc Minier 2010-08-16 14:22:00 UTC
Also, even if it's invalid input, I guess gcc should never SEGV, but rather throw an error out?
Comment 10 Martin Michlmayr 2010-08-16 14:34:29 UTC
Reopening since GCC should not ICE, even if the code is invalid.
Comment 11 Martin Michlmayr 2010-08-16 14:35:03 UTC
Reopening.
Comment 12 Loïc Minier 2010-08-16 14:40:16 UTC
Ok, it's [0] because ziproxy uses "nsaddr" as an identifier for a local variable which conflicts with a compatibility #define in glibc resolv.h.  Renaming to "nsaddress" for instance fixes the build, so clearly bogus source code.
Comment 13 Richard Earnshaw 2013-08-05 23:04:42 UTC
gcc-4.6 seems to compile the code without generating an ICE.  However, versions of gcc older than 4.7 are no-longer being maintained.