]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Tweak special handling of synchronized type scopes
authorRonan Desplanques <desplanques@adacore.com>
Wed, 2 Apr 2025 08:48:57 +0000 (10:48 +0200)
committerEric Botcazou <ebotcazou@adacore.com>
Thu, 12 Jun 2025 11:02:38 +0000 (13:02 +0200)
Exp_Util.Insert_Actions handles scopes of synchronized types specially,
but the condition it tested before this patch was not quite correct in
some cases, for example during some expansion operations made under
Expand_N_Task_Type_Declaration. This patch refines the test.

gcc/ada/ChangeLog:

* exp_util.adb (Insert_Actions): Refine test.

gcc/ada/exp_util.adb

index 44e26d19a84de2472d95af380f40ddd06ef6da85..5fc4ed87358d68c433fab06cd9a86a1f1ee4d8cd 100644 (file)
@@ -8223,19 +8223,31 @@ package body Exp_Util is
                   return;
                end if;
 
-            --  the expansion of Task and protected type declarations can
+            --  The expansion of task and protected type declarations can
             --  create declarations for temporaries which, like other actions
-            --  are inserted and analyzed before the current declaraation.
-            --  However, the current scope is the synchronized type, and
-            --  for unnesting it is critical that the proper scope for these
-            --  generated entities be the enclosing one.
+            --  are inserted and analyzed before the current declaration.
+            --  However, in some cases, the current scope is the synchronized
+            --  type, and for unnesting it is critical that the proper scope
+            --  for these generated entities be the enclosing one.
 
             when N_Task_Type_Declaration
                | N_Protected_Type_Declaration =>
 
-               Push_Scope (Scope (Current_Scope));
-               Insert_List_Before_And_Analyze (P, Ins_Actions);
-               Pop_Scope;
+               declare
+                  Skip_Scope : constant Boolean :=
+                    Ekind (Current_Scope) in Concurrent_Kind;
+               begin
+                  if Skip_Scope then
+                     Push_Scope (Scope (Current_Scope));
+                  end if;
+
+                  Insert_List_Before_And_Analyze (P, Ins_Actions);
+
+                  if Skip_Scope then
+                     Pop_Scope;
+                  end if;
+               end;
+
                return;
 
             --  A special case, N_Raise_xxx_Error can act either as a statement