From patchwork Tue Apr 25 09:40:58 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Charlet X-Patchwork-Id: 754666 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]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3wByrm1DQCz9s3s for ; Tue, 25 Apr 2017 19:41:11 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="pQUCwYMQ"; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:mime-version:content-type; q=dns; s=default; b=llNfabM3EPpZKYy9xHyF+t5ktV1Vs/puq8QL9O4Jaw6Cs9PwXl 2KCs8H54Xpf13fewwdzkaiMhYEl3LaS3S3BXXHeGVD3z4Ddt4lVHG8y/B3q0ogOr nO1eWHRSNNI6Tqw/kKzxhDtsHYQvwBZVr+77Nr5Mb5DO15kiJrMBxhHnU= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:mime-version:content-type; s= default; bh=xff1iFnieVFQ8kdu+Kdeoky5vRc=; b=pQUCwYMQmbhiIwMPpiJ0 5ThbxWiZ5KMAzqHhzzbgUh61QVGbZ66pAy4kiUmD1V6iBtTMSbLysS/nZy2miXCC sLGNrzmM0Hb25rHC/zFmEyTeMt5aVi2oU4Zrc9UAWaZ0ImeQF9ULDOS80Tr1wsMM wRINu3lpqzoswWtWiKoco+o= Received: (qmail 57352 invoked by alias); 25 Apr 2017 09:41:00 -0000 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 Received: (qmail 56833 invoked by uid 89); 25 Apr 2017 09:40:59 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-10.8 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=raised, clauses X-HELO: rock.gnat.com Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 25 Apr 2017 09:40:58 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id F1DC03547; Tue, 25 Apr 2017 05:40:58 -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 OiQihLT8sOJx; Tue, 25 Apr 2017 05:40:58 -0400 (EDT) Received: from tron.gnat.com (tron.gnat.com [205.232.38.10]) by rock.gnat.com (Postfix) with ESMTP id DF37D350F; Tue, 25 Apr 2017 05:40:58 -0400 (EDT) Received: by tron.gnat.com (Postfix, from userid 4192) id DB333521; Tue, 25 Apr 2017 05:40:58 -0400 (EDT) Date: Tue, 25 Apr 2017 05:40:58 -0400 From: Arnaud Charlet To: gcc-patches@gcc.gnu.org Cc: Hristian Kirtchev Subject: [Ada] Specifying Address clause on controlled objects Message-ID: <20170425094058.GA113857@adacore.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) This patch removes the restriction on attribute definition clause 'Address which prevented it from being used with controlled objects. The restriction was a legacy left over from the previous controlled type implementation where each controlled type had hidden components that should not be overlayed. ------------ -- Source -- ------------ -- types.ads with Ada.Finalization; use Ada.Finalization; package Types is type Ctrl is new Controlled with record Comp_1 : Integer; end record; type Rec is record Comp_1 : Ctrl; Comp_2 : Integer; end record; type Tag_Typ is tagged record Comp_1 : Integer; Comp_2 : Integer; Comp_3 : Integer; end record; end Types; -- main.adb with Ada.Text_IO; use Ada.Text_IO; with System; use System; with System.Storage_Elements; use System.Storage_Elements; with Types; use Types; procedure Main is Obj_1 : constant Integer := 1; Obj_1_Addr : constant Address := Obj_1'Address; -- The objects are declared in one order, but their address clauses order -- them in reverse declarative order. Obj_4_Addr : constant Address := Obj_1_Addr + Integer'Size; Obj_3_Addr : constant Address := Obj_4_Addr + Tag_Typ'Size; Obj_2_Addr : constant Address := Obj_3_Addr + Ctrl'Size; Obj_2 : Ctrl; for Obj_2'Address use Obj_2_Addr; Obj_3 : Rec; for Obj_3'Address use Obj_3_Addr; Obj_4 : Tag_Typ; for Obj_4'Address use Obj_4_Addr; begin if Obj_2'Address /= Obj_2_Addr then Put_Line ("ERROR: Obj_2 is in the wrong place"); end if; if Obj_3'Address /= Obj_3_Addr then Put_Line ("ERROR: Obj_3 is in the wrong place"); end if; if Obj_4'Address /= Obj_4_Addr then Put_Line ("ERROR: Obj_4 is in the wrong place"); end if; end Main; ----------------- -- Compilation -- ----------------- $ gnatmake -q -gnatws main.adb $ ./main Tested on x86_64-pc-linux-gnu, committed on trunk 2017-04-25 Hristian Kirtchev * sem_ch13.adb (Analyze_Attribute_Definition_Clause): Remove the restriction converning the use of 'Address where the prefix is of a controlled type. Index: sem_ch13.adb =================================================================== --- sem_ch13.adb (revision 247160) +++ sem_ch13.adb (working copy) @@ -4887,21 +4887,6 @@ ("\?j?use interrupt procedure instead", N); end if; - -- Case of an address clause for a controlled object, which we - -- consider to be erroneous. - - elsif Is_Controlled (Etype (U_Ent)) - or else Has_Controlled_Component (Etype (U_Ent)) - then - Error_Msg_NE - ("??controlled object & must not be overlaid", Nam, U_Ent); - Error_Msg_N - ("\??Program_Error will be raised at run time", Nam); - Insert_Action (Declaration_Node (U_Ent), - Make_Raise_Program_Error (Loc, - Reason => PE_Overlaid_Controlled_Object)); - return; - -- Case of an address clause for a class-wide object, which is -- considered erroneous. @@ -4915,9 +4900,9 @@ Reason => PE_Overlaid_Controlled_Object)); return; - -- Case of address clause for a (non-controlled) object + -- Case of address clause for an object - elsif Ekind_In (U_Ent, E_Variable, E_Constant) then + elsif Ekind_In (U_Ent, E_Constant, E_Variable) then declare Expr : constant Node_Id := Expression (N); O_Ent : Entity_Id; @@ -5006,28 +4991,11 @@ end; end if; - -- Overlaying controlled objects is erroneous. Emit warning - -- but continue analysis because program is itself legal, - -- and back end must see address clause. - - if Present (O_Ent) - and then (Has_Controlled_Component (Etype (O_Ent)) - or else Is_Controlled (Etype (O_Ent))) - and then not Inside_A_Generic - then - Error_Msg_N - ("??cannot use overlays with controlled objects", Expr); - Error_Msg_N - ("\??Program_Error will be raised at run time", Expr); - Insert_Action (Declaration_Node (U_Ent), - Make_Raise_Program_Error (Loc, - Reason => PE_Overlaid_Controlled_Object)); - -- Issue an unconditional warning for a constant overlaying -- a variable. For the reverse case, we will issue it only -- if the variable is modified. - elsif Ekind (U_Ent) = E_Constant + if Ekind (U_Ent) = E_Constant and then Present (O_Ent) and then not Overlays_Constant (U_Ent) and then Address_Clause_Overlay_Warnings