This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix UB in tree-ssa-structalias.c


Another easy to fix bug reported by bootstrap-ubsan.
We check that rhsunitoffset fits into shwi, but even if it does,
8x that might not, in which case we trigger UB.
Fixed by doing the multiplication in unsigned HWI type to make it well

Bootstrapped/regtested on x86_64-linux and i686-linux (both normal
and bootstrap-ubsan), ok for trunk?

2017-06-19  Jakub Jelinek  <>

	* tree-ssa-structalias.c (get_constraint_for_ptr_offset): Multiply
	in UWHI to avoid undefined overflow.

--- gcc/tree-ssa-structalias.c.jj	2017-05-24 11:59:06.000000000 +0200
+++ gcc/tree-ssa-structalias.c	2017-06-19 14:10:50.989594911 +0200
@@ -3087,7 +3087,7 @@ get_constraint_for_ptr_offset (tree ptr,
 	  /* Make sure the bit-offset also fits.  */
 	  HOST_WIDE_INT rhsunitoffset = soffset.to_shwi ();
-	  rhsoffset = rhsunitoffset * BITS_PER_UNIT;
+	  rhsoffset = rhsunitoffset * (unsigned HOST_WIDE_INT) BITS_PER_UNIT;
 	  if (rhsunitoffset != rhsoffset / BITS_PER_UNIT)
 	    rhsoffset = UNKNOWN_OFFSET;


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]