From ce04dcdc8498b5429c2da2338a8912ff3914d19f Mon Sep 17 00:00:00 2001 From: sayle Date: Mon, 21 Mar 2005 03:30:08 +0000 Subject: PR middle-end/20539 * fold-const.c (fold_binary): Fix type mismatch between TRUTH_{AND,OR,XOR}_EXPR nodes an their operands' types. (fold_binary) : Avoid calling invert_truthvalue for non-truth-valued expressions. * c-common.c (c_common_truthvalue_conversion): Handle ERROR_MARK and FUNCTION_DECL in the main switch. : When changing the result type of these tree nodes, we also need to convert their operands to match. : Likewise. * gcc.c-torture/compile/pr13066-1.c: New test case. * gcc.c-torture/compile/pr20539-1.c: Likewise. * g++.dg/opt/pr13066-1.C: Likewise. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@96777 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/c-common.c | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) (limited to 'gcc/c-common.c') diff --git a/gcc/c-common.c b/gcc/c-common.c index 9c6a9d141af..a18520d9e0d 100644 --- a/gcc/c-common.c +++ b/gcc/c-common.c @@ -2327,33 +2327,33 @@ pointer_int_sum (enum tree_code resultcode, tree ptrop, tree intop) tree c_common_truthvalue_conversion (tree expr) { - if (TREE_CODE (expr) == ERROR_MARK) - return expr; - - if (TREE_CODE (expr) == FUNCTION_DECL) - expr = build_unary_op (ADDR_EXPR, expr, 0); - switch (TREE_CODE (expr)) { case EQ_EXPR: case NE_EXPR: case UNEQ_EXPR: case LTGT_EXPR: case LE_EXPR: case GE_EXPR: case LT_EXPR: case GT_EXPR: case UNLE_EXPR: case UNGE_EXPR: case UNLT_EXPR: case UNGT_EXPR: case ORDERED_EXPR: case UNORDERED_EXPR: + if (TREE_TYPE (expr) == truthvalue_type_node) + return expr; + return build2 (TREE_CODE (expr), truthvalue_type_node, + TREE_OPERAND (expr, 0), TREE_OPERAND (expr, 1)); + case TRUTH_ANDIF_EXPR: case TRUTH_ORIF_EXPR: case TRUTH_AND_EXPR: case TRUTH_OR_EXPR: case TRUTH_XOR_EXPR: - if (TREE_TYPE (expr) != truthvalue_type_node) - return build2 (TREE_CODE (expr), truthvalue_type_node, - TREE_OPERAND (expr, 0), TREE_OPERAND (expr, 1)); - return expr; + if (TREE_TYPE (expr) == truthvalue_type_node) + return expr; + return build2 (TREE_CODE (expr), truthvalue_type_node, + lang_hooks.truthvalue_conversion (TREE_OPERAND (expr, 0)), + lang_hooks.truthvalue_conversion (TREE_OPERAND (expr, 1))); case TRUTH_NOT_EXPR: - if (TREE_TYPE (expr) != truthvalue_type_node) - return build1 (TREE_CODE (expr), truthvalue_type_node, - TREE_OPERAND (expr, 0)); - return expr; + if (TREE_TYPE (expr) == truthvalue_type_node) + return expr; + return build1 (TREE_CODE (expr), truthvalue_type_node, + lang_hooks.truthvalue_conversion (TREE_OPERAND (expr, 0))); case ERROR_MARK: return expr; @@ -2369,6 +2369,10 @@ c_common_truthvalue_conversion (tree expr) ? truthvalue_true_node : truthvalue_false_node; + case FUNCTION_DECL: + expr = build_unary_op (ADDR_EXPR, expr, 0); + /* Fall through. */ + case ADDR_EXPR: { if (TREE_CODE (TREE_OPERAND (expr, 0)) == FUNCTION_DECL -- cgit v1.2.1