Commit Message

Bug 54103 is a C front-end regression involving ICEs in certain cases
of expressions such as 0 / 0 being converted to truthvalues.
c_common_truthvalue_conversion, or
c_objc_common_truthvalue_conversion, received 0 / 0 directly as a
TRUNC_DIV_EXPR, without any wrapping C_MAYBE_CONST_EXPR to indicate
that the expression has integer constant operands, so did not know
that it had to produce a result valid for an expression with integer
constant operands (that is, one satisfying EXPR_INT_CONST_OPERANDS -
meaning either an INTEGER_CST, or a C_MAYBE_CONST_EXPR with
C_MAYBE_CONST_EXPR_INT_OPERANDS set, but not anything with
C_MAYBE_CONST_EXPR deeper in the expression). As a result it returned
an expression with a C_MAYBE_CONST_EXPR not at top level - but the
callers assumed this could not occur, so created their own wrapping
C_MAYBE_CONST_EXPR (and C_MAYBE_CONST_EXPR should never be nested).
This is fixed by ensuring that a properly marked expression gets
passed to c_objc_common_truthvalue_conversion; ensuring
c_objc_common_truthvalue_conversion handes such expressions directly
so c_common_truthvalue_conversion doesn't have to; and avoiding direct
calls to c_common_truthvalue_conversion in relevant places.
Bootstrapped with no regressions on x86_64-unknown-linux-gnu. Applied
to mainline. Will apply to 4.7 (when not frozen) and 4.6 branches
subject to testing there.
c:
2012-09-14 Joseph Myers <joseph@codesourcery.com>
PR c/54103
* c-typeck.c (build_unary_op): Pass original argument of
TRUTH_NOT_EXPR to c_objc_common_truthvalue_conversion, then remove
any C_MAYBE_CONST_EXPR, if it has integer operands.
(build_binary_op): Pass original arguments of TRUTH_ANDIF_EXPR,
TRUTH_ORIF_EXPR, TRUTH_AND_EXPR, TRUTH_OR_EXPR and TRUTH_XOR_EXPR
to c_objc_common_truthvalue_conversion, then remove any
C_MAYBE_CONST_EXPR, if they have integer operands. Use
c_objc_common_truthvalue_conversion not
c_common_truthvalue_conversion.
(c_objc_common_truthvalue_conversion): Build NE_EXPR directly and
call note_integer_operands for arguments with integer operands
that are not integer constants.
testsuite:
2012-09-14 Joseph Myers <joseph@codesourcery.com>
PR c/54103
* gcc.c-torture/compile/pr54103-1.c,
gcc.c-torture/compile/pr54103-2.c,
gcc.c-torture/compile/pr54103-3.c,
gcc.c-torture/compile/pr54103-4.c,
gcc.c-torture/compile/pr54103-5.c,
gcc.c-torture/compile/pr54103-6.c: New tests.
* gcc.dg/c90-const-expr-8.c: Update expected column number.