Bug 12613 - [3.3] ICE on initializer with an array index
Summary: [3.3] ICE on initializer with an array index
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.3.2
: P3 normal
Target Milestone: 3.4.0
Assignee: Not yet assigned to anyone
URL:
Keywords:
: 13151 (view as bug list)
Depends on:
Blocks:
 
Reported: 2003-10-14 11:49 UTC by ban
Modified: 2004-01-03 13:49 UTC (History)
2 users (show)

See Also:
Host: i486-pc-linux-gnu
Target: i486-pc-linux-gnu
Build: i486-pc-linux-gnu
Known to work:
Known to fail:
Last reconfirmed: 2003-10-14 16:33:31


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description ban 2003-10-14 11:49:40 UTC
  A declaration of an array with an array index causes an ICE on 3.3/3.4.

  When C++ parser calls build_tree_list() (or tree_cons()) with
PURPOSE parameter, this function makes a TREE node which TREE_PURPOSE is
non-NULL. Then reshape_init()'s array initializer processing routine
passes its PURPOSE to size_binop(), which causes type mismatch and an ICE.

Environment:
(a) Debian GNU/Linux testing (GCC version 3.3.2 20030908 (Debian prerelease))
  and
(b) FreeBSD 5.1-CURRENT (GCC version 3.3.1)
  and
(c) FreeBSD 4.8 (GCC 3.4 cvs at 2003/10/07 (JST))


* More information about (a):

Packages: (result from `dpkg -l g++ g++-3.3')
ii  g++            3.3.1-2        The GNU C++ compiler.
ii  g++-3.3        3.3.2-0pre4    The GNU C++ compiler

Architecture: i686
	
host: i486-pc-linux-gnu
build: i486-pc-linux-gnu
target: i486-pc-linux-gnu
Configured with: ../src/configure -v --enable-languages=c,c++,java,f77,pascal,objc,ada,treelang --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-gxx-include-dir=/usr/include/c++/3.3 --enable-shared --with-system-zlib --enable-nls --without-included-gettext --enable-__cxa_atexit --enable-clocale=gnu --enable-debug --enable-java-gc=boehm --enable-java-awt=xlib --enable-objc-gc i486-linux
Thread model: posix
gcc version 3.3.2 20030908 (Debian prerelease)


* More information about (b):

% uname -a
FreeBSD sto.ipl.t.u-tokyo.ac.jp 5.1-CURRENT FreeBSD 5.1-CURRENT #3: Wed Oct  1 19:30:06 JST 2003     root@sto.ipl.t.u-tokyo.ac.jp:/work/src/sys/i386/compile/STO  i386

% gcc -v
Using built-in specs.
Configured with: FreeBSD/i386 system compiler
Thread model: posix
gcc version 3.3.1 [FreeBSD]


* More information about (c):

% gcc -v
Using built-in specs.
Configured with: ./configure --enable-languages=c++,c
Thread model: posix
gcc version 3.4 20031006 (experimental)

How-To-Repeat:
  To compile these files:

---- ice1.ii
int a[] = { [1] 1 };
---- ice2.ii
enum { FOO = 1, BAR = 2 };
int a[] = { FOO: 1, BAR: 2 };
---- ice3.ii
int a[] = { FOO: 1, BAR: 2 };
---- end

  ice1.ii is GCC's old-style C-extention code, and ice2.ii and ice3.ii
are both invalid code.

  LOG:

% g++ ice1.ii
ice1.ii:1: internal compiler error: in size_binop, at fold-const.c:1459
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.
% g++ ice2.ii
ice2.ii:2: 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.
% g++ ice3.ii
ice3.ii:1: 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.
Comment 1 ban 2003-10-14 11:49:40 UTC
Fix:
  This patch avoids the ICE:
	
--- gcc/cp/decl.c.old	2003-09-02 15:03:24.000000000 +0900
+++ gcc/cp/decl.c	2003-10-11 03:52:11.000000000 +0900
@@ -8364,7 +8364,10 @@
 	      TREE_CHAIN (element_init) = CONSTRUCTOR_ELTS (new_init);
 	      CONSTRUCTOR_ELTS (new_init) = element_init;
 	      if (TREE_PURPOSE (element_init))
-		index = TREE_PURPOSE (element_init);
+		{
+		  /* index = TREE_PURPOSE (element_init); */
+		  sorry ("initializer with an array index");
+		}
 	    }
 	}
       else

  More constructive solution would be to port C's code (and parser)
to C++. It handles a C-extention of designated initializers
much better.
Comment 2 Andrew Pinski 2003-10-14 16:33:30 UTC
The first testcase does not ICE on the mainline:
tin:~/src/gnu/gcctest>gcc pr12613.cc
pr12613.cc:1: error: expected primary-expression
pr12613.cc:1: error: expected `}'
pr12613.cc:1: error: expected `,' or `;'
pr12613.cc:1: error: expected declaration
The second and third one does ICE but the 2.95.3 produced a sorry for all three (so I do not know 
if this counts as a regression):
tin:~/src/gnu/gcctest>~/ia32_linux_gcc2_95//bin/gcc pr12613.2.cc
pr12613.2.cc:1: sorry, not implemented: non-trivial labeled initializers
pr12613.2.cc:1: sorry, not implemented: non-trivial labeled initializers
tin:~/src/gnu/gcctest>~/ia32_linux_gcc2_95//bin/gcc pr12613.1.cc
pr12613.1.cc:2: sorry, not implemented: non-trivial labeled initializers
pr12613.1.cc:2: sorry, not implemented: non-trivial labeled initializers
tin:~/src/gnu/gcctest>~/ia32_linux_gcc2_95//bin/gcc pr12613.cc
pr12613.cc:1: sorry, not implemented: non-trivial labeled initializers

Comment 3 Andrew Pinski 2003-11-21 17:03:50 UTC
*** Bug 13151 has been marked as a duplicate of this bug. ***
Comment 4 CVS Commits 2003-12-29 02:42:20 UTC
Subject: Bug 12613

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	mmitchel@gcc.gnu.org	2003-12-29 02:42:17

Modified files:
	gcc/cp         : ChangeLog decl.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/g++.dg/opt: inline6.C 
	gcc/testsuite/g++.dg/parse: error9.C 

Log message:
	PR c++/13081
	* decl.c (duplicate_decls): Preserve inline-ness when redeclaring
	a function template.
	
	PR c++/12613
	* decl.c (reshape_init): Reject GNU colon-style designated
	initializers in arrays.
	
	PR c++/13081
	* g++.dg/opt/inline6.C: New test.
	
	PR c++/12613
	* g++.dg/parse/error9.C: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.3837&r2=1.3838
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/decl.c.diff?cvsroot=gcc&r1=1.1168&r2=1.1169
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.3315&r2=1.3316
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/opt/inline6.C.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/parse/error9.C.diff?cvsroot=gcc&r1=NONE&r2=1.1

Comment 5 Mark Mitchell 2003-12-29 02:44:35 UTC
Fixed in GCC 3.4.
Comment 6 Andrew Pinski 2004-01-03 13:49:19 UTC
Was fixed for 3.4.