]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization/123310 - wrong aggregate copy VN
authorRichard Biener <rguenther@suse.de>
Thu, 8 Jan 2026 12:08:57 +0000 (13:08 +0100)
committerRichard Biener <rguenth@gcc.gnu.org>
Thu, 8 Jan 2026 13:23:25 +0000 (14:23 +0100)
There's a typo in the check against unknown offset when processing
an aggregate copy during VN, leading to wrong lookup.

PR tree-optimization/123310
* tree-ssa-sccvn.cc (vn_reference_lookup_3): Properly
test against unknown offset.

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

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

diff --git a/gcc/testsuite/gcc.dg/torture/pr123310.c b/gcc/testsuite/gcc.dg/torture/pr123310.c
new file mode 100644 (file)
index 0000000..1c2dee6
--- /dev/null
@@ -0,0 +1,21 @@
+/* { dg-do run } */
+
+struct a {
+    short b;
+} c[7], e;
+int d;
+static struct a f[3][2] = {{}, {}, 5, 5};
+void __attribute__((noipa)) g()
+{
+  for (; e.b >= 0; e.b--)
+    {
+      c[e.b + 6] = f[2][1];
+      d = c[6].b;
+    }
+}
+int main()
+{
+  g();
+  if (d != 5)
+    __builtin_abort ();
+}
index 6fda0ef604407c9ad71cace8a0ddf98183839afa..16343d2a407f6a8635a661b0de697479ff2f491a 100644 (file)
@@ -3694,7 +3694,7 @@ vn_reference_lookup_3 (ao_ref *ref, tree vuse, void *data_,
         via extra_off.  Note this is an attempt to fixup secondary
         copies after we hit the !found && j == 0 case above.  */
       while (j != -1
-            && known_ne (lhs_ops[j].off, -1U))
+            && known_ne (lhs_ops[j].off, -1))
        {
          extra_off += -lhs_ops[j].off;
          j--;