aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Biener <rguenther@suse.de>2024-05-17 09:31:52 +0200
committerRichard Biener <rguenther@suse.de>2024-05-17 10:54:11 +0200
commitb420e0b920613c42f63252aa2478a8315dc37a13 (patch)
tree881fa8b9789ef27b8a69bfec8f2073e9c6400716
parent9bd0b709ddb70589436c326142b1566f49f5e979 (diff)
downloadgcc-b420e0b920613c42f63252aa2478a8315dc37a13.zip
gcc-b420e0b920613c42f63252aa2478a8315dc37a13.tar.gz
gcc-b420e0b920613c42f63252aa2478a8315dc37a13.tar.bz2
Add missing check for const_pool in the escaped solutions
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.
-rw-r--r--gcc/testsuite/gcc.dg/torture/20240517-1.c26
-rw-r--r--gcc/tree-ssa-alias.cc3
-rw-r--r--gcc/tree-ssa-alias.h1
-rw-r--r--gcc/tree-ssa-structalias.cc11
4 files changed, 40 insertions, 1 deletions
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 0000000..ab83d3c
--- /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 6d31fc8..9f5f69b 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 e29dff5..5cd64e7 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 0c6085b..61fb361 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. */