public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [COMMITTED] ada: Allow attributes like First and Last to be read in Exceptional_Cases
@ 2023-05-29  8:29 Marc Poulhiès
  0 siblings, 0 replies; only message in thread
From: Marc Poulhiès @ 2023-05-29  8:29 UTC (permalink / raw)
  To: gcc-patches; +Cc: Piotr Trojanek

From: Piotr Trojanek <trojanek@adacore.com>

Attributes that do not read data from the object can be safely used in
consequences of Exceptional_Cases regardless of the parameter passing
mode.

gcc/ada/

	* sem_res.adb (Resolve_Entity_Name): Relax rules for Exceptional_Cases.

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

---
 gcc/ada/sem_res.adb | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/gcc/ada/sem_res.adb b/gcc/ada/sem_res.adb
index a31077a5f33..6d4bef8d38e 100644
--- a/gcc/ada/sem_res.adb
+++ b/gcc/ada/sem_res.adb
@@ -8117,11 +8117,19 @@ package body Sem_Res is
             --  Parameters of modes OUT or IN OUT of the subprogram shall not
             --  occur in the consequences of an exceptional contract unless
             --  they are either passed by reference or occur in the prefix
-            --  of a reference to the 'Old attribute.
+            --  of a reference to the 'Old attribute. For convenience, we also
+            --  allow them as prefixes of attributes that do not actually read
+            --  data from the object.
 
             if Ekind (E) in E_Out_Parameter | E_In_Out_Parameter
               and then Within_Exceptional_Cases_Consequence (N)
               and then not In_Attribute_Old (N)
+              and then not (Nkind (Parent (N)) = N_Attribute_Reference
+                              and then
+                            Attribute_Name (Parent (N)) in Name_Constrained
+                                                         | Name_First
+                                                         | Name_Last
+                                                         | Name_Length)
               and then not Is_By_Reference_Type (Etype (E))
               and then not Is_Aliased (E)
             then
-- 
2.40.0


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-05-29  8:29 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-29  8:29 [COMMITTED] ada: Allow attributes like First and Last to be read in Exceptional_Cases Marc Poulhiès

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