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: Eric Botcazou <ebotcazou@adacore.com>
Subject: [COMMITTED 18/31] ada: Fix small inaccuracy for Size attribute applied to objects
Date: Tue, 21 May 2024 09:30:21 +0200	[thread overview]
Message-ID: <20240521073035.314024-18-poulhies@adacore.com> (raw)
In-Reply-To: <20240521073035.314024-1-poulhies@adacore.com>

From: Eric Botcazou <ebotcazou@adacore.com>

This reverts a change made some time ago in lvalue_required_for_attribute_p
whereby the Size attribute applied to objects would no longer be considered
as requiring an lvalue.

While not wrong in principle, this turns out to be problematic because the
implementation in Attribute_to_gnu needs to look at the translated prefix
to spot particular cases and not only at the actual type of its value.

This of course requires a small adjustment in gnat_to_gnu to compensate.

gcc/ada/

	* gcc-interface/trans.cc (access_attribute_p): New predicate.
	(lvalue_required_for_attribute_p): Return again 1 for Size and add
	the missing terminating call to gcc_unreachable.
	(gnat_to_gnu): Return the result unmodified for a reference to an
	unconstrained array only if it is the prefix of an access attribute.

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

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

diff --git a/gcc/ada/gcc-interface/trans.cc b/gcc/ada/gcc-interface/trans.cc
index 8c7ffbf5687..6f761766559 100644
--- a/gcc/ada/gcc-interface/trans.cc
+++ b/gcc/ada/gcc-interface/trans.cc
@@ -745,6 +745,26 @@ build_raise_check (int check, enum exception_info_kind kind)
   return result;
 }
 
+/* Return true if GNAT_NODE, which is an N_Attribute_Reference, is one of the
+   access attributes.  */
+
+static bool
+access_attribute_p (Node_Id gnat_node)
+{
+  switch (Get_Attribute_Id (Attribute_Name (gnat_node)))
+    {
+    case Attr_Access:
+    case Attr_Unchecked_Access:
+    case Attr_Unrestricted_Access:
+      return true;
+
+    default:
+      return false;
+    }
+
+  gcc_unreachable ();
+}
+
 /* Return a positive value if an lvalue is required for GNAT_NODE, which is
    an N_Attribute_Reference.  */
 
@@ -760,7 +780,6 @@ lvalue_required_for_attribute_p (Node_Id gnat_node)
     case Attr_Range_Length:
     case Attr_Length:
     case Attr_Object_Size:
-    case Attr_Size:
     case Attr_Value_Size:
     case Attr_Component_Size:
     case Attr_Descriptor_Size:
@@ -786,11 +805,14 @@ lvalue_required_for_attribute_p (Node_Id gnat_node)
     case Attr_First_Bit:
     case Attr_Last_Bit:
     case Attr_Bit:
+    case Attr_Size:
     case Attr_Asm_Input:
     case Attr_Asm_Output:
     default:
       return 1;
     }
