From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15036 invoked by alias); 2 Sep 2011 08:26:23 -0000 Received: (qmail 14571 invoked by uid 22791); 2 Sep 2011 08:26:20 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 02 Sep 2011 08:26:06 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 221C92BB3FC; Fri, 2 Sep 2011 04:26:06 -0400 (EDT) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id SaifgJx3Wb9z; Fri, 2 Sep 2011 04:26:06 -0400 (EDT) Received: from kwai.gnat.com (kwai.gnat.com [205.232.38.4]) by rock.gnat.com (Postfix) with ESMTP id 0F15A2BB3E7; Fri, 2 Sep 2011 04:26:06 -0400 (EDT) Received: by kwai.gnat.com (Postfix, from userid 4192) id 0D83D3FEE8; Fri, 2 Sep 2011 04:26:06 -0400 (EDT) Date: Fri, 02 Sep 2011 08:26:00 -0000 From: Arnaud Charlet To: gcc-patches@gcc.gnu.org Cc: Ed Schonberg Subject: [Ada] Possibly bit aligned objects in assignments Message-ID: <20110902082606.GA5493@adacore.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="T4sUOijqQbZv57TR" Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org X-SW-Source: 2011-09/txt/msg00104.txt.bz2 --T4sUOijqQbZv57TR Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-length: 1714 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 * exp_util.adb: (Possible_Bit_Aligned_Object): If the object is an unchecked conversion, apply test to its expression. --T4sUOijqQbZv57TR Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=difs Content-length: 708 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. --T4sUOijqQbZv57TR--