From 4fd9587f7c4b77550b6a9a1045e2687fb5d77335 Mon Sep 17 00:00:00 2001 From: Ed Schonberg Date: Mon, 28 May 2018 08:55:47 +0000 Subject: [PATCH] [Ada] Improve unnesting for discriminants of record subtypes 2018-05-28 Ed Schonberg gcc/ada/ * exp_unst.adb (Check_Static_Type): For a record subtype, check discriminant constraints as well. (Visit_Node): For a selected component, check type of prefix, as is done for indexed components and slices. From-SVN: r260838 --- gcc/ada/ChangeLog | 7 +++++++ gcc/ada/exp_unst.adb | 31 ++++++++++++++++++++++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index c00a76d..f6689b5 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,10 @@ +2018-05-28 Ed Schonberg + + * exp_unst.adb (Check_Static_Type): For a record subtype, check + discriminant constraints as well. + (Visit_Node): For a selected component, check type of prefix, as is + done for indexed components and slices. + 2018-05-28 Javier Miranda * exp_ch4.adb (Real_Range_Check): Add a temporary to store the integer diff --git a/gcc/ada/exp_unst.adb b/gcc/ada/exp_unst.adb index e2ecafc..f6d7650 100644 --- a/gcc/ada/exp_unst.adb +++ b/gcc/ada/exp_unst.adb @@ -481,17 +481,34 @@ package body Exp_Unst is end if; end; - -- For record type, check all components + -- For record type, check all components and discriminant + -- constraints if present. elsif Is_Record_Type (T) then declare C : Entity_Id; + D : Elmt_Id; + begin C := First_Component_Or_Discriminant (T); while Present (C) loop Check_Static_Type (Etype (C), N, DT); Next_Component_Or_Discriminant (C); end loop; + + if Has_Discriminants (T) + and then Present (Discriminant_Constraint (T)) + then + D := First_Elmt (Discriminant_Constraint (T)); + while Present (D) loop + if not Is_Static_Expression (Node (D)) then + Note_Uplevel_Bound (Node (D), N); + DT := True; + end if; + + Next_Elmt (D); + end loop; + end if; end; -- For array type, check index types and component type @@ -685,6 +702,18 @@ package body Exp_Unst is Check_Static_Type (Etype (Prefix (N)), Empty, DT); end; + -- A selected component can have an implicit up-level reference + -- due to the bounds of previous fields in the record. We + -- simplify the processing here by examining all components + -- of the record. + + elsif Nkind (N) = N_Selected_Component then + declare + DT : Boolean := False; + begin + Check_Static_Type (Etype (Prefix (N)), Empty, DT); + end; + -- Record a subprogram. We record a subprogram body that acts as -- a spec. Otherwise we record a subprogram declaration, providing -- that it has a corresponding body we can get hold of. The case -- 2.7.4