diff options
author | Jason Merrill <jason@redhat.com> | 2016-10-08 13:40:22 -0400 |
---|---|---|
committer | Jason Merrill <jason@gcc.gnu.org> | 2016-10-08 13:40:22 -0400 |
commit | 627be19fe1b259a18a33f0f90f2aee63fee13384 (patch) | |
tree | 243c02c542d5ba8e9536eb8932e83a95ef4af526 /gcc | |
parent | 490a67336b3c5608d76439c536bde3809db6c958 (diff) | |
download | gcc-627be19fe1b259a18a33f0f90f2aee63fee13384.zip gcc-627be19fe1b259a18a33f0f90f2aee63fee13384.tar.gz gcc-627be19fe1b259a18a33f0f90f2aee63fee13384.tar.bz2 |
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
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/c-family/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/c-family/c-common.c | 17 | ||||
-rw-r--r-- | gcc/cp/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/cp/cp-gimplify.c | 9 |
4 files changed, 21 insertions, 15 deletions
diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index 9f6b16d..21985c7 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,3 +1,8 @@ +2016-10-08 Jason Merrill <jason@redhat.com> + + * c-common.c (c_common_truthvalue_conversion): Don't distribute + into COND_EXPR in C++. + 2016-10-08 Jakub Jelinek <jakub@redhat.com> * c-lex.c (c_lex_with_flags) <case CPP_COMMENT>: For CPP_COMMENT diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c index f7a5d620..dbdb276 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 0bd0457..32b011f 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2016-10-08 Jason Merrill <jason@redhat.com> + + * cp-gimplify.c (cp_fold): Distribute cp_truthvalue_conversion + into COND_EXPR. + 2016-10-07 Jason Merrill <jason@redhat.com> Further P0135 refinement. diff --git a/gcc/cp/cp-gimplify.c b/gcc/cp/cp-gimplify.c index 5aca8f2..4879632 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)) |