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 <pola...@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