+
+  gcc_unreachable ();
 }
 
 /* Return a positive value if an lvalue is required for GNAT_NODE.  GNU_TYPE
@@ -8472,7 +8494,7 @@ gnat_to_gnu (Node_Id gnat_node)
 	  return slot optimization in this case.
 
        5. If this is a reference to an unconstrained array which is used either
-	  as the prefix of an attribute reference that requires an lvalue or in
+	  as the prefix of an attribute reference for an access attribute or in
 	  a return statement without storage pool, return the result unmodified
 	  because we want to return the original bounds.
 
@@ -8539,7 +8561,7 @@ gnat_to_gnu (Node_Id gnat_node)
   else if (TREE_CODE (TREE_TYPE (gnu_result)) == UNCONSTRAINED_ARRAY_TYPE
 	   && Present (Parent (gnat_node))
 	   && ((Nkind (Parent (gnat_node)) == N_Attribute_Reference
-	        && lvalue_required_for_attribute_p (Parent (gnat_node)))
+	        && access_attribute_p (Parent (gnat_node)))
 	       || (Nkind (Parent (gnat_node)) == N_Simple_Return_Statement
 		   && No (Storage_Pool (Parent (gnat_node))))))
     ;
-- 
2.43.2


  parent reply	other threads:[~2024-05-21  7:31 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-21  7:30 [COMMITTED 01/31] ada: Add new Mingw task priority mapping Marc Poulhiès
2024-05-21  7:30 ` [COMMITTED 02/31] ada: Follow-up fix to previous change for Text_Ptr Marc Poulhiès
2024-05-21  7:30 ` [COMMITTED 03/31] ada: Remove trailing NUL in minimal expansion of Put_Image attribute Marc Poulhiès
2024-05-21  7:30 ` [COMMITTED 04/31] ada: Remove conversion from String_Id to String and back to String_Id Marc Poulhiès
2024-05-21  7:30 ` [COMMITTED 05/31] ada: Do not leak tagged type names when Discard_Names is enabled Marc Poulhiès
2024-05-21  7:30 ` [COMMITTED 06/31] ada: Update documentation of warning messages Marc Poulhiès
2024-05-21  7:30 ` [COMMITTED 07/31] ada: Fix index entry for an implemented AI feature Marc Poulhiès
2024-05-21  7:30 ` [COMMITTED 08/31] ada: Sort list of implemented Ada 2012 features Marc Poulhiès
2024-05-21  7:30 ` [COMMITTED 09/31] ada: Fix formatting in " Marc Poulhiès
2024-05-21  7:30 ` [COMMITTED 10/31] ada: Remove some explicit yields in tasking run-time Marc Poulhiès
2024-05-21  7:30 ` [COMMITTED 11/31] ada: Simplify management of scopes while inlining Marc Poulhiès
2024-05-21  7:30 ` [COMMITTED 12/31] ada: Add elaboration switch tags to info messages Marc Poulhiès
2024-05-21  7:30 ` [COMMITTED 13/31] ada: Remove useless trampolines caused by Unchecked_Conversion Marc Poulhiès
2024-05-21  7:30 ` [COMMITTED 14/31] ada: Remove duplicate statement Marc Poulhiès
2024-05-21  7:30 ` [COMMITTED 15/31] ada: Fix layout in a list of aspects Marc Poulhiès
2024-05-21  7:30 ` [COMMITTED 16/31] ada: Missing constraint check for initial value of object with address clause Marc Poulhiès
2024-05-21  7:30 ` [COMMITTED 17/31] ada: Fix oversight in previous change Marc Poulhiès
2024-05-21  7:30 ` Marc Poulhiès [this message]
2024-05-21  7:30 ` [COMMITTED 19/31] ada: Fix crash on aliased constant with packed array type and -g switch Marc Poulhiès
2024-05-21  7:30 ` [COMMITTED 20/31] ada: Fix assembler error for gigantic library-level object on 64-bit Windows Marc Poulhiès
2024-05-21  7:30 ` [COMMITTED 21/31] ada: Remove unused dependencies from gnatbind object list Marc Poulhiès
2024-05-21  7:30 ` [COMMITTED 22/31] ada: Avoid temporary for conditional expression of discriminated record type Marc Poulhiès
2024-05-21  7:30 ` [COMMITTED 23/31] ada: Follow-up adjustment to earlier fix in Build_Allocate_Deallocate_Proc Marc Poulhiès
2024-05-21  7:30 ` [COMMITTED 24/31] ada: Minor typo fix in comment Marc Poulhiès
2024-05-21  7:30 ` [COMMITTED 25/31] ada: Fix crash with aliased array and if expression Marc Poulhiès
2024-05-21  7:30 ` [COMMITTED 26/31] ada: Fix strict aliasing violation in parameter passing Marc Poulhiès
2024-05-21  7:30 ` [COMMITTED 27/31] ada: Make detection of useless copy for return more robust Marc Poulhiès
2024-05-21  7:30 ` [COMMITTED 28/31] ada: Fix strict aliasing violation in parameter passing (continued) Marc Poulhiès
2024-05-21  7:30 ` [COMMITTED 29/31] ada: Fix internal error on discriminated record with Atomic aspect in Ada 2022 Marc Poulhiès
2024-05-21  7:30 ` [COMMITTED 30/31] ada: Simplify test for propagation of attributes to subtypes Marc Poulhiès
2024-05-21  7:30 ` [COMMITTED 31/31] ada: Streamline implementation of simple nonbinary modular operations Marc Poulhiès

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=20240521073035.314024-18-poulhies@adacore.com \
    --to=poulhies@adacore.com \
    --cc=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).