diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index 4754bdf2b99..3ec4fe7de16 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,3 +1,9 @@ +2014-01-22 Marek Polacek + + PR c/59891 + * c-typeck.c (build_conditional_expr): Call c_fully_fold instead + of remove_c_maybe_const_expr on op1 and op2. + 2014-01-15 Jakub Jelinek PR c/58943 diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c index 09049e2a3ca..7cb717a9749 100644 --- a/gcc/c/c-typeck.c +++ b/gcc/c/c-typeck.c @@ -4708,8 +4708,10 @@ build_conditional_expr (location_t colon_loc, tree ifexp, bool ifexp_bcp, { if (int_operands) { - op1 = remove_c_maybe_const_expr (op1); - op2 = remove_c_maybe_const_expr (op2); + /* Use c_fully_fold here, since C_MAYBE_CONST_EXPR might be + nested inside of the expression. */ + op1 = c_fully_fold (op1, false, NULL); + op2 = c_fully_fold (op2, false, NULL); } ret = build3 (COND_EXPR, result_type, ifexp, op1, op2); if (int_operands) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 6f26f7fe744..4cc8d9f8984 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2014-01-22 Marek Polacek + + PR c/59891 + * gcc.dg/torture/pr59891.c: New test. + 2014-01-22 Jeff Law PR tree-optimization/59597 diff --git a/gcc/testsuite/gcc.dg/torture/pr59891.c b/gcc/testsuite/gcc.dg/torture/pr59891.c new file mode 100644 index 00000000000..1562acccf68 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr59891.c @@ -0,0 +1,9 @@ +/* PR c/59891 */ + +unsigned int a; + +int +main () +{ + return (0 ? a : 0) ? : 0 % 0; /* { dg-warning "division by zero" } */ +}