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]

Re: [PATCH] Fix PR28935, infinite loop folding due to fold_stmt deficiency


On Sat, 2006-09-02 at 22:59 +0200, Richard Guenther wrote:
> We end up calling fold on 0 != 0 ? 1 : 0 from VRP through the propagator 
> engine.  fold_stmt fails to recursively fold 0 != 0, so the unfolded 
> expression is passed to fold which is a bug as fold expects subexpressions
> that are properly folded.
> 
> Fixed by teaching fold_stmt_r how to fold the condition of a COND_EXPR.
> 
> Bootstrapped and tested on x86_64-unknown-linux-gnu.
> 
> Ok for mainline?
> +     case COND_EXPR:
> +       if (COMPARISON_CLASS_P (TREE_OPERAND (expr, 0)))
> +         {
> + 	  tree op0 = TREE_OPERAND (expr, 0);
> +           tree tem = fold_binary (TREE_CODE (op0), TREE_TYPE (op0),
> + 				  TREE_OPERAND (op0, 0), TREE_OPERAND (op0, 1));
> + 	  if (tem && is_gimple_condexpr (tem))
> + 	    TREE_OPERAND (expr, 0) = tem;
> + 	  t = expr;
> +           break;


Why are you using fold_binary here, you already have the tree created?
Also if you are going to use fold_binary, you really should be using
fold_binary_to_constant instead as there is nothing simpler that is
valid gimple than what is a COND_EXPR than either what is currently
there or a constant and then you can remove this is_gimple_condexpr
stuff.

-- Pinski 



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