From: Richard Biener Date: Thu, 8 Jan 2026 12:08:57 +0000 (+0100) Subject: tree-optimization/123310 - wrong aggregate copy VN X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6225251b90056f21b5896be46ed2c3c5a823a848;p=thirdparty%2Fgcc.git tree-optimization/123310 - wrong aggregate copy VN 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. --- diff --git a/gcc/testsuite/gcc.dg/torture/pr123310.c b/gcc/testsuite/gcc.dg/torture/pr123310.c new file mode 100644 index 00000000000..1c2dee65c8d --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr123310.c @@ -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 (); +} diff --git a/gcc/tree-ssa-sccvn.cc b/gcc/tree-ssa-sccvn.cc index 6fda0ef6044..16343d2a407 100644 --- a/gcc/tree-ssa-sccvn.cc +++ b/gcc/tree-ssa-sccvn.cc @@ -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--;