Bug 18384 - [3.3 Regression] ICE on zero-length array with empty initializer...
Summary: [3.3 Regression] ICE on zero-length array with empty initializer...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.4.3
: P2 critical
Target Milestone: 3.4.4
Assignee: Jakub Jelinek
URL:
Keywords: ice-on-valid-code, patch
: 18581 18922 19006 (view as bug list)
Depends on:
Blocks: 18327
  Show dependency treegraph
 
Reported: 2004-11-08 21:34 UTC by apl
Modified: 2005-05-02 11:14 UTC (History)
11 users (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
Known to work: 3.3 3.3.4 3.4.0 3.4.1 3.4.2 3.4.4 4.0.0 4.1.0
Known to fail: 3.3.5 3.3.6 3.4.3
Last reconfirmed: 2004-11-08 22:12:34


Attachments
New patch (872 bytes, patch)
2004-12-27 20:15 UTC, Jakub Jelinek
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description apl 2004-11-08 21:34:32 UTC
Compilers before 3.4.3 (including 2.95.3, gcc-3.3.x) accept

  const int table[0] = {};

With 3.4.3, we see

[apl]aluminum$ /tools/linux/gcc-3.4.3/bin/g++ -c bug.cxx
bug.cxx:1: internal compiler error: in tree_low_cst, at tree.c:3313
Please submit a full bug report,
with preprocessed source if appropriate.

This also fails on Solaris.....
Comment 1 Andrew Pinski 2004-11-08 22:12:30 UTC
: Search converges between 2004-09-21-004002-3.4 (#77) and 2004-09-22-004001-3.4 (#78).
: Search converges between 2004-09-20-161001-trunk (#551) and 2004-09-21-094824-trunk 
(#552).
: Search converges between 2004-09-20-064502-3.3 (#296) and 2004-09-27-064501-3.3 (#297).

Looks like another fall out from
2004-09-20  Giovanni Bajo  <giovannibajo@gcc.gnu.org>
        PR c++/14179
        * decl.c (reshape_init): Extract array handling into...
        (reshape_init_array): New function. Use integers instead of trees
        for indices. Handle out-of-range designated initializers.

Related to PR 18327 which is the first fall out.
Comment 2 Giovanni Bajo 2004-11-18 01:44:47 UTC
Mark, I guess this is the same problem of PR 18327. Will your fix take care of 
both, or should I look into PR 18327?
Comment 3 Mark Mitchell 2004-11-18 07:59:25 UTC
Subject: Re:  [3.3/3.4/4.0 Regression] ICE on zero-length array
 with empty initializer...

giovannibajo at libero dot it wrote:

>------- Additional Comments From giovannibajo at libero dot it  2004-11-18 01:44 -------
>Mark, I guess this is the same problem of PR 18327. Will your fix take care of 
>both, or should I look into PR 18327?
>
I haven't fixed either bug yet, so go for it!

Comment 4 Giovanni Bajo 2004-11-18 09:00:10 UTC
OK, I'll take care of this since I caused it.
Comment 5 Andrew Pinski 2004-11-20 18:33:08 UTC
*** Bug 18581 has been marked as a duplicate of this bug. ***
Comment 6 Giovanni Bajo 2004-11-21 22:52:42 UTC
It looks like the testcase in this bug (and the related bugs and duplicates) 
is invalid. But I am not sure if it used to be accepted thanks to a GCC 
extension we want to prefer. Can someone elaborate on this?

This affects the kind of fix we want to do, at least on mainline: if we catch 
the error early on, there is no need to add sanity checks in reshape_init, and 
the ICE will disappear. For the branches, of course, I'll prepare a minimum 
fix which will work around the ICE.
Comment 7 Mark Mitchell 2004-11-23 01:17:29 UTC
I think that the idea behavior here would be to match GNU C.  If we reject this
code in C, then we should certainly do so in C++ as well.  If we accept it in C,
then it would be nice to accept it in C++.
Comment 8 Andrew Pinski 2004-12-10 13:27:05 UTC
*** Bug 18922 has been marked as a duplicate of this bug. ***
Comment 9 Andrew Pinski 2004-12-15 13:36:03 UTC
*** Bug 19006 has been marked as a duplicate of this bug. ***
Comment 10 Andrew Pinski 2004-12-27 15:47:04 UTC
Jakub posted a patch here: <http://gcc.gnu.org/ml/gcc-patches/2004-12/msg01962.html>.
Comment 11 Mark Mitchell 2004-12-27 17:18:23 UTC
This patch is OK in pricinple.

However, I don't think the designated_index change (to check for sizetype) is
necessary.  And, I think that the max_index should always be sizetype (and thus
the check is unncessary).

Jakub, would you please retry with a simplified version of your patch?
Comment 12 Jakub Jelinek 2004-12-27 20:15:30 UTC
Created attachment 7831 [details]
New patch

Regarding max_index, I have removed the if (!TYPE_IS_TYPESIZE (max_index))
gcc_unreachable (); part.  I still think it is useful to first check for
host_integerp (, 1), as that's the common case and we don't need to create
any new trees in that case.
As for designated_index, this differs between 3.3 and 3.4+ it seems.
With GCC 3.3, reshape_init_array can see arbitrary trees in TREE_PURPOSE (),
checking of these happens afterwards, not before reshape_init.	So I think we
certainly want a host_integerp (, 1) there, that will ensure it is an
INTEGER_CST and not negative.  In GCC 3.4 and HEAD, it seems the new parser
doesn't parse
[4] = X nor [4] X style array designated initializers at all, so we IMHO either
can do what will be done in GCC 3.3 too, or remove the designated_index
handling
altoghether and replace with gcc_assert (!TREE_PURPOSE (element_init)).
Comment 13 Mark Mitchell 2004-12-27 20:19:24 UTC
Subject: Re:  [3.3/3.4/4.0 Regression] ICE on zero-length array
 with empty initializer...

jakub at gcc dot gnu dot org wrote:
> ------- Additional Comments From jakub at gcc dot gnu dot org  2004-12-27 20:15 -------
> Created an attachment (id=7831)
>  --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=7831&action=view)
> New patch
> 
> Regarding max_index, I have removed the if (!TYPE_IS_TYPESIZE (max_index))
> gcc_unreachable (); part.  I still think it is useful to first check for
> host_integerp (, 1), as that's the common case and we don't need to create
> any new trees in that case.

Agreed.

> As for designated_index, this differs between 3.3 and 3.4+ it seems.
> With GCC 3.3, reshape_init_array can see arbitrary trees in TREE_PURPOSE (),
> checking of these happens afterwards, not before reshape_init.	So I think we
> certainly want a host_integerp (, 1) there, that will ensure it is an
> INTEGER_CST and not negative.  In GCC 3.4 and HEAD, it seems the new parser
> doesn't parse
> [4] = X nor [4] X style array designated initializers at all, so we IMHO either
> can do what will be done in GCC 3.3 too, or remove the designated_index
> handling
> altoghether and replace with gcc_assert (!TREE_PURPOSE (element_init)).

3.3 is up to Gaby.  For 3.4/mainline, let's do as you suggest and just 
add the assertion.  We'll fix it when (if?) we add that extension back 
to G++.  (It was removed because it basically didn't work.)

Patch OK.

Thanks,

Comment 14 Giovanni Bajo 2004-12-27 21:57:36 UTC
Jakub, many thanks for cleaning this up for me!!

Just one comment: in your latest patch, the second error message is capitalized 
and shouldn't, plus it uses a double negation ("not a non-negative number") 
which could be probably simplified into "a negative number".
Comment 15 GCC Commits 2004-12-28 20:58:09 UTC
Subject: Bug 18384

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-3_4-branch
Changes by:	jakub@gcc.gnu.org	2004-12-28 20:57:56

Modified files:
	gcc/cp         : ChangeLog 
	gcc/testsuite  : ChangeLog 
	gcc/cp         : decl.c 
Added files:
	gcc/testsuite/g++.dg/init: array18.C 

Log message:
	PR c++/18384, c++/18327
	* decl.c (reshape_init_array): Use UHWI type for max_index_cst
	and index.  Convert max_index to size_type_node if it isn't
	host_integerp (, 1).
	
	* g++.dg/init/array18.C: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.3892.2.188&r2=1.3892.2.189
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.3389.2.337&r2=1.3389.2.338
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/decl.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.1174.2.28&r2=1.1174.2.29
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/init/array18.C.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=NONE&r2=1.1.2.1

Comment 16 Gabriel Dos Reis 2004-12-29 18:54:17 UTC
Subject: Re:  [3.3/3.4/4.0 Regression] ICE on zero-length array with empty initializer...

"mark at codesourcery dot com" <gcc-bugzilla@gcc.gnu.org> writes:

| > As for designated_index, this differs between 3.3 and 3.4+ it seems.
| > With GCC 3.3, reshape_init_array can see arbitrary trees in TREE_PURPOSE (),
| > checking of these happens afterwards, not before reshape_init.	So I think we
| > certainly want a host_integerp (, 1) there, that will ensure it is an
| > INTEGER_CST and not negative. 

That is OK for 3.3.x

-- Gaby
Comment 17 Giovanni Bajo 2005-02-07 10:37:02 UTC
Jakub, it looks like you applied the patch only to 3.4. Can you apply it to 
mainline and 3.3 too so that we can close this regression?
Comment 18 Steven Bosscher 2005-02-25 06:39:37 UTC
Jakub, any plans to commit your patch to mainline and 3.3? 
Comment 19 Jakub Jelinek 2005-02-25 06:49:28 UTC
The trunk version of the patch works (I have it in my local tree for ages), it
hasn't been applied because of
http://gcc.gnu.org/ml/gcc-patches/2004-12/msg01976.html
but as seen in the thread after that there were issues with changing that.

So I think it would be best to apply
http://gcc.gnu.org/ml/gcc-patches/2004-12/msg01962.html
(well, the actual patch I have is a tiny bit different) for at least 4.0 branch
and deal with the sign extension of sizetype for 4.1.

As for 3.3, I haven't had yet time to write the patch, so if there are any
volunteers to write/regtest that, it would be appreciated.
Comment 20 GCC Commits 2005-02-28 12:03:44 UTC
Subject: Bug 18384

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-4_0-rhl-branch
Changes by:	jakub@gcc.gnu.org	2005-02-28 12:03:27

Modified files:
	gcc/cp         : ChangeLog 
	gcc/testsuite  : ChangeLog 
	gcc/cp         : decl.c 
Added files:
	gcc/testsuite/g++.dg/init: array18.C 

Log message:
	PR c++/18384, c++/18327
	* decl.c (reshape_init_array): Use UHWI type for max_index_cst
	and index.  Convert max_index to size_type_node if it isn't
	host_integerp (, 1).
	
	* g++.dg/init/array18.C: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-4_0-rhl-branch&r1=1.4648.2.1&r2=1.4648.2.1.2.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-4_0-rhl-branch&r1=1.5084.2.9.2.2&r2=1.5084.2.9.2.3
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/decl.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-rhl-branch&r1=1.1371.2.1&r2=1.1371.2.1.2.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/init/array18.C.diff?cvsroot=gcc&only_with_tag=gcc-4_0-rhl-branch&r1=NONE&r2=1.1.8.1

Comment 21 GCC Commits 2005-03-10 14:18:39 UTC
Subject: Bug 18384

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-4_0-branch
Changes by:	jakub@gcc.gnu.org	2005-03-10 14:17:11

Modified files:
	gcc/cp         : ChangeLog 
	gcc/testsuite  : ChangeLog 
	gcc/cp         : decl.c 
Added files:
	gcc/testsuite/g++.dg/init: array19.C 

Log message:
	PR c++/18384, c++/18327
	* decl.c (reshape_init_array): Use UHWI type for max_index_cst
	and index.  Convert max_index to size_type_node if it isn't
	host_integerp (, 1).
	
	* g++.dg/init/array19.C: New test.

Patches:
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.8&r2=1.4648.2.9
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.31&r2=1.5084.2.32
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.2&r2=1.1371.2.3
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/init/array19.C.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=NONE&r2=1.1.2.1

Comment 22 GCC Commits 2005-03-10 14:20:36 UTC
Subject: Bug 18384

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	jakub@gcc.gnu.org	2005-03-10 14:19:51

Modified files:
	gcc/cp         : ChangeLog 
	gcc/testsuite  : ChangeLog 
	gcc/cp         : decl.c 
Added files:
	gcc/testsuite/g++.dg/init: array19.C 

Log message:
	PR c++/18384, c++/18327
	* decl.c (reshape_init_array): Use UHWI type for max_index_cst
	and index.  Convert max_index to size_type_node if it isn't
	host_integerp (, 1).
	
	* g++.dg/init/array19.C: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.4658&r2=1.4659
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.5136&r2=1.5137
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/decl.c.diff?cvsroot=gcc&r1=1.1376&r2=1.1377
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/init/array19.C.diff?cvsroot=gcc&r1=1.1&r2=1.2

Comment 23 Jakub Jelinek 2005-03-10 14:22:59 UTC
Fixed for 3.4/4.0/4.1.
Comment 24 Gabriel Dos Reis 2005-04-30 13:08:30 UTC
will not fix in 3.3.x
Comment 25 Gabriel Dos Reis 2005-04-30 13:26:16 UTC
 fixed for 3.4.x