+2008-07-15 Richard Guenther <rguenther@suse.de>
+
+ PR middle-end/36369
+ * c-common.c (strict_aliasing_warning): Do not warn for
+ TYPE_REF_CAN_ALIAS_ALL pointers.
+ (c_common_get_alias_set): may_alias types are not special.
+ * tree.c (build_pointer_type_for_mode): Look up the may_alias
+ attribute and set can_ref_all accordingly.
+ (build_reference_type_for_mode): Likewise.
+ * doc/extend.texi (may_alias): Clarify.
+
2008-07-15 Kaz Kojima <kkojima@gcc.gnu.org>
PR target/36780
bool
strict_aliasing_warning (tree otype, tree type, tree expr)
{
- if (!(flag_strict_aliasing && POINTER_TYPE_P (type)
- && POINTER_TYPE_P (otype) && !VOID_TYPE_P (TREE_TYPE (type))))
+ if (!(flag_strict_aliasing
+ && POINTER_TYPE_P (type)
+ && POINTER_TYPE_P (otype)
+ && !VOID_TYPE_P (TREE_TYPE (type)))
+ /* If the type we are casting to is a ref-all pointer
+ dereferencing it is always valid. */
+ || TYPE_REF_CAN_ALIAS_ALL (type))
return false;
if ((warn_strict_aliasing > 1) && TREE_CODE (expr) == ADDR_EXPR
|| t == unsigned_char_type_node)
return 0;
- /* If it has the may_alias attribute, it can alias anything. */
- if (lookup_attribute ("may_alias", TYPE_ATTRIBUTES (t)))
- return 0;
-
/* The C standard specifically allows aliasing between signed and
unsigned variants of the same type. We treat the signed
variant as canonical. */
variables (@pxref{Function Attributes}, @pxref{Variable Attributes}.)
@item may_alias
-Accesses to objects with types with this attribute are not subjected to
-type-based alias analysis, but are instead assumed to be able to alias
-any other type of objects, just like the @code{char} type. See
-@option{-fstrict-aliasing} for more information on aliasing issues.
+Accesses through pointers to types with this attribute are not subject
+to type-based alias analysis, but are instead assumed to be able to alias
+any other type of objects. In the context of 6.5/7 an lvalue expression
+dereferencing such a pointer is treated like having a character type.
+See @option{-fstrict-aliasing} for more information on aliasing issues.
+This extension exists to support some vector APIs, in which pointers to
+one vector type are permitted to alias pointers to a different vector type.
+
+Note that an object of a type with this attribute does not have any
+special semantics.
Example of use:
+2008-07-15 Richard Guenther <rguenther@suse.de>
+
+ PR middle-end/36369
+ * gcc.dg/Wstrict-aliasing-bogus-ref-all.c: New testcase.
+
2008-07-15 Andrew Pinski <andrew_pinski@playstation.sony.com>
PR target/31568
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O2 -Wall" } */
+
+struct g { long a; };
+unsigned long f(struct g *a) { return *(unsigned long *)&a->a; }
+
+struct A
+{
+ void *a;
+};
+
+int g(const struct A *x, long *y)
+{
+ typedef long __attribute__ ((may_alias)) long_a;
+ *y = *(const long_a *) (&x->a);
+ return 1;
+}
+
+void *a;
+
+int
+f0 (long *y)
+{
+ *y = *(const long *) &a; /* { dg-warning "will break" } */
+ return 1;
+}
+
+int
+f1 (long *y)
+{
+ typedef long __attribute__ ((may_alias)) long_a;
+ *y = *(const long_a *) &a;
+ return 1;
+}
+
+int
+f2 (long *y)
+{
+ *y = *(const long *) &a; /* { dg-warning "will break" } */
+ return 1;
+}
if (to_type == error_mark_node)
return error_mark_node;
+ /* If the pointed-to type has the may_alias attribute set, force
+ a TYPE_REF_CAN_ALIAS_ALL pointer to be generated. */
+ if (lookup_attribute ("may_alias", TYPE_ATTRIBUTES (to_type)))
+ can_alias_all = true;
+
/* In some cases, languages will have things that aren't a POINTER_TYPE
(such as a RECORD_TYPE for fat pointers in Ada) as TYPE_POINTER_TO.
In that case, return that type without regard to the rest of our
{
tree t;
+ if (to_type == error_mark_node)
+ return error_mark_node;
+
+ /* If the pointed-to type has the may_alias attribute set, force
+ a TYPE_REF_CAN_ALIAS_ALL pointer to be generated. */
+ if (lookup_attribute ("may_alias", TYPE_ATTRIBUTES (to_type)))
+ can_alias_all = true;
+
/* In some cases, languages will have things that aren't a REFERENCE_TYPE
(such as a RECORD_TYPE for fat pointers in Ada) as TYPE_REFERENCE_TO.
In that case, return that type without regard to the rest of our