]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Inheritance of pragma/aspect unchecked_union
authorJavier Miranda <miranda@adacore.com>
Thu, 12 Mar 2026 18:55:21 +0000 (18:55 +0000)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Fri, 29 May 2026 08:49:47 +0000 (10:49 +0200)
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.

gcc/ada/exp_ch3.adb
gcc/ada/sem_ch3.adb

index 73d37dea315e5bac48edfe0df34c5e667dd2a7fd..6734c84986338d1f91402ec1f7916de0dc30956a 100644 (file)
@@ -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)))
index 3348303b99a15af42c7b894673a136551d7188b0..612cf712fd58c2aabbfe67431a5b65bb1b5c0dbb 100644 (file)
@@ -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;