This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[4.0 PATCH] Fix PR c++/18384
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Richard Henderson <rth at redhat dot com>, Roger Sayle <roger at eyesopen dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Wed, 9 Mar 2005 19:32:02 -0500
- Subject: [4.0 PATCH] Fix PR c++/18384
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
Hi!
This patch got already applied on gcc-3_4-branch, on HEAD (at that time)
it got stuck on attempts to make sizetype not sign extended, which in
turn touched the overflow handling area outside of front-ends.
As this is unlikely to be resolved on the gcc-4_0-branch, can I
commit this patch to 4.0 branch?
Should I commit it on HEAD for now too and when the overflow stuff gets
changed, it could be backed out?
Bootstrapped/regtested on 7 linux arches.
2005-03-10 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-12-27 13:00:56.000000000 +0100
+++ gcc/cp/decl.c 2004-12-27 21:31:53.909449149 +0100
@@ -4208,13 +4208,18 @@ 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 (fold_convert (size_type_node, max_index),
+ 1);
+ }
/* Loop until there are no more initializers. */
for (index = 0;
@@ -4231,27 +4236,16 @@ reshape_init_array (tree elt_type, tree
CONSTRUCTOR_ELTS (new_init) = element_init;
designated_index = TREE_PURPOSE (element_init);
if (designated_index)
- {
+ {
/* Handle array designated initializers (GNU extension). */
if (TREE_CODE (designated_index) == IDENTIFIER_NODE)
{
error ("name %qD used in a GNU-style designated "
- "initializer for an array", designated_index);
+ "initializer for an array", designated_index);
TREE_PURPOSE (element_init) = NULL_TREE;
}
else
- {
- gcc_assert (TREE_CODE (designated_index) == INTEGER_CST);
- if (sized_array_p
- && tree_int_cst_lt (max_index, designated_index))
- {
- error ("Designated initializer %qE larger than array "
- "size", designated_index);
- TREE_PURPOSE (element_init) = NULL_TREE;
- }
- else
- index = tree_low_cst (designated_index, 1);
- }
+ gcc_unreachable ();
}
}
--- gcc/testsuite/g++.dg/init/array18.C.jj 2004-12-27 15:24:03.000000000 +0100
+++ gcc/testsuite/g++.dg/init/array18.C 2004-12-27 15:23:27.000000000 +0100
@@ -0,0 +1,4 @@
+// { dg-do compile }
+// { dg-options "" }
+double a[0] = { };
+const double b[0][1] = { };
Jakub