This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[C++ PATCH] Canonical type fixes for arrays (PRs 33112, 33185?)
- From: "Doug Gregor" <doug dot gregor at gmail dot com>
- To: "GCC Patches" <gcc-patches at gcc dot gnu dot org>
- Date: Mon, 10 Sep 2007 16:37:00 -0400
- Subject: [C++ PATCH] Canonical type fixes for arrays (PRs 33112, 33185?)
This patch corrects the construction of the canonical type for a C++
array type with cv-qualifiers. It may fix PRs 33185 (a P1) and 33112
(a P3), but I can't know for sure. What I do know is that:
(1) The previous handling of canonical types here was wrong.
(2) Most of the problems with that incorrect code will show up when
the array type involves dependent types, which both PRs do.
(3) I can't reproduce either PR, so this is a bit of a shot-in-the-dark patch.
Tested i686-pc-linux-gnu; no regressions.
I'd like to hear back from the submitters of PRs 33112 and 33185 to
determine whether this fixed their problem or not before committing.
Assuming it fixes at least one of the PRs, okay to commit?
- Doug
2007-09-10 Douglas Gregor <doug.gregor@gmail.com>
* tree.c (build_cplus_array_type): Always set a new
TYPE_CANONICAL.
(cp_build_qualified_type_real): Use build_cplus_array_type instead
of build_array_type to build the canonical type, build canonical
types without names, and handle the attribute variant of the
canonical type appropriately.
Index: tree.c
===================================================================
--- tree.c (revision 128346)
+++ tree.c (working copy)
@@ -576,6 +576,8 @@ build_cplus_array_type_1 (tree elt_type,
index_type?
TYPE_CANONICAL (index_type)
: index_type));
+ else
+ TYPE_CANONICAL (t) = t;
/* Store it in the hash table. */
*e = t;
@@ -755,17 +757,25 @@ cp_build_qualified_type_real (tree type,
*e = t;
}
- if (TYPE_STRUCTURAL_EQUALITY_P (TREE_TYPE (t))
- || (TYPE_DOMAIN (t)
- && TYPE_STRUCTURAL_EQUALITY_P (TYPE_DOMAIN (t))))
+ if (TYPE_STRUCTURAL_EQUALITY_P (element_type)
+ || (domain && TYPE_STRUCTURAL_EQUALITY_P (domain)))
SET_TYPE_STRUCTURAL_EQUALITY (t);
- else
- TYPE_CANONICAL (t)
- = TYPE_CANONICAL
- (build_array_type (TYPE_CANONICAL (TREE_TYPE (t)),
- TYPE_DOMAIN (t)?
- TYPE_CANONICAL (TYPE_DOMAIN(t))
- : TYPE_DOMAIN (t)));
+ else if (TYPE_CANONICAL (element_type) != element_type
+ || (domain && TYPE_CANONICAL (domain) != domain)
+ || TYPE_NAME (t)
+ || TYPE_DOMAIN (t))
+ {
+ tree canon
+ = build_cplus_array_type
+ (TYPE_CANONICAL (element_type),
+ domain? TYPE_CANONICAL (domain) : domain);
+
+ if (TYPE_ATTRIBUTES (t))
+ canon
+ = build_type_attribute_variant (type, TYPE_ATTRIBUTES (t));
+
+ TYPE_CANONICAL (t) = TYPE_CANONICAL (canon);
+ }
}
/* Even if we already had this variant, we update