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.....
: 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.
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?
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!
OK, I'll take care of this since I caused it.
*** Bug 18581 has been marked as a duplicate of this bug. ***
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.
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++.
*** Bug 18922 has been marked as a duplicate of this bug. ***
*** Bug 19006 has been marked as a duplicate of this bug. ***
Jakub posted a patch here: <http://gcc.gnu.org/ml/gcc-patches/2004-12/msg01962.html>.
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?
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)).
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,
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".
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
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
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?
Jakub, any plans to commit your patch to mainline and 3.3?
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.
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
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
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
Fixed for 3.4/4.0/4.1.
will not fix in 3.3.x
fixed for 3.4.x