diff mbox series

[Ada] Adjust the alignment to the size for bit-packed arrays

Message ID 20220110094134.GA586058@adacore.com
State New
Headers show
Series [Ada] Adjust the alignment to the size for bit-packed arrays | expand

Commit Message

Pierre-Marie de Rodat Jan. 10, 2022, 9:41 a.m. UTC
This fixes a fallout of the latest change, which removed a problematic
line resetting the alignment of the PAT type.  It turns out that the
alignment must now be adjusted for modular PAT types, as done in other
contexts, to be consistent with the size.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

	* exp_pakd.adb (Install_PAT): If the PAT is a scalar type, apply
	the canonical adjustment to its alignment.
diff mbox series

Patch

diff --git a/gcc/ada/exp_pakd.adb b/gcc/ada/exp_pakd.adb
--- a/gcc/ada/exp_pakd.adb
+++ b/gcc/ada/exp_pakd.adb
@@ -573,6 +573,19 @@  package body Exp_Pakd is
             end if;
          end if;
 
+         --  In the case of a modular type, make sure the alignment is
+         --  consistent with the Esize.
+
+         if Is_Scalar_Type (PAT) then
+            while Alignment (PAT) * System_Storage_Unit < Esize (PAT)
+              and then Alignment (PAT) < Maximum_Alignment
+            loop
+               Set_Alignment (PAT, 2 * Alignment (PAT));
+            end loop;
+         end if;
+
+         --  Then, in all cases, make sure the opposite is also true
+
          Adjust_Esize_Alignment (PAT);
 
          --  Set remaining fields of packed array type