]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization/90242 - UBSAN error in vn_reference_compute_hash
authorRichard Biener <rguenther@suse.de>
Fri, 1 Aug 2025 13:07:15 +0000 (15:07 +0200)
committerRichard Biener <rguenther@suse.de>
Sun, 3 Aug 2025 07:25:46 +0000 (09:25 +0200)
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.

gcc/tree-ssa-sccvn.cc

index a3117dacb969740b34d43d314c469afea37a1e77..3974c4d458304cfa5d061714e624665802410416 100644 (file)
@@ -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;