This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[3.4 PATCH] Fix a fallout of PR14179 fix (take 2)
- From: Jakub Jelinek <jakub at redhat dot com>
- To: mark at codesourcery dot com
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Tue, 28 Dec 2004 04:46:47 -0500
- Subject: [3.4 PATCH] Fix a fallout of PR14179 fix (take 2)
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
Hi!
Based on discussion in http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18384
this is what I'd like to commit for gcc-3_4-branch
(bootstrapped/regtested on {i386,x86_64,ia64,ppc,ppc64}-redhat-linux).
For 3.4 I guess changing the zero/sign extension of sizetype is not
appropriate and IDENTIFIER_NODE is the only TREE_PURPOSE that can ever
make it into reshape_init_array (from errorneous sources like
parse/error9.C; GCC 3.4 parser doesn't parse [4] = nor [4] style array
designators). Ok to commit?
For HEAD I'll try making sizetype zero extended, for 3.3 the
designated_index usage should be guarded by host_integerp (, 1), as
reshape_init_array can see arbitrary trees at that point from invalid
sources like
int i[10] = { [5.0] = 1, [-26] = 2, ["abcd" + 1] = 3, [sqrt (12.5) + 5.4] = 4 };
and we'd ICE on all of them.
2004-12-28 Jakub Jelinek <jakub@redhat.com>
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.
--- gcc/cp/decl.c.jj 2004-10-18 15:28:56.000000000 +0200
+++ gcc/cp/decl.c 2004-12-27 21:31:13.539659468 +0100
@@ -4213,13 +4213,17 @@ reshape_init_array (tree elt_type, tree
tree *initp, tree new_init)
{
bool sized_array_p = (max_index != NULL_TREE);
- HOST_WIDE_INT max_index_cst = 0;
- HOST_WIDE_INT index;
+ unsigned HOST_WIDE_INT max_index_cst = 0;
+ unsigned HOST_WIDE_INT index;
if (sized_array_p)
- /* HWI is either 32bit or 64bit, so it must be enough to represent the
- array size. */
- max_index_cst = tree_low_cst (max_index, 1);
+ {
+ if (host_integerp (max_index, 1))
+ max_index_cst = tree_low_cst (max_index, 1);
+ /* sizetype is sign extended, not zero extended. */
+ else
+ max_index_cst = tree_low_cst (convert (size_type_node, max_index), 1);
+ }
/* Loop until there are no more initializers. */
for (index = 0;
@@ -4245,19 +4249,7 @@ reshape_init_array (tree elt_type, tree
TREE_PURPOSE (element_init) = NULL_TREE;
}
else
- {
- if (TREE_CODE (designated_index) != INTEGER_CST)
- abort ();
- if (sized_array_p
- && tree_int_cst_lt (max_index, designated_index))
- {
- error ("Designated initializer `%E' larger than array "
- "size", designated_index);
- TREE_PURPOSE (element_init) = NULL_TREE;
- }
- else
- index = tree_low_cst (designated_index, 1);
- }
+ abort ();
}
}
--- gcc/testsuite/g++.dg/init/array18.C.jj 2004-12-27 21:27:41.473535046 +0100
+++ gcc/testsuite/g++.dg/init/array18.C 2004-12-27 21:27:41.473535046 +0100
@@ -0,0 +1,4 @@
+// { dg-do compile }
+// { dg-options "" }
+double a[0] = { };
+const double b[0][1] = { };
Jakub