From: Jason Merrill Date: Sat, 8 Oct 2016 17:40:22 +0000 (-0400) Subject: Delay folding of bool conversion into COND_EXPR. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=627be19fe1b259a18a33f0f90f2aee63fee13384;p=gcc.git Delay folding of bool conversion into COND_EXPR. gcc/c-family/ * c-common.c (c_common_truthvalue_conversion): Don't distribute into COND_EXPR in C++. gcc/cp/ * cp-gimplify.c (cp_fold): Distribute cp_truthvalue_conversion into COND_EXPR. From-SVN: r240893 --- diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index 9f6b16d7306..21985c796fb 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,3 +1,8 @@ +2016-10-08 Jason Merrill + + * c-common.c (c_common_truthvalue_conversion): Don't distribute + into COND_EXPR in C++. + 2016-10-08 Jakub Jelinek * c-lex.c (c_lex_with_flags) : For CPP_COMMENT diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c index f7a5d62012b..dbdb276f953 100644 --- a/gcc/c-family/c-common.c +++ b/gcc/c-family/c-common.c @@ -4694,21 +4694,8 @@ c_common_truthvalue_conversion (location_t location, tree expr) } /* Distribute the conversion into the arms of a COND_EXPR. */ if (c_dialect_cxx ()) - { - tree op1 = TREE_OPERAND (expr, 1); - tree op2 = TREE_OPERAND (expr, 2); - int w = warn_int_in_bool_context; - warn_int_in_bool_context = 0; - /* In C++ one of the arms might have void type if it is throw. */ - if (!VOID_TYPE_P (TREE_TYPE (op1))) - op1 = c_common_truthvalue_conversion (location, op1); - if (!VOID_TYPE_P (TREE_TYPE (op2))) - op2 = c_common_truthvalue_conversion (location, op2); - expr = fold_build3_loc (location, COND_EXPR, truthvalue_type_node, - TREE_OPERAND (expr, 0), op1, op2); - warn_int_in_bool_context = w; - goto ret; - } + /* Avoid premature folding. */ + break; else { int w = warn_int_in_bool_context; diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 0bd0457f01a..32b011f3462 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2016-10-08 Jason Merrill + + * cp-gimplify.c (cp_fold): Distribute cp_truthvalue_conversion + into COND_EXPR. + 2016-10-07 Jason Merrill Further P0135 refinement. diff --git a/gcc/cp/cp-gimplify.c b/gcc/cp/cp-gimplify.c index 5aca8f2a3b0..48796323523 100644 --- a/gcc/cp/cp-gimplify.c +++ b/gcc/cp/cp-gimplify.c @@ -2253,6 +2253,15 @@ cp_fold (tree x) op1 = cp_fold (TREE_OPERAND (x, 1)); op2 = cp_fold (TREE_OPERAND (x, 2)); + if (TREE_CODE (TREE_TYPE (x)) == BOOLEAN_TYPE) + { + warning_sentinel (warn_int_in_bool_context); + if (!VOID_TYPE_P (TREE_TYPE (op1))) + op1 = cp_truthvalue_conversion (op1); + if (!VOID_TYPE_P (TREE_TYPE (op2))) + op2 = cp_truthvalue_conversion (op2); + } + if (op0 != TREE_OPERAND (x, 0) || op1 != TREE_OPERAND (x, 1) || op2 != TREE_OPERAND (x, 2))