Bug 23337 - [4.0/4.1 Regression] ICE initializing array of vectors in C++
Summary: [4.0/4.1 Regression] ICE initializing array of vectors in C++
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.1.0
: P2 normal
Target Milestone: 4.0.2
Assignee: Not yet assigned to anyone
URL: http://gcc.gnu.org/ml/gcc-patches/200...
Keywords: ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2005-08-11 18:36 UTC by Ian Lance Taylor
Modified: 2005-08-16 22:18 UTC (History)
1 user (show)

See Also:
Host:
Target: i686-pc-linux-gnu
Build:
Known to work:
Known to fail:
Last reconfirmed: 2005-08-11 18:45:51


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ian Lance Taylor 2005-08-11 18:36:04 UTC
This C++ program:

typedef int vec __attribute__ ((vector_size (8)));
extern int bar (vec);
int
foo (int i)
{
  vec a[] = { (vec) { 0, i }, (vec) { 4, 5 } };
  return bar (a[0]) + bar (a[1]);
}

when compiled with or without optimization gives this ICE in a compiler with
checking enabled:

/home/ian/foo.cc: In function ‘int foo(int)’:
/home/ian/foo.cc:6: internal compiler error: tree check: expected field_decl,
have integer_cst in component_ref_field_offset, at expr.c:5683

The misstep which leads to that is in gimplify_init_ctor_eval which assumes that
if array_elt_type is NULL that purpose is a FIELD_DECL.  That is not true when
constructing a vector type.  However, the problem presumably has to be fixed at
a higher level, since as far as I know there is no equivalent to ARRAY_REF or
COMPONENT_REF for vector types.

The same program does not ICE in C, so I'm reporting this as a C++ bug.  Perhaps
C++ is generating incorrect GENERIC.  Or perhaps the fact that C uses
COMPOUND_LITERAL_EXPR makes it work more or less by accident in C.
Comment 1 Andrew Pinski 2005-08-11 18:45:51 UTC
Confirmed, 3.4.0 accepted the code without an ICE even with checking enabled.
Comment 2 GCC Commits 2005-08-16 22:07:56 UTC
Subject: Bug 23337

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	ian@gcc.gnu.org	2005-08-16 22:07:45

Modified files:
	gcc            : ChangeLog gimplify.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/g++.dg/ext: vector2.C 

Log message:
	./
	PR c++/23337
	* gimplify.c (gimplify_init_ctor_eval): If we see an element of
	vector type, don't try to construct it element by element.  Add an
	assertion that we use a FIELD_DECL when building a COMPONENT_REF.
	testsuite/
	PR c++/23337
	* g++.dg/ext/vector2.C: New.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.9748&r2=2.9749
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/gimplify.c.diff?cvsroot=gcc&r1=2.145&r2=2.146
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.5930&r2=1.5931
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/ext/vector2.C.diff?cvsroot=gcc&r1=NONE&r2=1.1

Comment 3 GCC Commits 2005-08-16 22:17:25 UTC
Subject: Bug 23337

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-4_0-branch
Changes by:	ian@gcc.gnu.org	2005-08-16 22:17:10

Modified files:
	gcc            : ChangeLog gimplify.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/g++.dg/ext: vector2.C 

Log message:
	./
	PR c++/23337
	* gimplify.c (gimplify_init_ctor_eval): If we see an element of
	vector type, don't try to construct it element by element.  Add an
	assertion that we use a FIELD_DECL when building a COMPONENT_REF.
	testsuite/
	PR c++/23337
	* g++.dg/ext/vector2.C: New.

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.373&r2=2.7592.2.374
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/gimplify.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=2.113.2.10&r2=2.113.2.11
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.338&r2=1.5084.2.339
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/ext/vector2.C.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=NONE&r2=1.1.2.1

Comment 4 Ian Lance Taylor 2005-08-16 22:18:20 UTC
Now fixed on mainline and 4.0 branch.