From 853ce7c073eedfba1adfb63530a8bd2baa767137 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Sat, 12 Oct 2019 14:21:45 +0200 Subject: [PATCH] re PR middle-end/92063 (ICE in operation_could_trap_p, at tree-eh.c:2528 when compiling Python's Python/_warnings.c) PR middle-end/92063 * tree-eh.c (operation_could_trap_helper_p) : Return false with *handled = false. (tree_could_trap_p): For {,VEC_}COND_EXPR return false instead of recursing on the first operand. * fold-const.c (simple_operand_p_2): Use generic_expr_could_trap_p instead of tree_could_trap_p. * tree-ssa-sccvn.c (vn_nary_may_trap): Formatting fixes. * gcc.c-torture/compile/pr92063.c: New test. From-SVN: r276915 --- gcc/ChangeLog | 11 +++++++++++ gcc/fold-const.c | 3 +-- gcc/testsuite/ChangeLog | 3 +++ gcc/testsuite/gcc.c-torture/compile/pr92063.c | 7 +++++++ gcc/tree-eh.c | 15 +++++++++++++-- gcc/tree-ssa-sccvn.c | 11 ++++------- 6 files changed, 39 insertions(+), 11 deletions(-) create mode 100644 gcc/testsuite/gcc.c-torture/compile/pr92063.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 12613f7f639..800b8cef524 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,14 @@ +2019-10-12 Jakub Jelinek + + PR middle-end/92063 + * tree-eh.c (operation_could_trap_helper_p) + : Return false with *handled = false. + (tree_could_trap_p): For {,VEC_}COND_EXPR return false instead of + recursing on the first operand. + * fold-const.c (simple_operand_p_2): Use generic_expr_could_trap_p + instead of tree_could_trap_p. + * tree-ssa-sccvn.c (vn_nary_may_trap): Formatting fixes. + 2019-10-11 Jim Wilson PR rtl-optimization/91860 diff --git a/gcc/fold-const.c b/gcc/fold-const.c index a99dafec589..58b967e48fe 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -4447,8 +4447,7 @@ simple_operand_p_2 (tree exp) { enum tree_code code; - if (TREE_SIDE_EFFECTS (exp) - || tree_could_trap_p (exp)) + if (TREE_SIDE_EFFECTS (exp) || generic_expr_could_trap_p (exp)) return false; while (CONVERT_EXPR_P (exp)) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 14b5da645ec..2f46d4dd857 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,8 @@ 2019-10-12 Jakub Jelinek + PR middle-end/92063 + * gcc.c-torture/compile/pr92063.c: New test. + * c-c++-common/gomp/declare-variant-2.c: Adjust for error recovery improvements. Add new tests. * c-c++-common/gomp/declare-variant-4.c: New test. diff --git a/gcc/testsuite/gcc.c-torture/compile/pr92063.c b/gcc/testsuite/gcc.c-torture/compile/pr92063.c new file mode 100644 index 00000000000..bb704abe0ef --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/compile/pr92063.c @@ -0,0 +1,7 @@ +/* PR middle-end/92063 */ + +int +foo (int a, int b, int *c, short *d) +{ + return (c[0] ? b : 0) == 'y' && ((a ? d[0] : c[0]) ? b : 0) == 'c'; +} diff --git a/gcc/tree-eh.c b/gcc/tree-eh.c index 7a028735d4e..54502e6f93c 100644 --- a/gcc/tree-eh.c +++ b/gcc/tree-eh.c @@ -2499,6 +2499,14 @@ operation_could_trap_helper_p (enum tree_code op, /* Constructing an object cannot trap. */ return false; + case COND_EXPR: + case VEC_COND_EXPR: + /* Whether *COND_EXPR can trap depends on whether the + first argument can trap, so signal it as not handled. + Whether lhs is floating or not doesn't matter. */ + *handled = false; + return false; + default: /* Any floating arithmetic may trap. */ if (fp_operation && flag_trapping_math) @@ -2614,9 +2622,12 @@ tree_could_trap_p (tree expr) if (!expr) return false; - /* For COND_EXPR and VEC_COND_EXPR only the condition may trap. */ + /* In COND_EXPR and VEC_COND_EXPR only the condition may trap, but + they won't appear as operands in GIMPLE form, so this is just for the + GENERIC uses where it needs to recurse on the operands and so + *COND_EXPR itself doesn't trap. */ if (TREE_CODE (expr) == COND_EXPR || TREE_CODE (expr) == VEC_COND_EXPR) - expr = TREE_OPERAND (expr, 0); + return false; code = TREE_CODE (expr); t = TREE_TYPE (expr); diff --git a/gcc/tree-ssa-sccvn.c b/gcc/tree-ssa-sccvn.c index 364d0d0ca4f..57331ab44dc 100644 --- a/gcc/tree-ssa-sccvn.c +++ b/gcc/tree-ssa-sccvn.c @@ -5105,18 +5105,15 @@ vn_nary_may_trap (vn_nary_op_t nary) honor_nans = flag_trapping_math && !flag_finite_math_only; honor_snans = flag_signaling_nans != 0; } - else if (INTEGRAL_TYPE_P (type) - && TYPE_OVERFLOW_TRAPS (type)) + else if (INTEGRAL_TYPE_P (type) && TYPE_OVERFLOW_TRAPS (type)) honor_trapv = true; } if (nary->length >= 2) rhs2 = nary->op[1]; ret = operation_could_trap_helper_p (nary->opcode, fp_operation, - honor_trapv, - honor_nans, honor_snans, rhs2, - &handled); - if (handled - && ret) + honor_trapv, honor_nans, honor_snans, + rhs2, &handled); + if (handled && ret) return true; for (i = 0; i < nary->length; ++i) -- 2.30.2