Bug 12446 - [3.3/3.4 regression] ICE in emit_move_insn on complicated array reference
Summary: [3.3/3.4 regression] ICE in emit_move_insn on complicated array reference
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 3.2.2
: P2 critical
Target Milestone: 3.3.2
Assignee: Eric Botcazou
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-09-29 20:21 UTC by Keith Thompson
Modified: 2004-01-17 04:22 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2003-09-29 20:53:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Keith Thompson 2003-09-29 20:21:06 UTC
"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.
Comment 1 Wolfgang Bangerth 2003-09-29 20:52:59 UTC
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.
Comment 2 Andrew Pinski 2003-09-29 20:57:46 UTC
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).
Comment 3 Andrew Pinski 2003-09-29 21:12:22 UTC
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.
Comment 4 Keith Thompson 2003-09-30 17:43:54 UTC
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.
Comment 5 Eric Botcazou 2003-10-03 10:00:06 UTC
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.
Comment 6 Gabriel Dos Reis 2003-10-03 10:24:41 UTC
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.

Comment 7 Eric Botcazou 2003-10-03 11:19:25 UTC
Sure. I'll try to restore the GCC 3.0.x behaviour.
Comment 8 GCC Commits 2003-10-04 18:02:38 UTC
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

Comment 10 Eric Botcazou 2003-10-04 18:09:49 UTC
See http://gcc.gnu.org/ml/gcc-patches/2003-10/msg00241.html