https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122423

            Bug ID: 122423
           Summary: Mutably Tagged Types (Size’Class) do not have proper
                    alignment on classwide types
           Product: gcc
           Version: 15.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: ada
          Assignee: unassigned at gcc dot gnu.org
          Reporter: liam at liampwll dot com
                CC: dkm at gcc dot gnu.org
  Target Milestone: ---

If a descendant of a type T with the Size'Class aspect has an alignment wider
than the T on its own then the alignment of T is not updated to reflect this.
This means that an array of T'Class (or presumably any instance of T'Class)
allows for incorrect alignment. Below is a code example:

pragma Ada_2022;
pragma Extensions_Allowed (All_Extensions);

with Ada.Text_IO; use Ada.Text_IO;

procedure Example is
   type Aligned_Integer is new Integer with Alignment => 16;
   type A is tagged null record with Size'Class => 256 + 64;
   type B is new A with record
      Foo : Aligned_Integer;
   end record;

   X : array (1 .. 2) of A'Class := (A'(null record), A'(null record));
begin
   Put_Line (A'Class'Alignment'Image); --  8
   Put_Line (A'Alignment'Image);       --  8
   Put_Line (B'Alignment'Image);       --  16

   --  One of these is not aligned to 16
   Put_Line (X (1)'Address'Image);
   Put_Line (X (2)'Address'Image);

   --  One of these assignments will raise a Storage_Error
   X (1) := B'(Foo => 123);
   X (2) := B'(Foo => 123);
end Example;

Reply via email to