https://gcc.gnu.org/g:515006c744f22d2707efa6789b2ef10c36e2eaaf
commit r17-933-g515006c744f22d2707efa6789b2ef10c36e2eaaf Author: Javier Miranda <[email protected]> Date: Thu Mar 12 18:55:21 2026 +0000 ada: Inheritance of pragma/aspect unchecked_union Derived types inherit pragma/aspect uncheched union. gcc/ada/ChangeLog: * sem_ch3.adb (Build_Derived_Record_Type): Record type derivations inherit Is_Unchecked_Union and Has_Unchecked_Union flags. (Inherit_Component): Add discriminals to the associations list. * exp_ch3.adb (Build_Record_Init_Proc): Derivations of Unchecked_Union types don't need an initialization procedure; they reuse the init proc of their parent type. Diff: --- gcc/ada/exp_ch3.adb | 4 +++- gcc/ada/sem_ch3.adb | 12 ++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/gcc/ada/exp_ch3.adb b/gcc/ada/exp_ch3.adb index 73d37dea315e..6734c8498633 100644 --- a/gcc/ada/exp_ch3.adb +++ b/gcc/ada/exp_ch3.adb @@ -4860,13 +4860,15 @@ package body Exp_Ch3 is -- Derived types that have no type extension can use the initialization -- procedure of their parent and do not need a procedure of their own. + -- Same for derivations of unchecked_union types. -- This is only correct if there are no representation clauses for the -- type or its parent, and if the parent has in fact been frozen so -- that its initialization procedure exists. if Is_Derived_Type (Rec_Type) and then not Is_Tagged_Type (Rec_Type) - and then not Is_Unchecked_Union (Rec_Type) + and then Is_Unchecked_Union (Rec_Type) + = Is_Unchecked_Union (Etype (Rec_Type)) and then not Has_New_Non_Standard_Rep (Rec_Type) and then not Parent_Subtype_Renaming_Discrims and then Present (Base_Init_Proc (Etype (Rec_Type))) diff --git a/gcc/ada/sem_ch3.adb b/gcc/ada/sem_ch3.adb index 3348303b99a1..612cf712fd58 100644 --- a/gcc/ada/sem_ch3.adb +++ b/gcc/ada/sem_ch3.adb @@ -10134,6 +10134,13 @@ package body Sem_Ch3 is Set_Has_Primitive_Operations (Derived_Type, Has_Primitive_Operations (Parent_Base)); + if Ekind (Derived_Type) = E_Record_Type then + Set_Is_Unchecked_Union + (Derived_Type, Is_Unchecked_Union (Parent_Base)); + Set_Has_Unchecked_Union + (Derived_Type, Has_Unchecked_Union (Parent_Base)); + end if; + -- Set fields for private derived types if Is_Private_Type (Derived_Type) then @@ -20013,6 +20020,11 @@ package body Sem_Ch3 is if not Is_Tagged then Append_Elmt (Old_C, Assoc_List); Append_Elmt (New_C, Assoc_List); + + if Plain_Discrim then + Append_Elmt (Discriminal (Old_C), Assoc_List); + Append_Elmt (Discriminal (New_C), Assoc_List); + end if; end if; end Inherit_Component;
