===================================================================
@@ -3220,6 +3220,31 @@ verify_gimple_comparison (tree type, tre
return false;
}
+/* Checks TYPE for being compatible to boolean. Returns
+ FALSE, if type is not compatible, otherwise TRUE.
+
+ A type is compatible if
+ a) TYPE_PRECISION is one.
+ b) The type - or the inner type - is of kind BOOLEAN_TYPE. */
+
+static bool
+compatible_boolean_type_p (tree type)
+{
+ if (!type)
+ return false;
+ if (TYPE_PRECISION (type) == 1)
+ return true;
+
+ /* We try to look here into inner type, as ADA uses
+ boolean_type_node with type precision != 1. */
+ while (TREE_TYPE (type)
+ && (TREE_CODE (type) == INTEGER_TYPE
+ || TREE_CODE (type) == REAL_TYPE))
+ type = TREE_TYPE (type);
+
+ return TYPE_PRECISION (type) == 1 || TREE_CODE (type) == BOOLEAN_TYPE;
+}
+
/* Verify a gimple assignment statement STMT with an unary rhs.
Returns true if anything is wrong. */
@@ -3350,15 +3375,16 @@ verify_gimple_assign_unary (gimple stmt)
return false;
case TRUTH_NOT_EXPR:
- if (!useless_type_conversion_p (boolean_type_node, rhs1_type))
+
+ if (!useless_type_conversion_p (lhs_type, rhs1_type)
+ || !compatible_boolean_type_p (lhs_type))
{
- error ("invalid types in truth not");
- debug_generic_expr (lhs_type);
- debug_generic_expr (rhs1_type);
- return true;
+ error ("invalid types in truth not");
+ debug_generic_expr (lhs_type);
+ debug_generic_expr (rhs1_type);
+ return true;
}
break;
-
case NEGATE_EXPR:
case ABS_EXPR:
case BIT_NOT_EXPR:
@@ -3558,10 +3584,11 @@ do_pointer_plus_expr_check:
case TRUTH_OR_EXPR:
case TRUTH_XOR_EXPR:
{
- /* We allow only boolean typed or compatible argument and result. */
- if (!useless_type_conversion_p (boolean_type_node, rhs1_type)
- || !useless_type_conversion_p (boolean_type_node, rhs2_type)
- || !useless_type_conversion_p (boolean_type_node, lhs_type))
+ /* We allow only boolean_typed or types with precision of one,
+ or compatible argument and result. */
+ if (!useless_type_conversion_p (lhs_type, rhs1_type)
+ || !useless_type_conversion_p (lhs_type, rhs2_type)
+ || !compatible_boolean_type_p (lhs_type))
{
error ("type mismatch in binary truth expression");
debug_generic_expr (lhs_type);