"config.guess" says i686-pc-linux-gnu "gcc --version" says gcc (GCC) 3.2.2 20030222 (Red Hat Linux 3.2.2-5) command line: gcc -v -save-temps -c gcc-bug.c Source program ("gcc-bug.c"): ======================================== struct foo { int arr[10]; }; static struct foo func(void) { struct foo result; return result; } int main(void) { int *ptr = func().arr; return 0; } ======================================== "gcc-bug.i": ======================================== # 1 "gcc-bug.c" # 1 "<built-in>" # 1 "<command line>" # 1 "gcc-bug.c" struct foo { int arr[10]; }; static struct foo func(void) { struct foo result; return result; } int main(void) { int *ptr = func().arr; return 0; } ======================================== output: ======================================== Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/3.2.2/specs Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --disable-checking --with-system-zlib --enable-__cxa_atexit --host=i386-redhat-linux Thread model: posix gcc version 3.2.2 20030222 (Red Hat Linux 3.2.2-5) /usr/lib/gcc-lib/i386-redhat-linux/3.2.2/cpp0 -lang-c -v -D__GNUC__=3 -D__GNUC_MINOR__=2 -D__GNUC_PATCHLEVEL__=2 -D__GXX_ABI_VERSION=102 -D__ELF__ -Dunix -D__gnu_linux__ -Dlinux -D__ELF__ -D__unix__ -D__gnu_linux__ -D__linux__ -D__unix -D__linux -Asystem=posix -D__NO_INLINE__ -D__STDC_HOSTED__=1 -Acpu=i386 -Amachine=i386 -Di386 -D__i386 -D__i386__ -D__tune_i386__ gcc-bug.c gcc-bug.i GNU CPP version 3.2.2 20030222 (Red Hat Linux 3.2.2-5) (cpplib) (i386 Linux/ELF) ignoring nonexistent directory "/usr/i386-redhat-linux/include" #include "..." search starts here: #include <...> search starts here: /usr/local/include /usr/lib/gcc-lib/i386-redhat-linux/3.2.2/include /usr/include End of search list. /usr/lib/gcc-lib/i386-redhat-linux/3.2.2/cc1 -fpreprocessed gcc-bug.i -quiet -dumpbase gcc-bug.c -version -o gcc-bug.s GNU CPP version 3.2.2 20030222 (Red Hat Linux 3.2.2-5) (cpplib) (i386 Linux/ELF) GNU C version 3.2.2 20030222 (Red Hat Linux 3.2.2-5) (i386-redhat-linux) compiled by GNU C version 3.2.2 20030222 (Red Hat Linux 3.2.2-5). gcc-bug.c: In function `main': gcc-bug.c:13: Internal compiler error in emit_move_insn, at expr.c:2776 Please submit a full bug report, with preprocessed source if appropriate. See <URL:http://bugzilla.redhat.com/bugzilla/> for instructions. ======================================== I get similar results with gcc 3.2.3 on sparc-sun-solaris2.8 (expr.c:2776) and "gcc (GCC) 3.3.1 (cygming special)" on i686-pc-cygwin (expr.c:3156). I'll be glad to provide more detailed information if it would be helpful. There's some question about the legality of the line on which the error occurs; see the "doubt in USING POINTERS" thread in the comp.std.c newsgroup. It's been suggested that it's legal in C99 but no in C90. I haven't followed the discussion closely enough to have an opinion on that, but of course an internal compiler error is a bug regardless of whether the source is legal.
Confirmed with 3.2, 3.3 and mainline. This worked in 2.95, though I'm not sure whether the code is legal because you are taking the address of a temporary. We shouldn't ICE though, regardless of the circumstances. W.
In 3.0.4, this is rejected.. From Phil's regression hunter: Search converges between 2001-11-04-trunk (#44) and 2001-11- 11-trunk (#45).
Most likely caused by <http://gcc.gnu.org/ml/gcc-patches/2001-11/msg00319.html> which implements "C99 non-lvalue array handling", the problem looks like GCC no longer rejects for the non-C99 case. Note this passes just fine with -std=c99, which is right.
Further discussion on comp.std.c turned up C99 6.5.2.2p5, which says in part: If an attempt is made to modify the result of a function call or to access it after the next sequence point, the behavior is undefined. So the value of ptr cannot be used after its initialization without invoking undefined behavior. I suggest that this should result in a warning.
Interestingly, when ptr is assigned after its declaration, the compiler emits: pr12446.c: In function `main': pr12446.c:17: error: incompatible types in assignment which is only slightly better. Both GCC 2.95.3 and 3.0.4 give: pr12446.c: In function `main': pr12446.c:17: invalid use of non-lvalue array which is far better IMHO.
Subject: Re: [3.3/3.4 regression] ICE in emit_move_insn on complicated array reference "ebotcazou at gcc dot gnu dot org" <gcc-bugzilla@gcc.gnu.org> writes: | Interestingly, when ptr is assigned after its declaration, the compiler emits: | | pr12446.c: In function `main': | pr12446.c:17: error: incompatible types in assignment | | which is only slightly better. it is better and an ICE but it is incorrect, IMHO.
Sure. I'll try to restore the GCC 3.0.x behaviour.
Subject: Bug 12446 CVSROOT: /cvs/gcc Module name: gcc Changes by: ebotcazou@gcc.gnu.org 2003-10-04 18:02:32 Modified files: gcc : ChangeLog c-typeck.c gcc/testsuite : ChangeLog Added files: gcc/testsuite/gcc.dg: c90-array-lval-6.c c99-array-lval-6.c Log message: PR c/12446 * c-typeck.c (convert_for_assignment): Issue an error for array to pointer assignment after default conversion. (digest_init): Likewise. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.1278&r2=2.1279 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/c-typeck.c.diff?cvsroot=gcc&r1=1.259&r2=1.260 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.3095&r2=1.3096 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/c90-array-lval-6.c.diff?cvsroot=gcc&r1=NONE&r2=1.1 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/c99-array-lval-6.c.diff?cvsroot=gcc&r1=NONE&r2=1.1
Subject: Bug 12446 CVSROOT: /cvs/gcc Module name: gcc Branch: gcc-3_3-branch Changes by: ebotcazou@gcc.gnu.org 2003-10-04 18:07:26 Modified files: gcc : ChangeLog c-typeck.c gcc/testsuite : ChangeLog Added files: gcc/testsuite/gcc.dg: c90-array-lval-6.c c99-array-lval-6.c Log message: PR c/12446 * c-typeck.c (convert_for_assignment): Issue an error for array to pointer assignment after default conversion. (digest_init): Likewise. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.16114.2.769&r2=1.16114.2.770 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/c-typeck.c.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.213.2.8&r2=1.213.2.9 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.2261.2.295&r2=1.2261.2.296 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/c90-array-lval-6.c.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=NONE&r2=1.1.2.1 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/c99-array-lval-6.c.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=NONE&r2=1.1.2.1
See http://gcc.gnu.org/ml/gcc-patches/2003-10/msg00241.html