[COMMITTED] ada: Fix handling of Global contracts inside generic subprograms

Message ID 20230526073618.2068882-1-poulhies@adacore.com
State Committed
Commit fd3eff65551876a04febca1621d7d19f9390aab6
Headers
Series [COMMITTED] ada: Fix handling of Global contracts inside generic subprograms |

Commit Message

Marc Poulhiès May 26, 2023, 7:36 a.m. UTC
  From: Piotr Trojanek <trojanek@adacore.com>

Routine Get_Argument works differently for generic units (as explained
in its comment), but it failed to reliably detect such units when their
kind is temporarily made non-generic (for resolving recursive calls, as
explained in the comment at the end of Is_Generic_Declaration_Or_Body).

With this patch the frontend will look at the decorated expression of
the Global contract attached to the Global aspect; previously it was
looking at the undecorated expression attached to the corresponding
pragma.

gcc/ada/

	* sem_prag.adb (Get_Argument): Improve detection of generic units.

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

---
 gcc/ada/sem_prag.adb | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
  

Patch

diff --git a/gcc/ada/sem_prag.adb b/gcc/ada/sem_prag.adb
index d66e5612135..96ea17209f3 100644
--- a/gcc/ada/sem_prag.adb
+++ b/gcc/ada/sem_prag.adb
@@ -31650,7 +31650,9 @@  package body Sem_Prag is
       --  to save the global references in the generic context.
 
       if From_Aspect_Specification (Prag)
-        and then (Present (Context_Id) and then Is_Generic_Unit (Context_Id))
+        and then Present (Context_Id)
+        and then
+          Is_Generic_Declaration_Or_Body (Unit_Declaration_Node (Context_Id))
       then
          return Corresponding_Aspect (Prag);