https://gcc.gnu.org/g:b423035d75f742a7377185a195231a62f1e36e92
commit r17-6490-gb423035d75f742a7377185a195231a62f1e36e92 Author: Richard Biener <[email protected]> Date: Fri Nov 20 08:55:58 2026 +0100 tree-optimization/90241 - overflow in bytes to bits conversion For large offsets ao_ref_init_from_ptr_and_range can lead to wrong code. Make sure the offset in bits fits a poly_int64. PR tree-optimization/90241 * tree-ssa-alias.cc (ao_ref_init_from_ptr_and_range): Add missing range check before multiplying byte offset by 8. * gcc.dg/pr90241.c: New testcase. Diff: --- gcc/testsuite/gcc.dg/pr90241.c | 12 ++++++++++++ gcc/tree-ssa-alias.cc | 7 +++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/gcc/testsuite/gcc.dg/pr90241.c b/gcc/testsuite/gcc.dg/pr90241.c new file mode 100644 index 000000000000..8e93de3483d5 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr90241.c @@ -0,0 +1,12 @@ +/* { dg-do compile } */ +/* { dg-require-effective-target lp64 } */ +/* { dg-options "-O2 -fdump-tree-optimized" } */ + +#define OFF (1ULL << 61) +void g (char *p) +{ + p[0] = 1; /* live */ + __builtin_memset (p + OFF, 7, 1000); /* does not touch p[0] */ +} + +/* { dg-final { scan-tree-dump " = 1;" "optimized" } } */ diff --git a/gcc/tree-ssa-alias.cc b/gcc/tree-ssa-alias.cc index 41072b4d5d9b..ea14fd339ca2 100644 --- a/gcc/tree-ssa-alias.cc +++ b/gcc/tree-ssa-alias.cc @@ -912,10 +912,13 @@ ao_ref_init_from_ptr_and_range (ao_ref *ref, tree ptr, ptr = gimple_assign_rhs1 (stmt); else if (is_gimple_assign (stmt) && gimple_assign_rhs_code (stmt) == POINTER_PLUS_EXPR - && ptrdiff_tree_p (gimple_assign_rhs2 (stmt), &extra_offset)) + && ptrdiff_tree_p (gimple_assign_rhs2 (stmt), &t) + && coeffs_in_range_p (t, + -HOST_WIDE_INT_MAX / BITS_PER_UNIT, + HOST_WIDE_INT_MAX / BITS_PER_UNIT)) { ptr = gimple_assign_rhs1 (stmt); - extra_offset *= BITS_PER_UNIT; + extra_offset = t * BITS_PER_UNIT; } }
