diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 6ad8a8a6ad5..6b38199aa55 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2008-10-10 Jakub Jelinek + + PR c++/37146 + * cp-gimplify.c (cp_genericize_r): Fix up bitfield operands of + COND_EXPR. + 2008-10-09 Jakub Jelinek PR c++/37568 diff --git a/gcc/cp/cp-gimplify.c b/gcc/cp/cp-gimplify.c index a1542b9f804..1641be5ebdc 100644 --- a/gcc/cp/cp-gimplify.c +++ b/gcc/cp/cp-gimplify.c @@ -803,6 +803,34 @@ cp_genericize_r (tree *stmt_p, int *walk_subtrees, void *data) CLEANUP_BODY (stmt), CLEANUP_EXPR (stmt)); + /* COND_EXPR might have incompatible types in branches if one or both + arms are bitfields. Fix it up now. */ + else if (TREE_CODE (stmt) == COND_EXPR) + { + tree type_left + = (TREE_OPERAND (stmt, 1) + ? is_bitfield_expr_with_lowered_type (TREE_OPERAND (stmt, 1)) + : NULL_TREE); + tree type_right + = (TREE_OPERAND (stmt, 2) + ? is_bitfield_expr_with_lowered_type (TREE_OPERAND (stmt, 2)) + : NULL_TREE); + if (type_left) + { + TREE_OPERAND (stmt, 1) + = fold_convert (type_left, TREE_OPERAND (stmt, 1)); + gcc_assert (useless_type_conversion_p (TREE_TYPE (stmt), + type_left)); + } + if (type_right) + { + TREE_OPERAND (stmt, 2) + = fold_convert (type_right, TREE_OPERAND (stmt, 2)); + gcc_assert (useless_type_conversion_p (TREE_TYPE (stmt), + type_right)); + } + } + pointer_set_insert (p_set, *stmt_p); return NULL; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 4232c498102..92a0f4102fb 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,10 @@ +2008-10-10 Jakub Jelinek + + PR c++/37146 + * g++.dg/torture/pr37146-1.C: New test. + * g++.dg/torture/pr37146-2.C: New test. + * g++.dg/expr/bitfield10.C: New test. + 2008-10-08 Jerry DeLisle