]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization/121323 - UBSAN error in ao_ref_init_from_ptr_and_range
authorRichard Biener <rguenther@suse.de>
Thu, 31 Jul 2025 11:04:49 +0000 (13:04 +0200)
committerRichard Biener <rguenther@suse.de>
Thu, 31 Jul 2025 12:12:50 +0000 (14:12 +0200)
We should check the offset fits a HWI when multiplied to be in bits.

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

index 41193432cc1048b3168b49db4a0753e7212c4ff7..9b028e0404600fe1c9cf2d69f4fb49e8d5860f7e 100644 (file)
@@ -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
        {