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]

[PATCH] Fix simplify_builtin_call forwprop ICE (PR tree-optimization/64269)


Hi!

This testcase ICEs because I wasn't checking for overflow in the size
computation.  Only max (diff + len2, len1) <= 1024 cases are considered,
so this patch gives up if either len2 or diff is > 1024.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk/4.9/4.8?

2014-12-12  Jakub Jelinek  <jakub@redhat.com>

	PR tree-optimization/64269
	* tree-ssa-forwprop.c (simplify_builtin_call): Bail out if
	len2 or diff are too large.

	* gcc.c-torture/compile/pr64269.c: New test.

--- gcc/tree-ssa-forwprop.c.jj	2014-12-01 14:57:30.000000000 +0100
+++ gcc/tree-ssa-forwprop.c	2014-12-12 09:46:05.790053928 +0100
@@ -1288,7 +1288,8 @@ simplify_builtin_call (gimple_stmt_itera
 	  use_operand_p use_p;
 
 	  if (!tree_fits_shwi_p (val2)
-	      || !tree_fits_uhwi_p (len2))
+	      || !tree_fits_uhwi_p (len2)
+	      || compare_tree_int (len2, 1024) == 1)
 	    break;
 	  if (is_gimple_call (stmt1))
 	    {
@@ -1354,7 +1355,8 @@ simplify_builtin_call (gimple_stmt_itera
 	     is not constant, or is bigger than memcpy length, bail out.  */
 	  if (diff == NULL
 	      || !tree_fits_uhwi_p (diff)
-	      || tree_int_cst_lt (len1, diff))
+	      || tree_int_cst_lt (len1, diff)
+	      || compare_tree_int (diff, 1024) == 1)
 	    break;
 
 	  /* Use maximum of difference plus memset length and memcpy length
--- gcc/testsuite/gcc.c-torture/compile/pr64269.c.jj	2014-12-12 09:47:04.795015479 +0100
+++ gcc/testsuite/gcc.c-torture/compile/pr64269.c	2014-12-12 09:46:51.000000000 +0100
@@ -0,0 +1,9 @@
+/* PR tree-optimization/64269 */
+
+void
+foo (char *p)
+{
+  __SIZE_TYPE__ s = ~(__SIZE_TYPE__)0;
+  *p = 0;
+  __builtin_memset (p + 1, 0, s);
+}

	Jakub


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