public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Nathan Sidwell <nathan@acm.org>
To: Jason Merrill <jason@redhat.com>
Cc: GCC Patches <gcc-patches@gcc.gnu.org>
Subject: [C++ PATCH] fix canonical type ICE
Date: Fri, 22 May 2015 02:56:00 -0000	[thread overview]
Message-ID: <555E5A35.9050306@acm.org> (raw)

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

             reply	other threads:[~2015-05-21 22:20 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-22  2:56 Nathan Sidwell [this message]
2015-05-22  6:34 ` Jason Merrill
2015-05-22 18:46   ` Nathan Sidwell
2015-05-23 22:45     ` Jason Merrill

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=555E5A35.9050306@acm.org \
    --to=nathan@acm.org \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jason@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).