public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Marek Polacek <polacek@redhat.com>
To: GCC Patches <gcc-patches@gcc.gnu.org>
Subject: C PATCH for comptypes handling of TYPE_REF_CAN_ALIAS_ALL
Date: Thu, 26 May 2016 15:30:00 -0000	[thread overview]
Message-ID: <20160526141651.GB3014@redhat.com> (raw)

The C++ FE has been changed, as a part of c++/50800, in such a way that it no
longer considers types differentiating only in TYPE_REF_CAN_ALIAS_ALL
incompatible.  But the C FE still rejects the following testcase, so this patch
makes the C FE follow suit.  After all, the may_alias attribute is not
considered as "affects_type_identity".  This TYPE_REF_CAN_ALIAS_ALL check was
introduced back in 2004 (r90078), but since then we've gotten rid of them, only
comptypes_internal retained it.  I suspect the TYPE_MODE check might go too,
but I don't feel like changing that right now.

This arised when discussing struct sockaddr vs. may_alias issue in glibc.

Bootstrapped/regtested on x86_64-linux, ok for trunk?

2016-05-26  Marek Polacek  <polacek@redhat.com>

	* c-typeck.c (comptypes_internal): Don't check TYPE_REF_CAN_ALIAS_ALL.

	* gcc.dg/attr-may-alias-2.c: New test.

diff --git gcc/c/c-typeck.c gcc/c/c-typeck.c
index 1520c20..02f2cf8 100644
--- gcc/c/c-typeck.c
+++ gcc/c/c-typeck.c
@@ -1106,9 +1106,8 @@ comptypes_internal (const_tree type1, const_tree type2, bool *enum_and_int_p,
   switch (TREE_CODE (t1))
     {
     case POINTER_TYPE:
-      /* Do not remove mode or aliasing information.  */
-      if (TYPE_MODE (t1) != TYPE_MODE (t2)
-	  || TYPE_REF_CAN_ALIAS_ALL (t1) != TYPE_REF_CAN_ALIAS_ALL (t2))
+      /* Do not remove mode information.  */
+      if (TYPE_MODE (t1) != TYPE_MODE (t2))
 	break;
       val = (TREE_TYPE (t1) == TREE_TYPE (t2)
 	     ? 1 : comptypes_internal (TREE_TYPE (t1), TREE_TYPE (t2),
diff --git gcc/testsuite/gcc.dg/attr-may-alias-2.c gcc/testsuite/gcc.dg/attr-may-alias-2.c
index e69de29..892748e 100644
--- gcc/testsuite/gcc.dg/attr-may-alias-2.c
+++ gcc/testsuite/gcc.dg/attr-may-alias-2.c
@@ -0,0 +1,13 @@
+/* We used to reject this because types differentiating only in
+   TYPE_REF_CAN_ALIAS_ALL were deemed incompatible.  */
+/* { dg-do compile } */
+
+struct sockaddr;
+struct sockaddr *f (void);
+
+struct __attribute__((may_alias)) sockaddr { int j; };
+struct sockaddr *
+f (void)
+{
+  return (void *) 0;
+}

	Marek

             reply	other threads:[~2016-05-26 14:16 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-26 15:30 Marek Polacek [this message]
2016-05-26 22:25 ` Joseph Myers
     [not found]   ` <20160531131443.GL3014@redhat.com>
2016-05-31 14:25     ` Marek Polacek
2016-06-06 15:06       ` Joseph Myers
2016-06-06 15:23         ` Marek Polacek
2016-06-06 15:33           ` Joseph Myers

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=20160526141651.GB3014@redhat.com \
    --to=polacek@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    /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).