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>, Jakub Jelinek <jakub@redhat.com>
Cc: GCC Patches <gcc-patches@gcc.gnu.org>
Subject: [PATCH] C++/70512 Fix may_alias canonical type mismatch
Date: Tue, 05 Apr 2016 22:00:00 -0000	[thread overview]
Message-ID: <5704356B.3010507@acm.org> (raw)

[-- Attachment #1: Type: text/plain, Size: 665 bytes --]

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70512

this fixes the canonical type mismatch of 70512.  As surmised we don't correct 
the ptr-to and ref-to types created during the structure parse when 
late-applying the may_alias attribute.

This  patch  adjusts fixup_attribute_variants to walk the ptr-to and ref-to 
lists setting the TYPE_REF_CAN_ALIAS_ALL flag.  We also walk those lists for the 
main variant itself.

It wasn't clear to me whether decl_attributes (attribs.c) should mark the ptr-to 
and ref-to lists of the type having the may_alias attribute applied in place?

By construction, we'll adjust the appropriate canonical types, IIUC.

ok?

nathan

[-- Attachment #2: 70512.patch --]
[-- Type: text/x-patch, Size: 2027 bytes --]

2016-04-04  Nathan Sidwell  <nathan@acm.org>

	PR c++/70512
	* class.c (fixup_may_alias): New.
	(fixup_attribute_variants): Call it.

	* g++.dg/ext/attribute-may-alias-5.C: New.

Index: cp/class.c
===================================================================
--- cp/class.c	(revision 234715)
+++ cp/class.c	(working copy)
@@ -1978,6 +1978,21 @@ fixup_type_variants (tree t)
     }
 }
 
+/* KLASS is a class that we're applying may_alias to after the body is
+   parsed.  Fixup any POINTER_TO and REFERENCE_TO types.  The
+   canonical type(s) will be implicitly updated.  */
+
+static void
+fixup_may_alias (tree klass)
+{
+  tree t;
+
+  for (t = TYPE_POINTER_TO (klass); t; t = TYPE_NEXT_PTR_TO (t))
+    TYPE_REF_CAN_ALIAS_ALL (t) = true;
+  for (t = TYPE_REFERENCE_TO (klass); t; t = TYPE_NEXT_REF_TO (t))
+    TYPE_REF_CAN_ALIAS_ALL (t) = true;
+}
+
 /* Early variant fixups: we apply attributes at the beginning of the class
    definition, and we need to fix up any variants that have already been
    made via elaborated-type-specifier so that check_qualified_type works.  */
@@ -1993,6 +2008,10 @@ fixup_attribute_variants (tree t)
   tree attrs = TYPE_ATTRIBUTES (t);
   unsigned align = TYPE_ALIGN (t);
   bool user_align = TYPE_USER_ALIGN (t);
+  bool may_alias = lookup_attribute ("may_alias", attrs);
+
+  if (may_alias)
+    fixup_may_alias (t);
 
   for (variants = TYPE_NEXT_VARIANT (t);
        variants;
@@ -2007,6 +2026,8 @@ fixup_attribute_variants (tree t)
       else
 	TYPE_USER_ALIGN (variants) = user_align;
       TYPE_ALIGN (variants) = valign;
+      if (may_alias)
+	fixup_may_alias (variants);
     }
 }
 \f
Index: testsuite/g++.dg/ext/attribute-may-alias-5.C
===================================================================
--- testsuite/g++.dg/ext/attribute-may-alias-5.C	(nonexistent)
+++ testsuite/g++.dg/ext/attribute-may-alias-5.C	(working copy)
@@ -0,0 +1,9 @@
+// PR c++/70512
+
+struct S 
+{
+  S& operator= (int)
+  {
+    return *this;
+  }
+} __attribute__ ((__may_alias__));

             reply	other threads:[~2016-04-05 22:00 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-05 22:00 Nathan Sidwell [this message]
2016-04-05 22:14 ` 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=5704356B.3010507@acm.org \
    --to=nathan@acm.org \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jakub@redhat.com \
    --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).