[Ada] Accessibility fix

Message ID 20211109094608.GA830553@adacore.com
State Committed
Commit 51e99ead9197fe4d6a8db8e9746e821abce76213
Headers
Series [Ada] Accessibility fix |

Commit Message

Pierre-Marie de Rodat Nov. 9, 2021, 9:46 a.m. UTC
  This commit fixes an issue where when creating initialization
procedures, GNAT would generate failing accessibility checks because it
would use the scope depth of the parameter of the initialization
procedure instead of using the scope depth passed as parameter.

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

gcc/ada/

	* sem_util.adb (Accessibility_Level): Use init_proc_level_formal
	instead of computing a new accessibility level from Scope_Depth
	(E).
  

Patch

diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb
--- a/gcc/ada/sem_util.adb
+++ b/gcc/ada/sem_util.adb
@@ -744,6 +744,13 @@  package body Sem_Util is
             then
                return Accessibility_Level (Related_Expression (E));
 
+            elsif Level = Dynamic_Level
+               and then Ekind (E) in E_In_Parameter | E_In_Out_Parameter
+               and then Present (Init_Proc_Level_Formal (Scope (E)))
+            then
+               return New_Occurrence_Of
+                        (Init_Proc_Level_Formal (Scope (E)), Loc);
+
             --  Normal object - get the level of the enclosing scope
 
             else