diff mbox series

tree-optimization/115199 - fix PTA constraint processing for &ANYTHING LHS

Message ID 20240523113759.4E2EB3858D33@sourceware.org
State New
Headers show
Series tree-optimization/115199 - fix PTA constraint processing for &ANYTHING LHS | expand

Commit Message

Richard Biener May 23, 2024, 11:37 a.m. UTC
When processing a &ANYTHING = X constraint we treat it as *ANYTHING = X
during constraint processing but then end up recording it as
&ANYTHING = X anyway, breaking constraint graph building.  This is
because we only update the local copy of the LHS and not the constraint
itself.

Bootstrap and regtest running on x86_64-unknown-linux-gnu.

	PR tree-optimization/115199
	* tree-ssa-structalias.cc (process_constraint): Also
	record &ANYTHING = X as *ANYTING = X in the end.

	* gcc.dg/torture/pr115199.c: New testcase.
---
 gcc/testsuite/gcc.dg/torture/pr115199.c | 24 ++++++++++++++++++++++++
 gcc/tree-ssa-structalias.cc             |  2 +-
 2 files changed, 25 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.dg/torture/pr115199.c
diff mbox series

Patch

diff --git a/gcc/testsuite/gcc.dg/torture/pr115199.c b/gcc/testsuite/gcc.dg/torture/pr115199.c
new file mode 100644
index 00000000000..981a7330b32
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr115199.c
@@ -0,0 +1,24 @@ 
+/* { dg-do run } */
+
+struct b {
+  char *volatile c;
+};
+struct b * __attribute__((noipa))
+d()
+{
+  char *e;
+  struct b *b = __builtin_malloc(sizeof(b));
+  void *f = __builtin_malloc(1);
+
+  e = __builtin_memcpy(f, "z", 1);
+  b->c = e;
+  return b;
+}
+
+int main()
+{
+  struct b b = *d();
+  if (b.c[0] != 'z')
+    __builtin_abort();
+  return 0;
+}
diff --git a/gcc/tree-ssa-structalias.cc b/gcc/tree-ssa-structalias.cc
index 0e9423a78ec..a39b36c146e 100644
--- a/gcc/tree-ssa-structalias.cc
+++ b/gcc/tree-ssa-structalias.cc
@@ -3104,7 +3104,7 @@  process_constraint (constraint_t t)
      it here by turning it into *ANYTHING.  */
   if (lhs.type == ADDRESSOF
       && lhs.var == anything_id)
-    lhs.type = DEREF;
+    t->lhs.type = lhs.type = DEREF;
 
   /* ADDRESSOF on the lhs is invalid.  */
   gcc_assert (lhs.type != ADDRESSOF);