The ptr-vs-ptr compare folding using points-to info was missing a
check for const_pool being included in the escaped solution.  The
following fixes that, fixing the observed execute FAIL of
experimental/functional/searchers.cc

Bootstrapped on x86_64-unknown-linux-gnu, testing in progress.

        * tree-ssa-alias.h (pt_solution_includes_const_pool): Declare.
        * tree-ssa-alias.cc (ptrs_compare_unequal): Use
        pt_solution_includes_const_pool.
        * tree-ssa-structalias.cc (pt_solution_includes_const_pool): New.

        * gcc.dg/torture/20240517-1.c: New testcase.
---
 gcc/testsuite/gcc.dg/torture/20240517-1.c | 26 +++++++++++++++++++++++
 gcc/tree-ssa-alias.cc                     |  3 ++-
 gcc/tree-ssa-alias.h                      |  1 +
 gcc/tree-ssa-structalias.cc               | 11 ++++++++++
 4 files changed, 40 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.dg/torture/20240517-1.c

diff --git a/gcc/testsuite/gcc.dg/torture/20240517-1.c 
b/gcc/testsuite/gcc.dg/torture/20240517-1.c
new file mode 100644
index 00000000000..ab83d3ca6fb
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/20240517-1.c
@@ -0,0 +1,26 @@
+/* { dg-do run } */
+/* { dg-additional-options "-fmerge-all-constants" } */
+
+char *p;
+
+char * __attribute__((noipa))
+foo () { return p+1; }
+
+volatile int z;
+
+int main()
+{
+  /* ESCAPED = CONST_POOL */
+  p = "Hello";
+  /* PT = ESCAPED */
+  char *x = foo ();
+  char *y;
+  /* y PT = CONST_POOL */
+  if (z)
+    y = "Baz";
+  else
+    y = "Hello" + 1;
+  if (y != x)
+    __builtin_abort ();
+  return 0;
+}
diff --git a/gcc/tree-ssa-alias.cc b/gcc/tree-ssa-alias.cc
index 6d31fc83691..9f5f69bcfad 100644
--- a/gcc/tree-ssa-alias.cc
+++ b/gcc/tree-ssa-alias.cc
@@ -501,7 +501,8 @@ ptrs_compare_unequal (tree ptr1, tree ptr2)
              || pi2->pt.vars_contains_interposable)
            return false;
          if ((!pi1->pt.null || !pi2->pt.null)
-             && (!pi1->pt.const_pool || !pi2->pt.const_pool))
+             && (!pt_solution_includes_const_pool (&pi1->pt)
+                 || !pt_solution_includes_const_pool (&pi2->pt)))
            return !pt_solutions_intersect (&pi1->pt, &pi2->pt);
        }
     }
diff --git a/gcc/tree-ssa-alias.h b/gcc/tree-ssa-alias.h
index e29dff58375..5cd64e72295 100644
--- a/gcc/tree-ssa-alias.h
+++ b/gcc/tree-ssa-alias.h
@@ -178,6 +178,7 @@ extern bool pt_solution_empty_p (const pt_solution *);
 extern bool pt_solution_singleton_or_null_p (struct pt_solution *, unsigned *);
 extern bool pt_solution_includes_global (struct pt_solution *, bool);
 extern bool pt_solution_includes (struct pt_solution *, const_tree);
+extern bool pt_solution_includes_const_pool (struct pt_solution *);
 extern bool pt_solutions_intersect (struct pt_solution *, struct pt_solution 
*);
 extern void pt_solution_reset (struct pt_solution *);
 extern void pt_solution_set (struct pt_solution *, bitmap, bool);
diff --git a/gcc/tree-ssa-structalias.cc b/gcc/tree-ssa-structalias.cc
index 0c6085b1766..61fb3610a17 100644
--- a/gcc/tree-ssa-structalias.cc
+++ b/gcc/tree-ssa-structalias.cc
@@ -7080,6 +7080,17 @@ pt_solution_includes (struct pt_solution *pt, const_tree 
decl)
   return res;
 }
 
+/* Return true if the points-to solution *PT contains a reference to a
+   constant pool entry.  */
+
+bool
+pt_solution_includes_const_pool (struct pt_solution *pt)
+{
+  return (pt->const_pool
+         || (pt->escaped && (!cfun || cfun->gimple_df->escaped.const_pool))
+         || (pt->ipa_escaped && ipa_escaped_pt.const_pool));
+}
+
 /* Return true if both points-to solutions PT1 and PT2 have a non-empty
    intersection.  */
 
-- 
2.35.3

Reply via email to