public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Eric Botcazou <ebotcazou@adacore.com>
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	[thread overview]
Message-ID: <201109261034.48251.ebotcazou@adacore.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 1270 bytes --]

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  <ebotcazou@adacore.com>
            Robert Dewar  <dewar@adacore.com>

	* 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

[-- Attachment #2: p.diff --]
[-- Type: text/x-diff, Size: 894 bytes --]

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);

                 reply	other threads:[~2011-09-26  8:38 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=201109261034.48251.ebotcazou@adacore.com \
    --to=ebotcazou@adacore.com \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).