]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Add missing check for const_pool in the escaped solutions
authorRichard Biener <rguenther@suse.de>
Fri, 17 May 2024 07:31:52 +0000 (09:31 +0200)
committerRichard Biener <rguenther@suse.de>
Fri, 17 May 2024 08:54:11 +0000 (10:54 +0200)
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

* 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 [new file with mode: 0644]
gcc/tree-ssa-alias.cc
gcc/tree-ssa-alias.h
gcc/tree-ssa-structalias.cc

diff --git a/gcc/testsuite/gcc.dg/torture/20240517-1.c b/gcc/testsuite/gcc.dg/torture/20240517-1.c
new file mode 100644 (file)
index 0000000..ab83d3c
--- /dev/null
@@ -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;
+}
index 6d31fc836917259a2627b55ee994884c163d3d8c..9f5f69bcfad20a48339605a632fa2e079b2d7f2a 100644 (file)
@@ -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);
        }
     }
index e29dff5837503e764976af061405635ccbadd092..5cd64e722955cf2c9040bee0b26d010388069a66 100644 (file)
@@ -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);
index 0c6085b17662a7a8dabc6d0e8265ca5a70cb0753..61fb3610a1725407c755fd15ddd81b96d57f5ec8 100644 (file)
@@ -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.  */