Ignored ghost code should only be semantically analyzed, but as it is
not contributing to any executable code, no restriction violation should
result from analyzing such code. Add protections to that effect in the
analysis of subprogram calls.

Tested on x86_64-pc-linux-gnu, committed on trunk

2019-12-16  Yannick Moy  <m...@adacore.com>

gcc/ada/

        * exp_ch6.adb: Fix comment.
        * sem_res.adb (Resolve_Call): Do not check No_Recursion
        restriction or indirectly No_Secondary_Stack restriction, when
        inside an ignored ghost subprogram.
--- gcc/ada/exp_ch6.adb
+++ gcc/ada/exp_ch6.adb
@@ -6934,8 +6934,8 @@ package body Exp_Ch6 is
       elsif Is_Thunk (Current_Scope) and then Is_Incomplete_Type (Exptyp) then
          return;
 
-      --  A return statement from a Ghost function does not use the secondary
-      --  stack (or any other one).
+      --  A return statement from an ignored Ghost function does not use the
+      --  secondary stack (or any other one).
 
       elsif not Requires_Transient_Scope (R_Type)
         or else Is_Ignored_Ghost_Entity (Scope_Id)

--- gcc/ada/sem_res.adb
+++ gcc/ada/sem_res.adb
@@ -6675,7 +6675,9 @@ package body Sem_Res is
                   --  checkable, the case of calling an immediately containing
                   --  subprogram is easy to catch.
 
-                  Check_Restriction (No_Recursion, N);
+                  if not Is_Ignored_Ghost_Entity (Nam) then
+                     Check_Restriction (No_Recursion, N);
+                  end if;
 
                   --  If the recursive call is to a parameterless subprogram,
                   --  then even if we can't statically detect infinite
@@ -6820,9 +6822,13 @@ package body Sem_Res is
       then
          null;
 
+      --  A return statement from an ignored Ghost function does not use the
+      --  secondary stack (or any other one).
+
       elsif Expander_Active
         and then Ekind_In (Nam, E_Function, E_Subprogram_Type)
         and then Requires_Transient_Scope (Etype (Nam))
+        and then not Is_Ignored_Ghost_Entity (Nam)
       then
          Establish_Transient_Scope (N, Manage_Sec_Stack => True);
 

Reply via email to