This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Ada] Possibly bit aligned objects in assignments


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  <schonberg@adacore.com>

	* exp_util.adb: (Possible_Bit_Aligned_Object): If the object
	is an unchecked conversion, apply test to its expression.

Attachment: difs
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]