[Ada] Spurious accessibility error on "for of" loop parameter

Message ID 20210616084355.GA95313@adacore.com
State New
Headers show
  • [Ada] Spurious accessibility error on "for of" loop parameter
Related show

Commit Message

Pierre-Marie de Rodat June 16, 2021, 8:43 a.m.
This patch fixes an issue in the compiler whereby taking 'Access of a
"for of" loop parameter caused spurious compile-time accessibility

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


	* sem_util.adb (Accessibility_Level): Take into account
	renamings of loop parameters.


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
@@ -664,6 +664,15 @@  package body Sem_Util is
                return Make_Level_Literal
                         (Scope_Depth (Enclosing_Dynamic_Scope (E)) + 1);
+            --  Check if E is an expansion-generated renaming of an iterator
+            --  by examining Related_Expression. If so, determine the
+            --  accessibility level based on the original expression.
+            elsif Ekind (E) in E_Constant | E_Variable
+              and then Present (Related_Expression (E))
+            then
+               return Accessibility_Level (Related_Expression (E));
             --  Normal object - get the level of the enclosing scope