From f69367ded7ba99c392b90d61e12126f70ab7e499 Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Fri, 11 Mar 2011 12:20:27 -0500 Subject: [PATCH] re PR c++/48029 (ICE in finish_member_declaration() with --param ggc-min-expand=0 --param ggc-min-heapsize=0) PR c++/48029 * stor-layout.c (layout_type): Don't set structural equality on arrays of incomplete type. * tree.c (type_hash_eq): Handle comparing them properly. * cp/pt.c (iterative_hash_template_arg): Remove special case for ARRAY_TYPE. From-SVN: r170880 --- gcc/ChangeLog | 7 +++++++ gcc/cp/ChangeLog | 6 ++++++ gcc/cp/pt.c | 7 ------- gcc/stor-layout.c | 5 ----- gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/g++.dg/template/array22.C | 14 ++++++++++++++ gcc/tree.c | 10 ++++++++-- 7 files changed, 39 insertions(+), 14 deletions(-) create mode 100644 gcc/testsuite/g++.dg/template/array22.C diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 768795017295..7380093e91bf 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2011-03-10 Jason Merrill + + PR c++/48029 + * stor-layout.c (layout_type): Don't set structural equality + on arrays of incomplete type. + * tree.c (type_hash_eq): Handle comparing them properly. + 2011-03-08 Richard Guenther Backport from mainline diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 337e94bd556c..711638225669 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2011-03-10 Jason Merrill + + PR c++/48029 + * pt.c (iterative_hash_template_arg): Remove special case for + ARRAY_TYPE. + 2011-03-09 Jason Merrill PR c++/44629 diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index b868770007b9..847712bfb039 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -1556,13 +1556,6 @@ iterative_hash_template_arg (tree arg, hashval_t val) val = iterative_hash_object (code, val); return iterative_hash_template_arg (TREE_OPERAND (arg, 2), val); - case ARRAY_TYPE: - /* layout_type sets structural equality for arrays of - incomplete type, so we can't rely on the canonical type - for hashing. */ - val = iterative_hash_template_arg (TREE_TYPE (arg), val); - return iterative_hash_template_arg (TYPE_DOMAIN (arg), val); - case LAMBDA_EXPR: /* A lambda can't appear in a template arg, but don't crash on erroneous input. */ diff --git a/gcc/stor-layout.c b/gcc/stor-layout.c index 55e3403b19f2..718161d69034 100644 --- a/gcc/stor-layout.c +++ b/gcc/stor-layout.c @@ -2029,11 +2029,6 @@ layout_type (tree type) #else TYPE_ALIGN (type) = MAX (TYPE_ALIGN (element), BITS_PER_UNIT); #endif - if (!TYPE_SIZE (element)) - /* We don't know the size of the underlying element type, so - our alignment calculations will be wrong, forcing us to - fall back on structural equality. */ - SET_TYPE_STRUCTURAL_EQUALITY (type); TYPE_USER_ALIGN (type) = TYPE_USER_ALIGN (element); SET_TYPE_MODE (type, BLKmode); if (TYPE_SIZE (type) != 0 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index feb556bae42b..a1128bc38008 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2011-03-10 Jason Merrill + + * g++.dg/template/array22.C: New. + 2011-03-11 Richard Guenther PR tree-optimization/47278 diff --git a/gcc/testsuite/g++.dg/template/array22.C b/gcc/testsuite/g++.dg/template/array22.C new file mode 100644 index 000000000000..e101587738b3 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/array22.C @@ -0,0 +1,14 @@ +// PR c++/48029 + +template struct A { }; +template struct B +{ + struct N { }; + typedef U u; +}; + +typedef B(*)[2]> btype; +A v1[2]; +btype v2; + + diff --git a/gcc/tree.c b/gcc/tree.c index 05218a05d0f9..4b1bfac42ae9 100644 --- a/gcc/tree.c +++ b/gcc/tree.c @@ -5797,12 +5797,18 @@ type_hash_eq (const void *va, const void *vb) || TREE_TYPE (a->type) != TREE_TYPE (b->type) || !attribute_list_equal (TYPE_ATTRIBUTES (a->type), TYPE_ATTRIBUTES (b->type)) - || TYPE_ALIGN (a->type) != TYPE_ALIGN (b->type) - || TYPE_MODE (a->type) != TYPE_MODE (b->type) || (TREE_CODE (a->type) != COMPLEX_TYPE && TYPE_NAME (a->type) != TYPE_NAME (b->type))) return 0; + /* Be careful about comparing arrays before and after the element type + has been completed; don't compare TYPE_ALIGN unless both types are + complete. */ + if (COMPLETE_TYPE_P (a->type) && COMPLETE_TYPE_P (b->type) + && (TYPE_ALIGN (a->type) != TYPE_ALIGN (b->type) + || TYPE_MODE (a->type) != TYPE_MODE (b->type))) + return 0; + switch (TREE_CODE (a->type)) { case VOID_TYPE: -- 2.47.2