* [C++ PATCH] fix canonical type ICE
@ 2015-05-22 2:56 Nathan Sidwell
2015-05-22 6:34 ` Jason Merrill
0 siblings, 1 reply; 4+ messages in thread
From: Nathan Sidwell @ 2015-05-22 2:56 UTC (permalink / raw)
To: Jason Merrill; +Cc: GCC Patches
[-- Attachment #1: Type: text/plain, Size: 1084 bytes --]
Jason,
this fixes 65936, where we have two identical types with mismatching
TYPE_CANONICAL. The problem comes from template decl creation vs template
instantiation.
At the point we create 'const C<int>' in the operator function we have not
applied the 'may_alias' attribute to 'const C<int>'. This means that the
following snippet in tree.c:7729 build_pointer_type_for_mode
if (lookup_attribute ("may_alias", TYPE_ATTRIBUTES (to_type)))
can_alias_all = true;
doesn't set 'can_alias_all'.
Later we complete C<int> and parse the static_cast in the operator function.
Completing C<int> will have applied the may_alias attribute. So this time
can_alias_all gets set on pointers to C<int> variants. This leads to two
different pointer types differing by TYPE_REF_CAN_ALIAS_ALL, each having
different CANONICAL_TYPEs. However as TYPE_STRUCTURAL_EQUALITY_P is false, we
have a problem. We blow up in comptypes verifying the canonical type machinery.
This patch applies the may_alias attribute to the instantiated decl.
built & tested on x86_64-linux, ok?
nathan
[-- Attachment #2: 65936.patch --]
[-- Type: text/x-patch, Size: 1372 bytes --]
2015-05-21 Nathan Sidwell <nathan@acm.org>
cp/
PR c++/65936
pt.c (lookup_template_class_1): Apply may_alias attribute here.
testsuite/
* g++.dg/template/pr65936.C: New.
Index: cp/pt.c
===================================================================
--- cp/pt.c (revision 223503)
+++ cp/pt.c (working copy)
@@ -7856,6 +7856,10 @@ lookup_template_class_1 (tree d1, tree a
= CLASSTYPE_DECLARED_CLASS (template_type);
SET_CLASSTYPE_IMPLICIT_INSTANTIATION (t);
TYPE_FOR_JAVA (t) = TYPE_FOR_JAVA (template_type);
+ if (lookup_attribute ("may_alias",
+ TYPE_ATTRIBUTES (template_type)))
+ TYPE_ATTRIBUTES (t) = tree_cons (get_identifier ("may_alias"),
+ NULL_TREE, NULL_TREE);
/* A local class. Make sure the decl gets registered properly. */
if (context == current_function_decl)
Index: testsuite/g++.dg/template/pr65936.C
===================================================================
--- testsuite/g++.dg/template/pr65936.C (revision 0)
+++ testsuite/g++.dg/template/pr65936.C (working copy)
@@ -0,0 +1,21 @@
+// checking ICE in canonical typing
+
+class A;
+
+template <typename> struct B
+{
+ typedef A type;
+};
+
+template <class T> class C
+ : public B<T>::type
+{
+} __attribute__ ((__may_alias__));
+
+class A
+{
+ operator const C<int> &()
+ {
+ return *static_cast<const C<int> *> (this);
+ }
+};
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [C++ PATCH] fix canonical type ICE
2015-05-22 2:56 [C++ PATCH] fix canonical type ICE Nathan Sidwell
@ 2015-05-22 6:34 ` Jason Merrill
2015-05-22 18:46 ` Nathan Sidwell
0 siblings, 1 reply; 4+ messages in thread
From: Jason Merrill @ 2015-05-22 6:34 UTC (permalink / raw)
To: Nathan Sidwell; +Cc: GCC Patches
How about adding may_alias support to the code a bit lower down that
copies the abi_tag attribute?
Jason
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [C++ PATCH] fix canonical type ICE
2015-05-22 6:34 ` Jason Merrill
@ 2015-05-22 18:46 ` Nathan Sidwell
2015-05-23 22:45 ` Jason Merrill
0 siblings, 1 reply; 4+ messages in thread
From: Nathan Sidwell @ 2015-05-22 18:46 UTC (permalink / raw)
To: Jason Merrill; +Cc: GCC Patches
[-- Attachment #1: Type: text/plain, Size: 370 bytes --]
On 05/21/15 21:47, Jason Merrill wrote:
> How about adding may_alias support to the code a bit lower down that copies the
> abi_tag attribute?
Good idea. This keeps the non-copy behavior when the attribute is the last on
the source attribute list, and fixes up the case for when there are both
may_alias and abi_tag.
booted and tested on x86_64-linux
ok?
nathan
[-- Attachment #2: 65936.patch --]
[-- Type: text/x-patch, Size: 1721 bytes --]
2015-05-22 Nathan Sidwell <nathan@acm.org>
PR c++/65936
* pt.c (lookup_template_class_1): Copy may_alias attribute too.
PR c++/65936
* g++.dg/template/pr65936.C: New.
Index: cp/pt.c
===================================================================
--- cp/pt.c (revision 223503)
+++ cp/pt.c (working copy)
@@ -7905,15 +7905,22 @@ lookup_template_class_1 (tree d1, tree a
if (OVERLOAD_TYPE_P (t)
&& !DECL_ALIAS_TEMPLATE_P (gen_tmpl))
{
- if (tree attributes
- = lookup_attribute ("abi_tag", TYPE_ATTRIBUTES (template_type)))
+ static const char *tags[] = {"abi_tag", "may_alias"};
+
+ for (unsigned ix = 0; ix != 2; ix++)
{
- if (!TREE_CHAIN (attributes))
+ tree attributes
+ = lookup_attribute (tags[ix], TYPE_ATTRIBUTES (template_type));
+
+ if (!attributes)
+ ;
+ else if (!TREE_CHAIN (attributes) && !TYPE_ATTRIBUTES (t))
TYPE_ATTRIBUTES (t) = attributes;
else
TYPE_ATTRIBUTES (t)
- = build_tree_list (TREE_PURPOSE (attributes),
- TREE_VALUE (attributes));
+ = tree_cons (TREE_PURPOSE (attributes),
+ TREE_VALUE (attributes),
+ TYPE_ATTRIBUTES (t));
}
}
Index: testsuite/g++.dg/template/pr65936.C
===================================================================
--- testsuite/g++.dg/template/pr65936.C (revision 0)
+++ testsuite/g++.dg/template/pr65936.C (working copy)
@@ -0,0 +1,21 @@
+// checking ICE in canonical typing
+
+class A;
+
+template <typename> struct B
+{
+ typedef A type;
+};
+
+template <class T> class C
+ : public B<T>::type
+{
+} __attribute__ ((__may_alias__));
+
+class A
+{
+ operator const C<int> &()
+ {
+ return *static_cast<const C<int> *> (this);
+ }
+};
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2015-05-23 20:25 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-22 2:56 [C++ PATCH] fix canonical type ICE Nathan Sidwell
2015-05-22 6:34 ` Jason Merrill
2015-05-22 18:46 ` Nathan Sidwell
2015-05-23 22:45 ` Jason Merrill
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).