If either the target or the expression in an array or record ssignment may be bit-aligned, the assignment must be expanded into component assignments. The object (or subcomponent) may be given by an unchecked conversion, in which case we must examine its expression to determine potential mis-alignment.
The following must execute quietly: gnatmake -gnata -q test_conversion test_conversion --- with Packing; use Packing; with Interfaces; use Interfaces; procedure Test_Conversion is Orig : Table := (1, (others => (others => (others => 4)))); Dest : Packed_Table; begin Convert (Orig, Dest); pragma Assert (Dest.Data (1) (1, 1) = 4); end Test_Conversion; --- with Interfaces; use Interfaces; package Packing is subtype Index is Integer range 0 .. 32; type Element is array (1 .. 2, 1 .. 2) of Integer_32; type Container is array (1 .. 3) of Element; pragma Pack (Container); type Table is record Padding : Index; Data : Container; end record; type Packed_Table is new Table; for Packed_Table use record Padding at 0 range 0 .. 5; Data at 0 range 6 .. 12 * 32 + 5; end record; procedure Convert (Value_In : Table; Value_Out : out Packed_Table); end Packing; --- package body Packing is procedure Convert (Value_In : Table; Value_Out : out Packed_Table) is begin Value_Out := Packed_Table (Value_In); end Convert; end Packing; Tested on x86_64-pc-linux-gnu, committed on trunk 2011-09-02 Ed Schonberg <schonb...@adacore.com> * exp_util.adb: (Possible_Bit_Aligned_Object): If the object is an unchecked conversion, apply test to its expression.
Index: exp_util.adb =================================================================== --- exp_util.adb (revision 178438) +++ exp_util.adb (working copy) @@ -5687,6 +5687,12 @@ when N_Slice => return Possible_Bit_Aligned_Component (Prefix (N)); + -- For an unchecked conversion, check whether the expression may + -- be bit-aligned. + + when N_Unchecked_Type_Conversion => + return Possible_Bit_Aligned_Component (Expression (N)); + -- If we have none of the above, it means that we have fallen off the -- top testing prefixes recursively, and we now have a stand alone -- object, where we don't have a problem.