aboutsummaryrefslogtreecommitdiff
path: root/gcc/fold-const.c
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/fold-const.c')
-rw-r--r--gcc/fold-const.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index bc17c1d..848b167 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -7159,13 +7159,14 @@ fold_binary (enum tree_code code, tree type, tree op0, tree op1)
tem = fold (build2 (code == BIT_AND_EXPR ? TRUTH_AND_EXPR
: code == BIT_IOR_EXPR ? TRUTH_OR_EXPR
: TRUTH_XOR_EXPR,
- type, fold_convert (boolean_type_node, arg0),
+ boolean_type_node,
+ fold_convert (boolean_type_node, arg0),
fold_convert (boolean_type_node, arg1)));
if (code == EQ_EXPR)
tem = invert_truthvalue (tem);
- return tem;
+ return fold_convert (type, tem);
}
if (TREE_CODE_CLASS (code) == tcc_comparison
@@ -8717,7 +8718,14 @@ fold_binary (enum tree_code code, tree type, tree op0, tree op1)
return non_lvalue (fold_convert (type, arg0));
/* If the second arg is constant true, this is a logical inversion. */
if (integer_onep (arg1))
- return non_lvalue (fold_convert (type, invert_truthvalue (arg0)));
+ {
+ /* Only call invert_truthvalue if operand is a truth value. */
+ if (TREE_CODE (TREE_TYPE (arg0)) != BOOLEAN_TYPE)
+ tem = fold (build1 (TRUTH_NOT_EXPR, TREE_TYPE (arg0), arg0));
+ else
+ tem = invert_truthvalue (arg0);
+ return non_lvalue (fold_convert (type, tem));
+ }
/* Identical arguments cancel to zero. */
if (operand_equal_p (arg0, arg1, 0))
return omit_one_operand (type, integer_zero_node, arg0);