The OpenBSD file zic.c causes g++ 4.0.1 to segfault, though plain gcc 4.0.1 does not. The plainest way to reproduce this is to get the OpenBSD version from <http://www.openbsd.org/cgi-bin/cvsweb/~checkout~/src/lib/libc/time/zic.c?rev=1.24&content- type=text/plain>, but I'll attach a Delta-reduced version of our modified copy. g++ 3.3.4 rejects it without crashing, but with "confused by earlier errors, bailing out," so this is presumably invalid code, though it seems to be a popular file. (Perhaps I should add OpenBSD to section I of my article :-) I'm not sure if this is the same as my two other segfault bugs: Running the --enable-checking version under GDB fails to catch the segfault, so I couldn't get a stacktrace. (I'm trying to build an -- enable-checking=all version, but it's taken more than twenty-four hours so far.) Session: 74> /opt/gcc401chk/bin/g++ -v ../cpp/bugfiles/GCC_bugfiles/error/105198_zic_min.c Using built-in specs. Target: i686-pc-linux-gnu Configured with: ../configure --enable-checking --prefix=/opt/gcc401chk --enable-languages=c,c+ + Thread model: posix gcc version 4.0.1 /opt/gcc401chk/libexec/gcc/i686-pc-linux-gnu/4.0.1/cc1plus -quiet -v -D_GNU_SOURCE ../cpp/ bugfiles/GCC_bugfiles/error/105198_zic_min.c -quiet -dumpbase 105198_zic_min.c - mtune=pentiumpro -auxbase 105198_zic_min -version -o /tmp/ccGy60bj.s ignoring nonexistent directory "/opt/gcc401chk/lib/gcc/i686-pc-linux-gnu/4.0.1/../../../../i686-pc- linux-gnu/include" #include "..." search starts here: #include <...> search starts here: /opt/gcc401chk/lib/gcc/i686-pc-linux-gnu/4.0.1/../../../../include/c++/4.0.1 /opt/gcc401chk/lib/gcc/i686-pc-linux-gnu/4.0.1/../../../../include/c++/4.0.1/i686-pc-linux-gnu /opt/gcc401chk/lib/gcc/i686-pc-linux-gnu/4.0.1/../../../../include/c++/4.0.1/backward /usr/local/include /opt/gcc401chk/include /opt/gcc401chk/lib/gcc/i686-pc-linux-gnu/4.0.1/include /usr/include End of search list. GNU C++ version 4.0.1 (i686-pc-linux-gnu) compiled by GNU C version 3.3.4 (pre 3.3.5 20040809). GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096 ../cpp/bugfiles/GCC_bugfiles/error/105198_zic_min.c:1: error: expected unqualified-id before ‘{’ token ../cpp/bugfiles/GCC_bugfiles/error/105198_zic_min.c:31: error: expected unqualified-id before ‘{’ token ../cpp/bugfiles/GCC_bugfiles/error/105198_zic_min.c:36: error: expected unqualified-id before ‘{’ token ../cpp/bugfiles/GCC_bugfiles/error/105198_zic_min.c:37: internal compiler error: Segmentation fault Please submit a full bug report, with preprocessed source if appropriate. See <URL:http://gcc.gnu.org/bugs.html> for instructions. Delta-reduced file: { if (sscanf(cp, scheck(cp, "%d"), &year) != 1) { } while (j != year) { if (year > j) { } } while (j != month) { } { if (strcmp(cp, "") == 0) { /* infile() turns "-" into "" */ } } for (i = 0; i < zonecount; ++i) { if (zp->z_nrules == 0) { if (usestart) { if (useuntil) { if (k < 0 || jtime < ktime) { } } if (usestart) { if (ktime < starttime) { } } } } if (usestart) { } } } { (timecnt == 1 && attypes[0].at < min_time)) { } } int a; { } register const char * bp; PalmSource bug 105198.
Created attachment 9384 [details] Delta-reduced version of zic.c
Error message from an --enable-checking=all build: /Projects/PlatformTools/compilerChain/tests/cpp/bugfiles/GCC_bugfiles/error /105198_zic_min.c:37: internal compiler error: RTL check: expected elt 0 type 'e' or 'u', have 'i' (rtx reg) in assemble_variable, at varasm.c:1588
Reduced testcase: int a; register const char * bp; ---- end ---- At least for 4.0.0 and above. I think there might be a couple different bugs here but I don't know for sure.
(In reply to comment #3) > I think there might be a couple different bugs here but I don't know for sure. And I think I know who caused it. Me as bp is no longer a real variable but one declared as a register. I will take a look at this soon.
This is a middle-end problem too and actually causes it be accepted in C also.
Testcase for all targets I can find: /* { dg-options "" } */ /* { dg-do compile } */ register int r0; /* { dg-error "register name not specified" } */ register int bp; /* { dg-error "register name not specified" } */ register int sp; /* { dg-error "register name not specified" } */ register int r30; /* { dg-error "register name not specified" } */ register int toc; /* { dg-error "register name not specified" } */ register int d0; /* { dg-error "register name not specified" } */ register int a0; /* { dg-error "register name not specified" } */
This was introduced by: 2004-08-04 Geoffrey Keating <geoffk@apple.com> PR 14516 * c-common.c (c_expand_decl): Don't special-case static VAR_DECLs. * c-common.h (make_rtl_for_local_static): Delete. * c-decl.c (shadow_tag_warned): Clean up comment. (finish_decl): Clean up spacing. Use set_user_assembler_name when appropriate. Don't pass asmspec to rest_of_decl_compilation. * c-semantics.c (make_rtl_for_local_static): Delete. * expr.c (init_block_move_fn): Use set_user_assembler_name. (init_block_clear_fn): Likewise. * passes.c (rest_of_decl_compilation): Remove asmspec parameter, expect it to be in DECL_ASSEMBLER_NAME. Update callers in many files. * toplev.h (rest_of_decl_compilation): Remove asmspec parameter. * tree.h (make_decl_rtl): Remove second parameter. (set_user_assembler_name): New. * varasm.c (set_user_assembler_name): New. (make_decl_rtl): Remove second parameter. Update callers in many files. So it is little harder to fix than I had previous thought as there is no way to know if user set the decl name or if it was just the name of the decl. The front-ends have to be fixed to call set_user_assembler_name all the time and then make_decl_rtl needs to be updated for that but I don't have the time to test that patch.
Subject: Re: [4.0/4.1 Regression] OpenBSD's zic.c causes g++ but not gcc to segfault On 09/09/2005, at 9:56 PM, pinskia at gcc dot gnu dot org wrote: > So it is little harder to fix than I had previous thought as there > is no way to know if user set the decl > name or if it was just the name of the decl. The front-ends have > to be fixed to call > set_user_assembler_name all the time and then make_decl_rtl needs > to be updated for that but I don't > have the time to test that patch. You should be able to tell if the user set the name because it will start with a '*'.
Subject: Re: [4.0/4.1 Regression] OpenBSD's zic.c causes g++ but not gcc to segfault On Sep 10, 2005, at 4:34 PM, geoffk at geoffk dot org wrote: > You should be able to tell if the user set the name because it will > start with a '*'. Except currently, we do: else if (C_DECL_REGISTER (decl)) change_decl_assembler_name (decl, get_identifier (asmspec)); else set_user_assembler_name (decl, asmspec); -- Pinski
I Have a fix which I will posting in the morning.
radr://3934846
Fixed on the mainline at least. Will be applying to the branch later this week.
Subject: Bug 23125 CVSROOT: /cvs/gcc Module name: gcc Changes by: pinskia@gcc.gnu.org 2005-10-04 13:39:17 Modified files: gcc : ChangeLog c-decl.c varasm.c gcc/cp : ChangeLog decl.c gcc/testsuite : ChangeLog Added files: gcc/testsuite/gcc.dg: register-var-3.c Log message: 2005-10-04 Andrew Pinski <pinskia@physics.uc.edu> PR middle-end/23125 * decl.c (make_rtl_for_nonlocal_decl): Use set_user_assembler_name instead of change_decl_assembler_name. 2005-10-04 Andrew Pinski <pinskia@physics.uc.edu> PR middle-end/23125 * c-decl.c (finish_decl): Use set_user_assembler_name even for register variables. * varasm.c (make_decl_rtl): If a register variable does not have a set user assmbler name, error out. Decode the asmspec is now name+1 bypassing '*'. 2005-10-04 Andrew Pinski <pinskia@physics.uc.edu> PR middle-end/23125 * gcc.dg/register-var-3.c: New test. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.10074&r2=2.10075 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/c-decl.c.diff?cvsroot=gcc&r1=1.685&r2=1.686 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/varasm.c.diff?cvsroot=gcc&r1=1.529&r2=1.530 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.4910&r2=1.4911 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/decl.c.diff?cvsroot=gcc&r1=1.1429&r2=1.1430 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.6131&r2=1.6132 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/register-var-3.c.diff?cvsroot=gcc&r1=NONE&r2=1.1
Fixed on both the mainline and 4.0 branches.
Subject: Bug 23125 CVSROOT: /cvs/gcc Module name: gcc Branch: gcc-4_0-branch Changes by: pinskia@gcc.gnu.org 2005-10-04 20:05:15 Modified files: gcc : ChangeLog c-decl.c varasm.c gcc/cp : ChangeLog decl.c gcc/testsuite : ChangeLog Added files: gcc/testsuite/gcc.dg: register-var-3.c Log message: 2005-10-04 Andrew Pinski <pinskia@physics.uc.edu> PR middle-end/23125 * c-decl.c (finish_decl): Use set_user_assembler_name even for register variables. * varasm.c (make_decl_rtl): If a register variable does not have a set user assmbler name, error out. Decode the asmspec is now name+1 bypassing '*'. 2005-10-04 Andrew Pinski <pinskia@physics.uc.edu> PR middle-end/23125 * decl.c (make_rtl_for_nonlocal_decl): Use set_user_assembler_name instead of change_decl_assembler_name. 2005-10-04 Andrew Pinski <pinskia@physics.uc.edu> PR middle-end/23125 * gcc.dg/register-var-3.c: New test. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=2.7592.2.446&r2=2.7592.2.447 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/c-decl.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.630.6.21&r2=1.630.6.22 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/varasm.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.477.6.13&r2=1.477.6.14 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.4648.2.114&r2=1.4648.2.115 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/decl.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.1371.2.22&r2=1.1371.2.23 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.5084.2.425&r2=1.5084.2.426 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/register-var-3.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=NONE&r2=1.1.2.1