diff mbox series

[COMMITTED,27/35] ada: Bug in computing local restrictions inherited from enclosing scopes.

Message ID 20240517083207.130391-27-poulhies@adacore.com
State New
Headers show
Series [COMMITTED,01/35] ada: Add support for 'Object_Size to pragma Compile_Time_{Warning, Error} | expand

Commit Message

Marc Poulhiès May 17, 2024, 8:31 a.m. UTC
From: Steve Baird <baird@adacore.com>

In the function Local_Restrict.Active_Restriction, we traverse enclosing
scopes looking for a relevant Local_Restrictions aspect specification.
Fix a bug in this traversal.

gcc/ada/

	* local_restrict.adb (Active_Restriction): When traversing scopes,
	do not skip over a subprogram body.

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

---
 gcc/ada/local_restrict.adb | 32 +++++++++++++++++++-------------
 1 file changed, 19 insertions(+), 13 deletions(-)
diff mbox series

Patch

diff --git a/gcc/ada/local_restrict.adb b/gcc/ada/local_restrict.adb
index 6e91c8a2e2a..3be94049928 100644
--- a/gcc/ada/local_restrict.adb
+++ b/gcc/ada/local_restrict.adb
@@ -90,22 +90,28 @@  package body Local_Restrict is
             return Result;
          end if;
 
-         Scop := Enclosing_Declaration (Scop);
-         if Present (Scop) then
-            Scop := Parent (Scop);
+         declare
+            Saved_Scope : constant Node_Id := Scop;
+         begin
+            Scop := Enclosing_Declaration (Scop);
             if Present (Scop) then
-               --  For a subprogram associated with a type, we don't care
-               --  where the type was frozen; continue from the type.
-
-               if Nkind (Scop) = N_Freeze_Entity then
-                  Scop := Scope (Entity (Scop));
-               elsif Nkind (Parent (Scop)) = N_Freeze_Entity then
-                  Scop := Scope (Entity (Parent (Scop)));
-               else
-                  Scop := Find_Enclosing_Scope (Scop);
+               Scop := Parent (Scop);
+               if Present (Scop) then
+                  --  For a subprogram associated with a type, we don't care
+                  --  where the type was frozen; continue from the type.
+
+                  if Nkind (Scop) = N_Freeze_Entity then
+                     Scop := Scope (Entity (Scop));
+                  elsif Nkind (Parent (Scop)) = N_Freeze_Entity then
+                     Scop := Scope (Entity (Parent (Scop)));
+                  elsif Present (Scope (Saved_Scope)) then
+                     Scop := Scope (Saved_Scope);
+                  else
+                     Scop := Find_Enclosing_Scope (Scop);
+                  end if;
                end if;
             end if;
-         end if;
+         end;
       end loop;
 
       return Empty;