]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization/115236 - more points-to *ANYTHING = x fixes
authorRichard Biener <rguenther@suse.de>
Mon, 27 May 2024 08:41:02 +0000 (10:41 +0200)
committerRichard Biener <rguenther@suse.de>
Tue, 28 May 2024 12:35:35 +0000 (14:35 +0200)
The stored-to ANYTHING handling has more holes, uncovered by treating
volatile accesses as ANYTHING.  We fail to properly build the
pred and succ graphs, in particular we may not elide direct nodes
from receiving from STOREDANYTHING.

PR tree-optimization/115236
* tree-ssa-structalias.cc (build_pred_graph): Properly
handle *ANYTHING = X.
(build_succ_graph): Likewise.  Do not elide direct nodes
from receiving from STOREDANYTHING.

* gcc.dg/pr115236.c: New testcase.

gcc/testsuite/gcc.dg/pr115236.c [new file with mode: 0644]
gcc/tree-ssa-structalias.cc

diff --git a/gcc/testsuite/gcc.dg/pr115236.c b/gcc/testsuite/gcc.dg/pr115236.c
new file mode 100644 (file)
index 0000000..91edfab
--- /dev/null
@@ -0,0 +1,12 @@
+/* { dg-do run } */
+/* { dg-options "-O -fno-tree-fre" } */
+
+int a, *b = &a;
+int main()
+{
+  int *c, *volatile *d = &c;
+  *d = b;
+  if (c != &a)
+    __builtin_abort();
+  return 0;
+}
index 9cec2c6cfd97f2e53bcf326d83dc84e48bd98997..330e64e65da18a7c34307a90181420c403ba2a56 100644 (file)
@@ -1312,7 +1312,12 @@ build_pred_graph (void)
        {
          /* *x = y.  */
          if (rhs.offset == 0 && lhs.offset == 0 && rhs.type == SCALAR)
-           add_pred_graph_edge (graph, FIRST_REF_NODE + lhsvar, rhsvar);
+           {
+             if (lhs.var == anything_id)
+               add_pred_graph_edge (graph, storedanything_id, rhsvar);
+             else
+               add_pred_graph_edge (graph, FIRST_REF_NODE + lhsvar, rhsvar);
+           }
        }
       else if (rhs.type == DEREF)
        {
@@ -1398,7 +1403,12 @@ build_succ_graph (void)
       if (lhs.type == DEREF)
        {
          if (rhs.offset == 0 && lhs.offset == 0 && rhs.type == SCALAR)
-           add_graph_edge (graph, FIRST_REF_NODE + lhsvar, rhsvar);
+           {
+             if (lhs.var == anything_id)
+               add_graph_edge (graph, storedanything_id, rhsvar);
+             else
+               add_graph_edge (graph, FIRST_REF_NODE + lhsvar, rhsvar);
+           }
        }
       else if (rhs.type == DEREF)
        {
@@ -1418,13 +1428,11 @@ build_succ_graph (void)
        }
     }
 
-  /* Add edges from STOREDANYTHING to all non-direct nodes that can
-     receive pointers.  */
+  /* Add edges from STOREDANYTHING to all nodes that can receive pointers.  */
   t = find (storedanything_id);
   for (i = integer_id + 1; i < FIRST_REF_NODE; ++i)
     {
-      if (!bitmap_bit_p (graph->direct_nodes, i)
-         && get_varinfo (i)->may_have_pointers)
+      if (get_varinfo (i)->may_have_pointers)
        add_graph_edge (graph, find (i), t);
     }