diff mbox

Fix get_maxval_strlen for COND_EXPR after changing them to ternary

Message ID CA+=Sn1m+rsRvO7P--U8+VWVhmVH2015UG-qZdJDg7wWSE_tyVw@mail.gmail.com
State New
Headers show

Commit Message

Andrew Pinski May 16, 2012, 7:34 p.m. UTC
When COND_EXPR was changed from GIMPLE_SINGLE_RHS to
GIMPLE_TERNARY_RHS, get_maxval_strlen was not updated for that
changed.  With a patch which has a late PHIOPT produce COND_EXPR, I
saw a couple of regressions (pr23484-chk.c and  strncpy-chk.c).

This patch fixes get_maxval_strlen for that change.

OK for the trunk and 4.7 branch?  Bootstrapped and tested on
x86_64-linux-gnu with no regressions.  And in 4.7.0 with the patch for
PHIOPT producing COND_EXPR on both x86_64-linux-gnu and mipsisa64-elf.

Thanks,
Andrew Pinski

ChangeLog:
* gimple-fold.c (get_maxval_strlen): Move COND_EXPR handling under
GIMPLE_ASSIGN.

Comments

Jakub Jelinek May 16, 2012, 8:17 p.m. UTC | #1
On Wed, May 16, 2012 at 12:34:18PM -0700, Andrew Pinski wrote:
> When COND_EXPR was changed from GIMPLE_SINGLE_RHS to
> GIMPLE_TERNARY_RHS, get_maxval_strlen was not updated for that
> changed.  With a patch which has a late PHIOPT produce COND_EXPR, I
> saw a couple of regressions (pr23484-chk.c and  strncpy-chk.c).
> 
> This patch fixes get_maxval_strlen for that change.
> 
> OK for the trunk and 4.7 branch?  Bootstrapped and tested on
> x86_64-linux-gnu with no regressions.  And in 4.7.0 with the patch for
> PHIOPT producing COND_EXPR on both x86_64-linux-gnu and mipsisa64-elf.

Ok for both, but please fix up whitespace (on all lines you've changed
replace 8 spaces with tab, you use tabs in some lines and spaces in other
lines).

> ChangeLog:
> * gimple-fold.c (get_maxval_strlen): Move COND_EXPR handling under
> GIMPLE_ASSIGN.

	Jakub
diff mbox

Patch

Index: gimple-fold.c
===================================================================
--- gimple-fold.c	(revision 187579)
+++ gimple-fold.c	(working copy)
@@ -670,13 +670,10 @@  get_maxval_strlen (tree arg, tree *lengt
 
   if (TREE_CODE (arg) != SSA_NAME)
     {
-      if (TREE_CODE (arg) == COND_EXPR)
-        return get_maxval_strlen (COND_EXPR_THEN (arg), length, visited, type)
-               && get_maxval_strlen (COND_EXPR_ELSE (arg), length, visited, type);
       /* We can end up with &(*iftmp_1)[0] here as well, so handle it.  */
-      else if (TREE_CODE (arg) == ADDR_EXPR
-	       && TREE_CODE (TREE_OPERAND (arg, 0)) == ARRAY_REF
-	       && integer_zerop (TREE_OPERAND (TREE_OPERAND (arg, 0), 1)))
+      if (TREE_CODE (arg) == ADDR_EXPR
+	  && TREE_CODE (TREE_OPERAND (arg, 0)) == ARRAY_REF
+	  && integer_zerop (TREE_OPERAND (TREE_OPERAND (arg, 0), 1)))
 	{
 	  tree aop0 = TREE_OPERAND (TREE_OPERAND (arg, 0), 0);
 	  if (TREE_CODE (aop0) == INDIRECT_REF
@@ -736,6 +733,13 @@  get_maxval_strlen (tree arg, tree *lengt
             tree rhs = gimple_assign_rhs1 (def_stmt);
             return get_maxval_strlen (rhs, length, visited, type);
           }
+        else if (gimple_assign_rhs_code (def_stmt) == COND_EXPR)
+          {
+	    tree op2 = gimple_assign_rhs2 (def_stmt);
+	    tree op3 = gimple_assign_rhs3 (def_stmt);
+            return get_maxval_strlen (op2, length, visited, type)
+                   && get_maxval_strlen (op3, length, visited, type);
+          }
         return false;
 
       case GIMPLE_PHI: