https://gcc.gnu.org/g:7c99de1c439dbb149cc6a33a214f22f2df1c88f3

commit r16-2720-g7c99de1c439dbb149cc6a33a214f22f2df1c88f3
Author: Richard Biener <rguent...@suse.de>
Date:   Fri Aug 1 15:07:15 2025 +0200

    tree-optimization/90242 - UBSAN error in vn_reference_compute_hash
    
    The following plugs possible overflow issues in vn_reference_compute_hash
    and possibly in vn_reference_eq.  The inchash "integer" adds are a bit
    of a mess, but I know overloads with different integer types can get
    messy, so not this time.  For hashing simply truncate to 64bits.
    
            PR tree-optimization/90242
            * tree-ssa-sccvn.cc (vn_reference_compute_hash): Use
            poly_offset_int for offset accumulation.  For hashing
            truncate to 64 bits and also hash 64 bits.
            (vn_reference_eq): Likewise.

Diff:
---
 gcc/tree-ssa-sccvn.cc | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/gcc/tree-ssa-sccvn.cc b/gcc/tree-ssa-sccvn.cc
index a3117dacb969..3974c4d45830 100644
--- a/gcc/tree-ssa-sccvn.cc
+++ b/gcc/tree-ssa-sccvn.cc
@@ -717,7 +717,7 @@ vn_reference_compute_hash (const vn_reference_t vr1)
   hashval_t result;
   int i;
   vn_reference_op_t vro;
-  poly_int64 off = -1;
+  poly_offset_int off = -1;
   bool deref = false;
 
   FOR_EACH_VEC_ELT (vr1->operands, i, vro)
@@ -736,7 +736,7 @@ vn_reference_compute_hash (const vn_reference_t vr1)
        {
          if (maybe_ne (off, -1)
              && maybe_ne (off, 0))
-           hstate.add_poly_int (off);
+           hstate.add_poly_hwi (off.force_shwi ());
          off = -1;
          if (deref
              && vro->opcode == ADDR_EXPR)
@@ -850,7 +850,7 @@ vn_reference_eq (const_vn_reference_t const vr1, 
const_vn_reference_t const vr2)
   j = 0;
   do
     {
-      poly_int64 off1 = 0, off2 = 0;
+      poly_offset_int off1 = 0, off2 = 0;
       vn_reference_op_t vro1, vro2;
       vn_reference_op_s tem1, tem2;
       bool deref1 = false, deref2 = false;

Reply via email to