* [Ada] Possibly bit aligned objects in assignments
@ 2011-09-02 8:26 Arnaud Charlet
0 siblings, 0 replies; only message in thread
From: Arnaud Charlet @ 2011-09-02 8:26 UTC (permalink / raw)
To: gcc-patches; +Cc: Ed Schonberg
[-- Attachment #1: Type: text/plain, Size: 1714 bytes --]
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 #2: difs --]
[-- Type: text/plain, Size: 708 bytes --]
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.
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2011-09-02 8:26 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-09-02 8:26 [Ada] Possibly bit aligned objects in assignments Arnaud Charlet
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).