From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24169 invoked by alias); 26 Sep 2011 08:38:25 -0000 Received: (qmail 24082 invoked by uid 22791); 26 Sep 2011 08:38:23 -0000 X-SWARE-Spam-Status: No, hits=-1.9 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from mel.act-europe.fr (HELO mel.act-europe.fr) (194.98.77.210) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 26 Sep 2011 08:38:08 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id 547CCCB01BA for ; Mon, 26 Sep 2011 10:38:09 +0200 (CEST) Received: from mel.act-europe.fr ([127.0.0.1]) by localhost (smtp.eu.adacore.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 6-h8SYaQrPet for ; Mon, 26 Sep 2011 10:37:59 +0200 (CEST) Received: from [192.168.1.2] (bon31-9-83-155-120-49.fbx.proxad.net [83.155.120.49]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mel.act-europe.fr (Postfix) with ESMTP id DAD87CB0262 for ; Mon, 26 Sep 2011 10:37:58 +0200 (CEST) From: Eric Botcazou To: gcc-patches@gcc.gnu.org Subject: [Ada] Eliminate redundant access checks for null-exclusion access types Date: Mon, 26 Sep 2011 09:42:00 -0000 User-Agent: KMail/1.9.9 MIME-Version: 1.0 Content-Type: Multipart/Mixed; boundary="Boundary-00=_okDgO4zgnBUx1GJ" Message-Id: <201109261034.48251.ebotcazou@adacore.com> 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/msg01565.txt.bz2 --Boundary-00=_okDgO4zgnBUx1GJ Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-Disposition: inline Content-length: 1270 It turned out that the front-end wasn't fully using the information about the null exclusion either in some cases. This eliminates redundant access checks in the callee for subprograms with IN or IN/OUT parameters of an null-exclusion access subtype, which were introduced in Ada 2005. The compiler already omits these checks in the case of non-null access parameters present in Ada 95. An access check is generated in the caller in both cases. The compiler must generate no access checks within P2 for the following unit: package Pkg is type Varray is array (Integer range <>) of Long_Float; type Ptr is access Varray; procedure P1 (X : not null access Varray); procedure P2 (X : not null Ptr); end Pkg; package body Pkg is procedure P1 (X : not null access Varray) is begin for I in X'Range loop X (I) := 0.0; end loop; end; procedure P2 (X : not null Ptr) is begin for I in X'Range loop X (I) := 0.0; end loop; end; end Pkg; 2011-09-26 Eric Botcazou Robert Dewar * sem_ch6.adb (Set_Formal_Mode): Set Can_Never_Be_Null on an IN or IN OUT formal parameter which is of an null-exclusion access subtype. -- Eric Botcazou --Boundary-00=_okDgO4zgnBUx1GJ Content-Type: text/x-diff; charset="iso 8859-15"; name="p.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="p.diff" Content-length: 894 Index: sem_ch6.adb =================================================================== --- sem_ch6.adb (revision 179163) +++ sem_ch6.adb (working copy) @@ -10267,6 +10267,16 @@ package body Sem_Ch6 is and then Can_Never_Be_Null (Etype (Formal_Id)) then Set_Is_Known_Non_Null (Formal_Id); + + -- We can also set Can_Never_Be_Null (thus preventing some junk + -- access checks) for the case of an IN parameter, which cannot + -- be changed, or for an IN OUT parameter, which can be changed but + -- not to a null value. But for an OUT parameter, the initial value + -- passed in can be null, so we can't set this flag in that case. + + if Ekind (Formal_Id) /= E_Out_Parameter then + Set_Can_Never_Be_Null (Formal_Id); + end if; end if; Set_Mechanism (Formal_Id, Default_Mechanism); --Boundary-00=_okDgO4zgnBUx1GJ--