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

Jan Hubicka hubicka@kam.mff.cuni.cz
Fri Nov 5 22:19:57 GMT 2021


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

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 ())


More information about the Gcc-patches mailing list