From: Pierre-Marie de Rodat <derodat@adacore.com>
To: gcc-patches@gcc.gnu.org
Cc: Steve Baird <baird@adacore.com>
Subject: [Ada] Implement AI12-0032 fixes for 'Old attribute accessibility
Date: Thu, 18 Jun 2020 05:13:20 -0400 [thread overview]
Message-ID: <20200618091320.GA2127@adacore.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 1002 bytes --]
AI12-0032 modifies/clarifies many of the rules pertaining to uses of the
Old attribute. Most of these 7 changes were already implemented by GNAT
but a couple having to do with accessibility were not. Implement those
unimplemented rules.
Tested on x86_64-pc-linux-gnu, committed on trunk
2020-06-18 Steve Baird <baird@adacore.com>
gcc/ada/
* sem_util.adb (Object_Access_Level): Treat a 'Old attribute
reference like an aggregate in determining its static
accessibility level; after the evaluation of the relevant
post-condition, the implicitly declared constant associated with
an Old attribute reference ceases to exist. Similarly for
Loop_Entry attribute.
* exp_ch6.adb (Expand_Call_Helper): For an attribute reference
that is expanded into a reference to an implicitly declared
constant (e.g., a 'Old or 'Loop_Entry attribute), compute the
dynamic accessibility level of that constant by looking at the
declaration of the constant (as opposed to looking at the
attribute reference).
[-- Attachment #2: patch.diff --]
[-- Type: text/x-diff, Size: 1927 bytes --]
--- gcc/ada/exp_ch6.adb
+++ gcc/ada/exp_ch6.adb
@@ -3617,6 +3617,21 @@ package body Exp_Ch6 is
then
Prev_Orig := Prev;
+ -- If the actual is an attribute reference that was expanded
+ -- into a reference to an entity, then get accessibility level
+ -- from that entity. AARM 6.1.1(27.d) says "... the implicit
+ -- constant declaration defines the accessibility level of X'Old".
+
+ elsif Nkind (Prev_Orig) = N_Attribute_Reference
+ and then Nam_In (Attribute_Name (Prev_Orig),
+ Name_Old,
+ Name_Loop_Entry)
+ and then Is_Entity_Name (Prev)
+ and then Present (Entity (Prev))
+ and then Is_Object (Entity (Prev))
+ then
+ Prev_Orig := Prev;
+
elsif Nkind (Prev_Orig) = N_Type_Conversion then
Prev_Orig := Expression (Prev_Orig);
end if;
--- gcc/ada/sem_util.adb
+++ gcc/ada/sem_util.adb
@@ -24237,6 +24237,18 @@ package body Sem_Util is
elsif Nkind (Orig_Obj) = N_Aggregate then
return Object_Access_Level (Current_Scope);
+ -- Treat an Old/Loop_Entry attribute reference like an aggregate.
+ -- AARM 6.1.1(27.d) says "... the implicit constant declaration
+ -- defines the accessibility level of X'Old", so that is what
+ -- we are trying to implement here.
+
+ elsif Nkind (Orig_Obj) = N_Attribute_Reference
+ and then Nam_In (Attribute_Name (Orig_Obj),
+ Name_Old,
+ Name_Loop_Entry)
+ then
+ return Object_Access_Level (Current_Scope);
+
-- Otherwise return the scope level of Standard. (If there are cases
-- that fall through to this point they will be treated as having
-- global accessibility for now. ???)
reply other threads:[~2020-06-18 9:13 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=20200618091320.GA2127@adacore.com \
--to=derodat@adacore.com \
--cc=baird@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).