This is the mail archive of the gcc-patches@gcc.gnu.org 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]

[3/4] Avoid undefined operation in overflow check


This is a case where tree_to_shwi can be used instead of TREE_INT_CST_LOW.
I separated it out because it was using a signed "x * y / y == x" to check
whether "x * y" overflows a HWI, which relies on undefined behaviour.

Thanks,
Richard


gcc/
	* tree-ssa-alias.c (ao_ref_init_from_ptr_and_size): Avoid signed
	overflow.  Use tree_to_shwi.

Index: gcc/tree-ssa-alias.c
===================================================================
--- gcc/tree-ssa-alias.c	2013-11-19 10:53:54.965643984 +0000
+++ gcc/tree-ssa-alias.c	2013-11-19 11:08:51.882992035 +0000
@@ -615,9 +615,8 @@ ao_ref_init_from_ptr_and_size (ao_ref *r
   ref->offset += extra_offset;
   if (size
       && tree_fits_shwi_p (size)
-      && TREE_INT_CST_LOW (size) * BITS_PER_UNIT / BITS_PER_UNIT
-	 == TREE_INT_CST_LOW (size))
-    ref->max_size = ref->size = TREE_INT_CST_LOW (size) * BITS_PER_UNIT;
+      && tree_to_shwi (size) <= HOST_WIDE_INT_MAX / BITS_PER_UNIT)
+    ref->max_size = ref->size = tree_to_shwi (size) * BITS_PER_UNIT;
   else
     ref->max_size = ref->size = -1;
   ref->ref_alias_set = 0;


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