diff mbox

[C++] fix canonical type ICE

Message ID 555E5A35.9050306@acm.org
State New
Headers show

Commit Message

Nathan Sidwell May 21, 2015, 10:20 p.m. UTC
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

Comments

Jason Merrill May 22, 2015, 1:47 a.m. UTC | #1
How about adding may_alias support to the code a bit lower down that 
copies the abi_tag attribute?

Jason
diff mbox

Patch

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);
+  }
+};