re PR middle-end/80222 (may_alias folded away)
authorRichard Biener <rguenther@suse.de>
Tue, 28 Mar 2017 10:10:01 +0000 (10:10 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Tue, 28 Mar 2017 10:10:01 +0000 (10:10 +0000)
2017-03-28  Richard Biener  <rguenther@suse.de>

PR middle-end/80222
* gimple-fold.c (gimple_fold_indirect_ref): Do not touch
TYPE_REF_CAN_ALIAS_ALL references.
* fold-const.c (fold_indirect_ref_1): Likewise.

* g++.dg/pr80222.C: New testcase.

From-SVN: r246527

gcc/ChangeLog
gcc/fold-const.c
gcc/gimple-fold.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/pr80222.C [new file with mode: 0644]

index 27e7b8f0a75210f8cccbfae96a5630e9f1042303..7274aa4e7a6ed5bf0fa210fd4f236be1cdb7cfcb 100644 (file)
@@ -1,3 +1,10 @@
+2017-03-28  Richard Biener  <rguenther@suse.de>
+
+       PR middle-end/80222
+       * gimple-fold.c (gimple_fold_indirect_ref): Do not touch
+       TYPE_REF_CAN_ALIAS_ALL references.
+       * fold-const.c (fold_indirect_ref_1): Likewise.
+
 2017-03-28  Martin Liska  <mliska@suse.cz>
 
        PR ipa/80104
index 6db16b514f1f32efd2e0a9beb2bb402c6137a398..fb54ffa0e5e0a46576995eb5adc5ff8229bdf991 100644 (file)
@@ -14006,7 +14006,8 @@ fold_indirect_ref_1 (location_t loc, tree type, tree op0)
 
   STRIP_NOPS (sub);
   subtype = TREE_TYPE (sub);
-  if (!POINTER_TYPE_P (subtype))
+  if (!POINTER_TYPE_P (subtype)
+      || TYPE_REF_CAN_ALIAS_ALL (TREE_TYPE (op0)))
     return NULL_TREE;
 
   if (TREE_CODE (sub) == ADDR_EXPR)
index 3094b54c109d06d1b0d98b6afd30d69d2f0ba19b..a6a958cefa4c560df9b828d55100e2802c2a1fd1 100644 (file)
@@ -6539,8 +6539,8 @@ gimple_get_virt_method_for_binfo (HOST_WIDE_INT token, tree known_binfo,
   return gimple_get_virt_method_for_vtable (token, v, offset, can_refer);
 }
 
-/* Given a pointer value OP0, return a simplified version of an
-   indirection through OP0, or NULL_TREE if no simplification is
+/* Given a pointer value T, return a simplified version of an
+   indirection through T, or NULL_TREE if no simplification is
    possible.  Note that the resulting type may be different from
    the type pointed to in the sense that it is still compatible
    from the langhooks point of view. */
@@ -6554,7 +6554,8 @@ gimple_fold_indirect_ref (tree t)
 
   STRIP_NOPS (sub);
   subtype = TREE_TYPE (sub);
-  if (!POINTER_TYPE_P (subtype))
+  if (!POINTER_TYPE_P (subtype)
+      || TYPE_REF_CAN_ALIAS_ALL (ptype))
     return NULL_TREE;
 
   if (TREE_CODE (sub) == ADDR_EXPR)
index a896f753719897c3f92cf5f886f3a9f1066c6755..4abe1dc0cfafe904e82fceb7f6664187d0f0cb04 100644 (file)
@@ -1,3 +1,8 @@
+2017-03-28  Richard Biener  <rguenther@suse.de>
+
+       PR middle-end/80222
+       * g++.dg/pr80222.C: New testcase.
+
 2017-03-28  Martin Liska  <mliska@suse.cz>
 
        PR ipa/80104
diff --git a/gcc/testsuite/g++.dg/pr80222.C b/gcc/testsuite/g++.dg/pr80222.C
new file mode 100644 (file)
index 0000000..ed1b37f
--- /dev/null
@@ -0,0 +1,13 @@
+// { dg-do compile }
+// { dg-options "-O2 -fdump-tree-optimized" } */
+
+struct C { int i; }__attribute__((may_alias)) ;
+
+C a, b;
+
+int main()
+{
+  a = static_cast <C&> (b);
+}
+
+// { dg-final { scan-tree-dump "{ref-all}\\\)&b\];" "optimized" } } */