This makes same_type_for_tbaa_p conservative in the same way
get_alias_set is about void * which we allow to alias all other
pointers.

Bootstrap & regtest running on x86_64-unknown-linux-gnu.

Honza, is this what you had in mind?

Thanks,
Richard.

2020-04-14  Richard Biener  <rguent...@suse.de>

        PR middle-end/94539
        * tree-ssa-alias.c (same_type_for_tbaa): Handle void *
        pointers the same as get_alias_set, returning -1.

        * gcc.dg/alias-14.c: Make dg-do run.
---
 gcc/testsuite/gcc.dg/alias-14.c | 2 +-
 gcc/tree-ssa-alias.c            | 9 +++++++++
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/gcc/testsuite/gcc.dg/alias-14.c b/gcc/testsuite/gcc.dg/alias-14.c
index 1ca1c09d5e3..24f0d1c1168 100644
--- a/gcc/testsuite/gcc.dg/alias-14.c
+++ b/gcc/testsuite/gcc.dg/alias-14.c
@@ -1,4 +1,4 @@
-/* { dg-do compile } */
+/* { dg-do run } */
 /* { dg-options "-O2" } */
 #include <stddef.h>
 void *a;
diff --git a/gcc/tree-ssa-alias.c b/gcc/tree-ssa-alias.c
index df9ba0de0d6..2850141303e 100644
--- a/gcc/tree-ssa-alias.c
+++ b/gcc/tree-ssa-alias.c
@@ -831,6 +831,15 @@ same_type_for_tbaa (tree type1, tree type2)
       && TREE_CODE (type2) == ARRAY_TYPE)
     return -1;
 
+  /* void * is compatible with all other pointers.  */
+  if (POINTER_TYPE_P (type1)
+      && POINTER_TYPE_P (type2)
+      && (TREE_CODE (TREE_TYPE (type1)) == VOID_TYPE
+         || TYPE_STRUCTURAL_EQUALITY_P (TREE_TYPE (type1))
+         || TREE_CODE (TREE_TYPE (type2)) == VOID_TYPE
+         || TYPE_STRUCTURAL_EQUALITY_P (TREE_TYPE (type2))))
+    return -1;
+
   /* ??? In Ada, an lvalue of an unconstrained type can be used to access an
      object of one of its constrained subtypes, e.g. when a function with an
      unconstrained parameter passed by reference is called on an object and
-- 
2.25.1

Reply via email to