From patchwork Mon May 2 09:24:01 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Charlet X-Patchwork-Id: 617434 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 3qyzR22SYbz9s4n for ; Mon, 2 May 2016 19:24:46 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=md0WH9zI; 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=OxA77h9pYL8qhmKI2voFFUNLDDthFeP5t93czuEFdv5mi4De2e YIFl8scmMTpjXZV+EWPpALlbU3sK9VPnReBETY32uF7LaZ1HmR2cmxGoh2RWFOi7 1bNQlDEfNHAKOW0CrLZqLASkP3QLiqS4yEcM2uj0Z0iKD1vioCHawzcbM= 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=ONLoahUhqACN3zFBXre1Vw1s7qE=; b=md0WH9zILnVv7kVLwaJu BFI0oxmdZ62ZriULKAyq8nfwCaJ4m5vX8NlT5UM776RAZn0eCAhx5w+6eyakR9Zx kKlzvLSsSSAj5haJAerU1ilQ6GCIFF/ArnuV6bFXdpp+HF3G7xN4Uv5K0e588ZJS PYrfD+3pK0WhGFEqES+pEKo= Received: (qmail 31856 invoked by alias); 2 May 2016 09:24:35 -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 31546 invoked by uid 89); 2 May 2016 09:24:25 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=1.2 required=5.0 tests=AWL, BAYES_05, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_DNSWL_NONE autolearn=no version=3.3.2 spammy=Warn, etype, Etype, H*F:U*charlet 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 (AES256-SHA encrypted) ESMTPS; Mon, 02 May 2016 09:24:03 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 9D16A116B2F; Mon, 2 May 2016 05:24:01 -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 eJdC+SfmOEAV; Mon, 2 May 2016 05:24:01 -0400 (EDT) Received: from tron.gnat.com (tron.gnat.com [205.232.38.10]) by rock.gnat.com (Postfix) with ESMTP id 8B583116B2E; Mon, 2 May 2016 05:24:01 -0400 (EDT) Received: by tron.gnat.com (Postfix, from userid 4192) id 88D4741B; Mon, 2 May 2016 05:24:01 -0400 (EDT) Date: Mon, 2 May 2016 05:24:01 -0400 From: Arnaud Charlet To: gcc-patches@gcc.gnu.org Cc: Ed Schonberg Subject: [Ada] Error in handling of convention of formal parameter Message-ID: <20160502092401.GA112785@adacore.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) This patch fixes an error in the determination of the convention to be used for a formal parameter, when the corresponding type carries a convention pragma. Executing: gcc -c p.ads -gnatRm must yield: Representation information for unit P (spec) for Rec'Size use 1024; for Rec'Alignment use 1; for Rec use record I at 0 range 0 .. 1023; end record; for Arr'Size use 64; for Arr'Alignment use 4; for Arr'Component_Size use 32; procedure proc1 declared at p.ads:11:13 convention : Ada r : passed by copy i : passed by copy procedure proc2 declared at p.ads:12:13 convention : Ada a : passed by reference i : passed by copy --- package P is type Rec is record I : String (1 .. 128); end record; pragma Convention (Ada_Pass_By_Copy, Rec); type Arr is array (1 .. 2) of Integer; pragma Convention (Ada_Pass_By_Reference, Arr); procedure Proc1 (R : Rec; I : Integer) is null; procedure Proc2 (A : Arr; I : Integer) is null; end P; Tested on x86_64-pc-linux-gnu, committed on trunk 2016-05-02 Ed Schonberg * sem_ch6.adb (Process_Formals): Check properly the type of a formal to determine whether a given convention applies to it. Index: sem_ch6.adb =================================================================== --- sem_ch6.adb (revision 235706) +++ sem_ch6.adb (working copy) @@ -10792,24 +10792,28 @@ -- Force call by reference if aliased - if Is_Aliased (Formal) then - Set_Mechanism (Formal, By_Reference); + declare + Conv : constant Convention_Id := Convention (Etype (Formal)); + begin + if Is_Aliased (Formal) then + Set_Mechanism (Formal, By_Reference); - -- Warn if user asked this to be passed by copy + -- Warn if user asked this to be passed by copy - if Convention (Formal_Type) = Convention_Ada_Pass_By_Copy then - Error_Msg_N - ("cannot pass aliased parameter & by copy??", Formal); - end if; + if Conv = Convention_Ada_Pass_By_Copy then + Error_Msg_N + ("cannot pass aliased parameter & by copy??", Formal); + end if; - -- Force mechanism if type has Convention Ada_Pass_By_Ref/Copy + -- Force mechanism if type has Convention Ada_Pass_By_Ref/Copy - elsif Convention (Formal_Type) = Convention_Ada_Pass_By_Copy then - Set_Mechanism (Formal, By_Copy); + elsif Conv = Convention_Ada_Pass_By_Copy then + Set_Mechanism (Formal, By_Copy); - elsif Convention (Formal_Type) = Convention_Ada_Pass_By_Reference then - Set_Mechanism (Formal, By_Reference); - end if; + elsif Conv = Convention_Ada_Pass_By_Reference then + Set_Mechanism (Formal, By_Reference); + end if; + end; <> Next (Param_Spec);