]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
rtl-optimization/109585 - alias analysis typo
authorRichard Biener <rguenther@suse.de>
Mon, 24 Apr 2023 11:31:07 +0000 (13:31 +0200)
committerRichard Biener <rguenther@suse.de>
Wed, 26 Apr 2023 09:35:12 +0000 (11:35 +0200)
When r10-514-gc6b84edb6110dd2b4fb improved access path analysis
it introduced a typo that triggers when there's an access to a
trailing array in the first access path leading to false
disambiguation.

PR rtl-optimization/109585
* tree-ssa-alias.cc (aliasing_component_refs_p): Fix typo.

* gcc.dg/torture/pr109585.c: New testcase.

(cherry picked from commit 6d4bd27a60447c7505cb4783e675e98a191a8904)

gcc/testsuite/gcc.dg/torture/pr109585.c [new file with mode: 0644]
gcc/tree-ssa-alias.cc

diff --git a/gcc/testsuite/gcc.dg/torture/pr109585.c b/gcc/testsuite/gcc.dg/torture/pr109585.c
new file mode 100644 (file)
index 0000000..f92de7c
--- /dev/null
@@ -0,0 +1,33 @@
+/* { dg-do run } */
+
+#include <stdlib.h>
+
+struct P {
+    long v;
+    struct P *n;
+};
+
+struct F {
+    long x;
+    struct P fam[];
+};
+
+int __attribute__((noipa))
+f(struct F *f, int i)
+{
+  struct P *p = f->fam;
+  asm("" : "+r"(f): "r"(p));
+  p->v = 0;
+  p->n = 0;
+  return f->fam->n != 0;
+}
+
+int
+main()
+{
+  struct F *m = malloc (sizeof (long) + 2 * sizeof (struct P));
+  m->fam[0].n = &m->fam[1];
+  if (f (m, 0))
+    abort ();
+  return 0;
+}
index b1e7a2d5afc0053450d82c3a4de29e1e1f794002..be7b597266f03092086925efabe32f6420082a99 100644 (file)
@@ -1326,7 +1326,7 @@ aliasing_component_refs_p (tree ref1,
   /* If we didn't find a common base, try the other way around.  */
   if (cmp_outer <= 0 
       || (end_struct_ref1
-         && compare_type_sizes (TREE_TYPE (end_struct_ref1), type1) <= 0))
+         && compare_type_sizes (TREE_TYPE (end_struct_ref1), type2) <= 0))
     {
       int res = aliasing_component_refs_walk (ref2, type2, base2,
                                              offset2, max_size2,