summaryrefslogtreecommitdiff
path: root/gcc/c-common.c
diff options
context:
space:
mode:
authorsayle <sayle@138bc75d-0d04-0410-961f-82ee72b054a4>2005-03-21 03:30:08 +0000
committersayle <sayle@138bc75d-0d04-0410-961f-82ee72b054a4>2005-03-21 03:30:08 +0000
commitce04dcdc8498b5429c2da2338a8912ff3914d19f (patch)
tree64a437ac2c7bf9dae4641ceb3ef591d6abc0a7e6 /gcc/c-common.c
parente35976b114cde73f3131da32a9bbbc6da1b13eb8 (diff)
downloadgcc-ce04dcdc8498b5429c2da2338a8912ff3914d19f.tar.gz
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) <TRUTH_XOR_EXPR>: 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. <TRUTH_ANDIF_EXPR, TRUTH_ORIF_EXPR, TRUTH_AND_EXPR, TRUTH_OR_EXPR, TRUTH_XOR_EXPR>: When changing the result type of these tree nodes, we also need to convert their operands to match. <TRUTH_NOT_EXPR>: 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
Diffstat (limited to 'gcc/c-common.c')
-rw-r--r--gcc/c-common.c32
1 files changed, 18 insertions, 14 deletions
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