This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Fix PR28935, infinite loop folding due to fold_stmt deficiency
- From: Andrew Pinski <pinskia at physics dot uc dot edu>
- To: Richard Guenther <rguenther at suse dot de>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Sat, 02 Sep 2006 14:07:52 -0700
- Subject: Re: [PATCH] Fix PR28935, infinite loop folding due to fold_stmt deficiency
- References: <Pine.LNX.4.64.0609022256500.4322@nyjnma.fhfr.qr>
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