https://gcc.gnu.org/g:4009ccbec618e5ac3c7a54708a5eeb076831ce87
commit r16-9017-g4009ccbec618e5ac3c7a54708a5eeb076831ce87 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 f419dd3919a0..4238ea778b8b 100644 --- a/gcc/ada/exp_ch3.adb +++ b/gcc/ada/exp_ch3.adb @@ -4865,13 +4865,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 c84f288f654d..6109d1e88c7f 100644 --- a/gcc/ada/sem_ch3.adb +++ b/gcc/ada/sem_ch3.adb @@ -10139,6 +10139,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 @@ -19988,6 +19995,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;
