From 062ab321b9dc7cdfe7e8cd096d584ff01b0a7d5c Mon Sep 17 00:00:00 2001 From: Eric Botcazou Date: Wed, 7 Nov 2012 22:37:01 +0000 Subject: [PATCH] re PR middle-end/55219 (memory explosion on nested conditional expressions) PR middle-end/55219 * fold-const.c (fold_binary_op_with_conditional_arg): Do not fold if the argument is itself a conditional expression. From-SVN: r193315 --- gcc/ChangeLog | 6 ++++++ gcc/fold-const.c | 5 +++-- gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/gcc.c-torture/compile/20121107-1.c | 14 ++++++++++++++ 4 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.c-torture/compile/20121107-1.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 12f22438fab1..f772e92a3deb 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2012-11-07 Eric Botcazou + + PR middle-end/55219 + * fold-const.c (fold_binary_op_with_conditional_arg): Do not fold if + the argument is itself a conditional expression. + 2012-10-30 Andrey Belevantsev Backport from mainline diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 5b4fc1fed45b..f11ddf14b75f 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -6003,10 +6003,11 @@ fold_binary_op_with_conditional_arg (location_t loc, } /* This transformation is only worthwhile if we don't have to wrap ARG - in a SAVE_EXPR and the operation can be simplified on at least one - of the branches once its pushed inside the COND_EXPR. */ + in a SAVE_EXPR and the operation can be simplified without recursing + on at least one of the branches once its pushed inside the COND_EXPR. */ if (!TREE_CONSTANT (arg) && (TREE_SIDE_EFFECTS (arg) + || TREE_CODE (arg) == COND_EXPR || TREE_CODE (arg) == VEC_COND_EXPR || TREE_CONSTANT (true_value) || TREE_CONSTANT (false_value))) return NULL_TREE; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index bc1b206f4731..1637989fe2b2 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2012-11-07 Eric Botcazou + + * gcc.c-torture/compile/20121107-1.c: New test. + 2012-10-30 Andrey Belevantsev Backport from mainline diff --git a/gcc/testsuite/gcc.c-torture/compile/20121107-1.c b/gcc/testsuite/gcc.c-torture/compile/20121107-1.c new file mode 100644 index 000000000000..a86206702afb --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/compile/20121107-1.c @@ -0,0 +1,14 @@ +/* PR middle-end/55219 */ +/* Testcase by Markus Trippelsdorf */ + +int x, c, d, e, f, g, h, i; +double j; +const int k; +const enum { B } a; +void +fn1 (void) +{ + h = (g ? c : g ? f : g ? e : g ? i : g ? f : g ? e : g ? d : x) + + (a ? : a ? : a ? : a ? : a ? : a ? : a ? : a ? : a ? : a ? : a + ? j : a ? : 0 ? : a ? : a ? : a ? : a ? : a ? : a ? k : a ? : x); +} -- 2.47.2