From patchwork Thu Jan 3 11:05:45 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Charlet X-Patchwork-Id: 209219 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 58CA02C008F for ; Thu, 3 Jan 2013 22:06:18 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1357815978; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Received:Date:From:To:Cc:Subject:Message-ID: MIME-Version:Content-Type:Content-Disposition:User-Agent: Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:Sender:Delivered-To; bh=+DRvI4zJGM6iSdU3qbYl y9tIBKk=; b=tQ2bC1iLzM0eGQZqRsVIks0OoDb/jtPs/5qUn3ArfNATSomO6oNM BGTJFwcbry73shdohe8CCQyadi4NgyOQDi65onFMsNfVNtvnCGk7Spc2t4I7oNDQ v90E0yrIWJePehk/eTVCRuLEpcStvi9rmYoYQK50TzHW2xPsw75ja8U= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Received:Received:Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type:Content-Disposition:User-Agent:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=MgJOpvVOdIbnHI4FDaru3dDS8RqTOA80Z9V4Hnp+7/RmxiTbZlsn6GTdAcgRKj sV2mF8Q4+KrnaJOYzuZD/+r8kaKn9GHQcyy64pLVHBjflCEofOobNZvBByuHjBNr y++Xd7gAnPcRfc8oxwlBvHXrmR1jD66ERfa5rUziYWCjw=; Received: (qmail 2741 invoked by alias); 3 Jan 2013 11:05:53 -0000 Received: (qmail 2700 invoked by uid 22791); 3 Jan 2013 11:05:52 -0000 X-SWARE-Spam-Status: No, hits=-0.5 required=5.0 tests=AWL, BAYES_50, RCVD_IN_HOSTKARMA_NO 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; Thu, 03 Jan 2013 11:05:45 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 3CC8B2E4AF; Thu, 3 Jan 2013 06:05:45 -0500 (EST) 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 gJyfjU9ZhIeB; Thu, 3 Jan 2013 06:05:45 -0500 (EST) Received: from kwai.gnat.com (kwai.gnat.com [205.232.38.4]) by rock.gnat.com (Postfix) with ESMTP id 175F92E4B1; Thu, 3 Jan 2013 06:05:45 -0500 (EST) Received: by kwai.gnat.com (Postfix, from userid 4192) id 164753FF09; Thu, 3 Jan 2013 06:05:45 -0500 (EST) Date: Thu, 3 Jan 2013 06:05:45 -0500 From: Arnaud Charlet To: gcc-patches@gcc.gnu.org Cc: Thomas Quinot Subject: [Ada] Incorrect attachment point for address clause alignment check Message-ID: <20130103110545.GA22552@adacore.com> MIME-Version: 1.0 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-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org The alignment check for an address clause must be inserted after the object has been elaborated in the GIGI sense, but before any initialization operation occur. This change fixes both the spec and implementation of Apply_Address_Clause_Check to this effect (previously they disagreed, and were both incorrect: following the spec would have cause the check to occur too early, before the alignment of the object can be accurately determined, while the implementation would insert it too late, after initialization is done). The following compilation must be accepted quietly and produce the indicated exception occurrence: $ gnatmake -q -gnatws addr_init_misaligned $ ./addr_init_misaligned raised PROGRAM_ERROR : addr_init_misaligned.adb:23 misaligned address value with System.Storage_Elements; with Ada.Text_IO; use Ada.Text_IO; procedure Addr_Init_Misaligned is Misaligned : constant System.Address := System.Storage_Elements.To_Address (1); function F return Integer is begin Put_Line ("must not be called!"); return 666; end F; type R is record Comp_I : Integer := F; comp_S : String (1 .. 10); end record; X : R; -- The init proc should never be evaluated because the address clause -- is misaligned. for X'Address use Misaligned; begin Put_Line ("must not be executed (PE raised)"); end; Tested on x86_64-pc-linux-gnu, committed on trunk 2013-01-03 Thomas Quinot * checks.adb, checks.ads (Apply_Address_Clause_Check): The check must be generated at the start of the freeze actions for the entity, not before (or after) the freeze node. Index: checks.adb =================================================================== --- checks.adb (revision 194841) +++ checks.adb (working copy) @@ -575,6 +575,8 @@ -------------------------------- procedure Apply_Address_Clause_Check (E : Entity_Id; N : Node_Id) is + pragma Assert (Nkind (N) = N_Freeze_Entity); + AC : constant Node_Id := Address_Clause (E); Loc : constant Source_Ptr := Sloc (AC); Typ : constant Entity_Id := Etype (E); @@ -734,7 +736,11 @@ Remove_Side_Effects (Expr); end if; - Insert_After_And_Analyze (N, + if No (Actions (N)) then + Set_Actions (N, New_List); + end if; + + Prepend_To (Actions (N), Make_Raise_Program_Error (Loc, Condition => Make_Op_Ne (Loc, @@ -745,11 +751,11 @@ (RTE (RE_Integer_Address), Expr), Right_Opnd => Make_Attribute_Reference (Loc, - Prefix => New_Occurrence_Of (E, Loc), + Prefix => New_Occurrence_Of (E, Loc), Attribute_Name => Name_Alignment)), Right_Opnd => Make_Integer_Literal (Loc, Uint_0)), - Reason => PE_Misaligned_Address_Value), - Suppress => All_Checks); + Reason => PE_Misaligned_Address_Value)); + Analyze (First (Actions (N)), Suppress => All_Checks); return; end if; Index: checks.ads =================================================================== --- checks.ads (revision 194841) +++ checks.ads (working copy) @@ -131,8 +131,11 @@ -- are enabled, then this procedure generates a check that the specified -- address has an alignment consistent with the alignment of the object, -- raising PE if this is not the case. The resulting check (if one is - -- generated) is inserted before node N. check is also made for the case of - -- a clear overlay situation that the size of the overlaying object is not + -- generated) is prepended to the Actions list of N_Freeze_Entity node N. + -- Note that the check references E'Alignment, so it cannot be emitted + -- before N (its freeze node), otherwise this would cause an illegal + -- access before elaboration error in GIGI. For the case of a clear overlay + -- situation, we also check that the size of the overlaying object is not -- larger than the overlaid object. procedure Apply_Arithmetic_Overflow_Check (N : Node_Id);