diff --git a/gcc/ada/accessibility.adb b/gcc/ada/accessibility.adb
index b808e88b128add7a5b6ffd91c6c02b47b13db179..8c85173aa34cd0232bb462b47928b3670ce1faaf 100644
--- a/gcc/ada/accessibility.adb
+++ b/gcc/ada/accessibility.adb
@@ -187,6 +187,15 @@ package body Accessibility is
                  or else (Nkind (Node_Par) = N_Object_Renaming_Declaration
                            and then Comes_From_Iterator (Node_Par))
                then
+                  --  Handle the case of expressions within library level
+                  --  subprograms here by adding one to the level modifier.
+
+                  if Encl_Scop = Standard_Standard
+                    and then Nkind (Node_Par) = N_Subprogram_Body
+                  then
+                     Master_Lvl_Modifier := Master_Lvl_Modifier + 1;
+                  end if;
+
                   --  Note that in some rare cases the scope depth may not be
                   --  set, for example, when we are in the middle of analyzing
                   --  a type and the enclosing scope is said type. In that case