Patchwork [committed] Fix a regression caused by my __builtin_unreachable assertion changes (PR tree-optimization/58978)

login
register
mail settings
Submitter Jakub Jelinek
Date Nov. 4, 2013, 8:19 p.m.
Message ID <20131104201947.GY27813@tucnak.zalov.cz>
Download mbox | patch
Permalink /patch/288246/
State New
Headers show

Comments

Jakub Jelinek - Nov. 4, 2013, 8:19 p.m.
Hi!

single_imm_use (to my surprise) modifies what it's last argument points to
even when returning false, this function wasn't expecting that. 
Furthermore, if a the var is used in a store which does't have lhs as
SSA_NAME, this would ICE.

Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux,
committed to trunk as obvious.

2013-11-04  Jakub Jelinek  <jakub@redhat.com>

	PR tree-optimization/58978
	* tree-vrp.c (all_imm_uses_in_stmt_or_feed_cond): Don't modify
	use_stmt by single_imm_use directly.  Only call single_imm_use
	on SSA_NAMEs.

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


	Jakub

Patch

--- gcc/tree-vrp.c.jj	2013-11-04 11:27:35.694278458 +0100
+++ gcc/tree-vrp.c	2013-11-04 16:16:59.607689824 +0100
@@ -6472,13 +6472,14 @@  all_imm_uses_in_stmt_or_feed_cond (tree
   FOR_EACH_IMM_USE_FAST (use_p, iter, var)
     if (USE_STMT (use_p) != stmt)
       {
-	gimple use_stmt = USE_STMT (use_p);
+	gimple use_stmt = USE_STMT (use_p), use_stmt2;
 	if (is_gimple_debug (use_stmt))
 	  continue;
 	while (is_gimple_assign (use_stmt)
+	       && TREE_CODE (gimple_assign_lhs (use_stmt)) == SSA_NAME
 	       && single_imm_use (gimple_assign_lhs (use_stmt),
-				  &use2_p, &use_stmt))
-	  ;
+				  &use2_p, &use_stmt2))
+	  use_stmt = use_stmt2;
 	if (gimple_code (use_stmt) != GIMPLE_COND
 	    || gimple_bb (use_stmt) != cond_bb)
 	  return false;
--- gcc/testsuite/gcc.c-torture/compile/pr58978.c.jj	2013-11-04 16:16:18.542905275 +0100
+++ gcc/testsuite/gcc.c-torture/compile/pr58978.c	2013-11-04 16:16:18.542905275 +0100
@@ -0,0 +1,16 @@ 
+/* PR tree-optimization/58978 */
+
+int
+foo (int x)
+{
+  switch (x)
+    {
+    case 0:
+    case 1:
+    case 9:
+      break;
+    default:
+      __builtin_unreachable ();
+    }
+  return x;
+}