* [Ada] Small fix for records with boolean discriminants
@ 2018-12-14 10:54 Eric Botcazou
0 siblings, 0 replies; only message in thread
From: Eric Botcazou @ 2018-12-14 10:54 UTC (permalink / raw)
To: gcc-patches
[-- Attachment #1: Type: text/plain, Size: 669 bytes --]
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 <ebotcazou@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
[-- Attachment #2: p.diff --]
[-- Type: text/x-patch, Size: 2287 bytes --]
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,
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2018-12-14 10:54 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-14 10:54 [Ada] Small fix for records with boolean discriminants Eric Botcazou
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).