Avoid left shift of negative value in ipa-modref-tree.h

Message ID 20211105221957.GE4548@kam.mff.cuni.cz
State Committed
Commit 9cc8ca8da90426f625481195a2127a5e86689bcd
Headers
Series Avoid left shift of negative value in ipa-modref-tree.h |

Commit Message

Jan Hubicka Nov. 5, 2021, 10:19 p.m. UTC
  Hi,
ubsan is complaining about left shift of negative value which is
undefined in c++11..c++17.  Replaced by multiplication.

Bootstrapped/regtested x86_64-linux, comitted.

Honza

gcc/ChangeLog:

	PR ipa/103082
	* ipa-modref-tree.h (struct modref_access_node): Avoid left shift
	of negative value
  

Patch

diff --git a/gcc/ipa-modref-tree.h b/gcc/ipa-modref-tree.h
index 9976e489697..bc428d193d2 100644
--- a/gcc/ipa-modref-tree.h
+++ b/gcc/ipa-modref-tree.h
@@ -116,8 +116,13 @@  struct GTY(()) modref_access_node
 	       if (!known_le (parm_offset, a.parm_offset)
 		   && !range_info_useful_p ())
 		 return false;
+	       /* We allow negative aoffset_adj here in case
+		  there is an useful range.  This is because adding
+		  a.offset may result in non-ngative offset again.
+		  Ubsan fails on val << LOG_BITS_PER_UNIT where val
+		  is negative.  */
 	       aoffset_adj = (a.parm_offset - parm_offset)
-			     << LOG2_BITS_PER_UNIT;
+			     * BITS_PER_UNIT;
 	    }
 	}
       if (range_info_useful_p ())