The point is to avoid building comparisons of the form "D == true" in this
case for the qualifiers of the union describing the variant part because 1)
it's useless and 2) it's output as "D = 1" by -gnatR, which is not valid Ada.
The dwarf2out.c change only affects the Ada compiler.
Tested on x86_64-suse-linux, applied on the mainline as obvious.
2018-12-14 Eric Botcazou <ebotca...@adacore.com>
* dwarf2out.c (analyze_discr_in_predicate): Simplify.
(analyze_variants_discr): Deal with naked boolean discriminants.
ada/
* gcc-interface/decl.c (choices_to_gnu): Directly use a naked boolean
discriminant if the value is the boolean true.
--
Eric Botcazou
Index: dwarf2out.c
===================================================================
--- dwarf2out.c (revision 267062)
+++ dwarf2out.c (working copy)
@@ -24537,6 +24537,7 @@ gen_inheritance_die (tree binfo, tree ac
/* Return whether DECL is a FIELD_DECL that represents the variant part of a
structure. */
+
static bool
is_variant_part (tree decl)
{
@@ -24550,17 +24551,8 @@ is_variant_part (tree decl)
static tree
analyze_discr_in_predicate (tree operand, tree struct_type)
{
- bool continue_stripping = true;
- while (continue_stripping)
- switch (TREE_CODE (operand))
- {
- CASE_CONVERT:
- operand = TREE_OPERAND (operand, 0);
- break;
- default:
- continue_stripping = false;
- break;
- }
+ while (CONVERT_EXPR_P (operand))
+ operand = TREE_OPERAND (operand, 0);
/* Match field access to members of struct_type only. */
if (TREE_CODE (operand) == COMPONENT_REF
@@ -24780,6 +24772,19 @@ analyze_variants_discr (tree variant_par
new_node->dw_discr_range = true;
}
+ else if ((candidate_discr
+ = analyze_discr_in_predicate (match_expr, struct_type))
+ && TREE_TYPE (candidate_discr) == boolean_type_node)
+ {
+ /* We are matching: <discr_field> for a boolean discriminant.
+ This sub-expression matches boolean_true_node. */
+ new_node = ggc_cleared_alloc<dw_discr_list_node> ();
+ if (!get_discr_value (boolean_true_node,
+ &new_node->dw_discr_lower_bound))
+ goto abort;
+ new_node->dw_discr_range = false;
+ }
+
else
/* Unsupported sub-expression: we cannot determine the set of
matching discriminant values. Abort everything. */
Index: ada/gcc-interface/decl.c
===================================================================
--- ada/gcc-interface/decl.c (revision 267062)
+++ ada/gcc-interface/decl.c (working copy)
@@ -6848,6 +6848,9 @@ choices_to_gnu (tree gnu_operand, Node_I
build_binary_op (LE_EXPR, boolean_type_node,
gnu_operand, gnu_high, true),
true);
+ else if (gnu_low == boolean_true_node
+ && TREE_TYPE (gnu_operand) == boolean_type_node)
+ gnu_test = gnu_operand;
else if (gnu_low)
gnu_test
= build_binary_op (EQ_EXPR, boolean_type_node, gnu_operand, gnu_low,