public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Marc Poulhiès" <poulhies@adacore.com>
To: gcc-patches@gcc.gnu.org
Cc: "Marc Poulhiès" <poulhies@adacore.com>
Subject: [COMMITTED] ada: Fix storage model handling for dereference as lvalue and renamings
Date: Tue, 30 May 2023 09:21:05 +0200	[thread overview]
Message-ID: <20230530072105.2500303-1-poulhies@adacore.com> (raw)

Don't require storage access for explicit dereferences used as
lvalue (e.g. Some_Access.all'Address) or for renamings.

gcc/ada/

	* gcc-interface/trans.cc (get_storage_model_access): Don't require
	storage model access for dereference used as lvalue or renamings.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/gcc-interface/trans.cc | 24 +++++++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)

diff --git a/gcc/ada/gcc-interface/trans.cc b/gcc/ada/gcc-interface/trans.cc
index 13f438c424b..f4a5db002f4 100644
--- a/gcc/ada/gcc-interface/trans.cc
+++ b/gcc/ada/gcc-interface/trans.cc
@@ -4398,14 +4398,32 @@ static void
 get_storage_model_access (Node_Id gnat_node, Entity_Id *gnat_smo)
 {
   const Node_Id gnat_parent = Parent (gnat_node);
+  *gnat_smo = Empty;
 
-  /* If we are the prefix of the parent, then the access is above us.  */
-  if (node_is_component (gnat_parent) && Prefix (gnat_parent) == gnat_node)
+  switch (Nkind (gnat_parent))
     {
-      *gnat_smo = Empty;
+    case N_Attribute_Reference:
+      /* If the parent is an attribute reference that requires an lvalue and
+         gnat_node is the Prefix (i.e. not a parameter), we do not need to
+         actually access any storage. */
+      if (lvalue_required_for_attribute_p (gnat_parent)
+          && Prefix (gnat_parent) == gnat_node)
+        return;
+      break;
+
+    case N_Object_Renaming_Declaration:
+      /* Nothing to do for the identifier in an object renaming declaration,
+         the renaming itself does not need storage model access. */
       return;
+
+    default:
+      break;
     }
 
+  /* If we are the prefix of the parent, then the access is above us.  */
+  if (node_is_component (gnat_parent) && Prefix (gnat_parent) == gnat_node)
+    return;
+
   /* Now strip any type conversion from GNAT_NODE.  */
   if (Nkind (gnat_node) == N_Type_Conversion
       || Nkind (gnat_node) == N_Unchecked_Type_Conversion)
-- 
2.40.0


                 reply	other threads:[~2023-05-30  7:21 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=20230530072105.2500303-1-poulhies@adacore.com \
    --to=poulhies@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).