From c36774bcc38ba51fc9091d92a079e5b2d4aab759 Mon Sep 17 00:00:00 2001 From: Bob Duff Date: Sun, 29 Aug 2021 11:25:08 -0400 Subject: [PATCH] [Ada] Declaration_Node for Itypes returns Empty or declaration gcc/ada/ * einfo.ads (Declaration_Node): Document that Declaration_Node for Itypes. * einfo-utils.adb (Declaration_Node): Make it return Empty for Itypes, or a proper type or subtype declaration. * gen_il-gen.adb: Minor comment improvement. --- gcc/ada/einfo-utils.adb | 21 +++++++++++++-------- gcc/ada/einfo.ads | 4 +++- gcc/ada/gen_il-gen.adb | 2 ++ 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/gcc/ada/einfo-utils.adb b/gcc/ada/einfo-utils.adb index 38cfe34a50ca..0274e6b1aa8a 100644 --- a/gcc/ada/einfo-utils.adb +++ b/gcc/ada/einfo-utils.adb @@ -655,16 +655,21 @@ package body Einfo.Utils is P := Parent (Id); end if; + while Nkind (P) in N_Selected_Component | N_Expanded_Name + or else (Nkind (P) = N_Defining_Program_Unit_Name + and then Is_Child_Unit (Id)) loop - if Nkind (P) in N_Selected_Component | N_Expanded_Name - or else (Nkind (P) = N_Defining_Program_Unit_Name - and then Is_Child_Unit (Id)) - then - P := Parent (P); - else - return P; - end if; + P := Parent (P); end loop; + + if Is_Itype (Id) + and then Nkind (P) not in + N_Full_Type_Declaration | N_Subtype_Declaration + then + P := Empty; + end if; + + return P; end Declaration_Node; --------------------- diff --git a/gcc/ada/einfo.ads b/gcc/ada/einfo.ads index f890fe54230d..2030841eaabc 100644 --- a/gcc/ada/einfo.ads +++ b/gcc/ada/einfo.ads @@ -829,7 +829,9 @@ package Einfo is -- a private type, then we obtain the declaration node denoted by the -- full type, i.e. the full type declaration node. Also note that for -- subprograms, this returns the {function,procedure}_specification, not --- the subprogram_declaration. +-- the subprogram_declaration. If the parent of an Itype is a type or +-- subtype declaration, we return the declaration node as for any other +-- type. For other Itypes, we return Empty. -- Default_Aspect_Component_Value [base type only] -- Defined in array types. Holds the static value specified in a diff --git a/gcc/ada/gen_il-gen.adb b/gcc/ada/gen_il-gen.adb index 305a99ae35c8..9983e1052db4 100644 --- a/gcc/ada/gen_il-gen.adb +++ b/gcc/ada/gen_il-gen.adb @@ -710,6 +710,8 @@ package body Gen_IL.Gen is Type_Table (T).Last := T; Add_Concrete_Descendant_To_Ancestors (Type_Table (T).Parent, T); + -- Parent cannot be No_Type here, because T is a concrete + -- type, and therefore not a root type. when Abstract_Type => declare -- 2.47.2