As mentioned in the PR, C FE leaked C_MAYBE_CONST_EXPR into GIMPLE. This happened because remove_c_maybe_const_expr doesn't look for nested C_MAYBE_CONST_EXPRs. But c_fully_fold will fold these away, so use that.
Regtested/bootstrapped on x86_64-linux, ok for trunk and 4.8? Alternatively, we could in if (int_operands) look at op1/op2, and call c_fully_fold only if C_MAYBE_CONST_EXPR isn't the top level expression. 2014-01-22 Marek Polacek <pola...@redhat.com> PR c/59891 c/ * c-typeck.c (build_conditional_expr): Call c_fully_fold instead of remove_c_maybe_const_expr on op1 and op2. testsuite/ * gcc.dg/torture/pr59891.c: New test. --- gcc/c/c-typeck.c.mp3 2014-01-22 18:47:36.812358319 +0100 +++ gcc/c/c-typeck.c 2014-01-22 18:45:10.298692933 +0100 @@ -4708,8 +4708,10 @@ build_conditional_expr (location_t colon { 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) --- gcc/testsuite/gcc.dg/torture/pr59891.c.mp3 2014-01-22 19:16:34.000000000 +0100 +++ gcc/testsuite/gcc.dg/torture/pr59891.c 2014-01-22 19:19:23.996129684 +0100 @@ -0,0 +1,9 @@ +/* PR c/59891 */ + +unsigned int a; + +int +main () +{ + return (0 ? a : 0) ? : 0 % 0; /* { dg-warning "division by zero" } */ +} Marek