This is the mail archive of the
mailing list for the GCC project.
Re: [4.1 PATCH] Avoid endless recursion between negate_expr and fold_unary (PR middle-end/30286)
- From: "Richard Guenther" <richard dot guenther at gmail dot com>
- To: "Jakub Jelinek" <jakub at redhat dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Fri, 29 Dec 2006 19:59:13 +0100
- Subject: Re: [4.1 PATCH] Avoid endless recursion between negate_expr and fold_unary (PR middle-end/30286)
- References: <20061229184415.GG29911@devserv.devel.redhat.com>
On 12/29/06, Jakub Jelinek <firstname.lastname@example.org> wrote:
This testcase was fixed in 4.2+ with the PR27116 patch.
So, either we want to backport that and patches that it depends on,
or the following should fix this case as well.
If negate_expr doesn't optimize negation of an INTEGER_CST or REAL_CST,
it falls back to the default fold_build1 (NEGATE_EXPR, TREE_TYPE (t), t),
which in turn calls fold_unary. As t here is known to be INTEGER_CST
or REAL_CST, all that it does is:
if (negate_expr_p (arg0))
return fold_convert (type, negate_expr (arg0));
/* Convert - (~A) to A + 1. */
if (INTEGRAL_TYPE_P (type) && TREE_CODE (arg0) == BIT_NOT_EXPR)
return fold_build2 (PLUS_EXPR, type, TREE_OPERAND (arg0, 0),
build_int_cst (type, 1));
so either recurses again with the same argument, or returns NULL
(because arg0 is certainly not BIT_NOT_EXPR). Just calling
build1 instead of fold_build1 will make the endless recursion impossible,
while won't change behavior in the rest of cases.
2006-12-29 Jakub Jelinek <email@example.com>
* fold-const.c (negate_expr): Don't call fold_build1
for INTEGER_CST or REAL_CST.
* gcc.dg/pr30286.c: New test.
This is ok. Can you also add the testcase to the 4.2 branch and trunk?