We should check the offset fits a HWI when multiplied to be in bits.

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

        PR tree-optimization/121323
        * tree-ssa-alias.cc (ao_ref_init_from_ptr_and_range): Check
        the pointer offset fits in a HWI when represented in bits.
---
 gcc/tree-ssa-alias.cc | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/gcc/tree-ssa-alias.cc b/gcc/tree-ssa-alias.cc
index 41193432cc1..9b028e04046 100644
--- a/gcc/tree-ssa-alias.cc
+++ b/gcc/tree-ssa-alias.cc
@@ -901,7 +901,9 @@ ao_ref_init_from_ptr_and_range (ao_ref *ref, tree ptr,
   if (TREE_CODE (ptr) == ADDR_EXPR)
     {
       ref->base = get_addr_base_and_unit_offset (TREE_OPERAND (ptr, 0), &t);
-      if (ref->base)
+      if (ref->base
+         && coeffs_in_range_p (t, -HOST_WIDE_INT_MAX / BITS_PER_UNIT,
+                               HOST_WIDE_INT_MAX / BITS_PER_UNIT))
        ref->offset = BITS_PER_UNIT * t;
       else
        {
-- 
2.43.0

Reply via email to