[COMMITTED] ada: Cannot requeue to a procedure implemented by an entry

Message ID 20240109131545.744441-1-poulhies@adacore.com
State Accepted
Headers
Series [COMMITTED] ada: Cannot requeue to a procedure implemented by an entry |

Checks

Context Check Description
snail/gcc-patch-check success Github commit url

Commit Message

Marc Poulhiès Jan. 9, 2024, 1:15 p.m. UTC
  From: Javier Miranda <miranda@adacore.com>

Add missing support for RM 9.5.4(5.6/4): the target of a requeue
statement may be a procedure when its name denotes a renaming of
an entry.

gcc/ada/

	* sem_ch6.adb (Analyze_Subprogram_Specification): Do not replace
	the type of the formals with its corresponding record in
	init-procs.
	* sem_ch9.adb (Analyze_Requeue): Add missing support to requeue to
	a procedure that denotes a renaming of an entry.

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

---
 gcc/ada/sem_ch6.adb |  1 +
 gcc/ada/sem_ch9.adb | 26 ++++++++++++++++++++++++++
 2 files changed, 27 insertions(+)
  

Patch

diff --git a/gcc/ada/sem_ch6.adb b/gcc/ada/sem_ch6.adb
index bdfe446d014..8a7dfef9019 100644
--- a/gcc/ada/sem_ch6.adb
+++ b/gcc/ada/sem_ch6.adb
@@ -5373,6 +5373,7 @@  package body Sem_Ch6 is
 
          if Ada_Version >= Ada_2005
            and then not Is_Invariant_Procedure_Or_Body (Designator)
+           and then not Is_Init_Proc (Designator)
          then
             declare
                Formal     : Entity_Id;
diff --git a/gcc/ada/sem_ch9.adb b/gcc/ada/sem_ch9.adb
index 365887cbe14..8e6ba4c6b81 100644
--- a/gcc/ada/sem_ch9.adb
+++ b/gcc/ada/sem_ch9.adb
@@ -2438,6 +2438,32 @@  package body Sem_Ch9 is
          Entry_Name := Selector_Name (Entry_Name);
       end if;
 
+      --  Ada 2012 (9.5.4(5.6/4): "If the target is a procedure, the name
+      --  shall denote a renaming of an entry or ...". We support this
+      --  language rule replacing the target procedure with the renamed
+      --  entry. Thus, reanalyzing the resulting requeue statement we
+      --  reuse all the Ada 2005 machinery to perform the analysis.
+
+      if Nkind (Entry_Name) in N_Has_Entity then
+         declare
+            Target_E : constant Entity_Id := Entity (Entry_Name);
+
+         begin
+            if Ada_Version >= Ada_2012
+              and then Ekind (Target_E) = E_Procedure
+              and then Convention (Target_E) = Convention_Entry
+              and then Nkind (Original_Node (Parent (Parent (Target_E))))
+                         = N_Subprogram_Renaming_Declaration
+            then
+               Set_Name (N,
+                 New_Copy_Tree
+                   (Name (Original_Node (Parent (Parent (Target_E))))));
+               Analyze_Requeue (N);
+               return;
+            end if;
+         end;
+      end if;
+
       --  If an explicit target object is given then we have to check the
       --  restrictions of 9.5.4(6).