]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
[Ada] Spurious accessibility error on renamed expression
authorJustin Squirek <squirek@adacore.com>
Wed, 18 Aug 2021 03:12:00 +0000 (23:12 -0400)
committerPierre-Marie de Rodat <derodat@adacore.com>
Mon, 4 Oct 2021 08:45:04 +0000 (08:45 +0000)
gcc/ada/

* sem_util.adb (Accessibility_Level): Add a case to handle
renamed subprograms in addition to renamed objects.

gcc/ada/sem_util.adb

index 70ab0d6d91da2cfd51e82eb9c7b39c6a210ba423..ba0341e70c71c8d53cd5a1e6f73369e54c929a92 100644 (file)
@@ -713,15 +713,25 @@ package body Sem_Util is
 
                return Make_Level_Literal (Typ_Access_Level (E) + 1);
 
-            --  Move up the renamed entity if it came from source since
-            --  expansion may have created a dummy renaming under certain
-            --  circumstances.
+            --  Move up the renamed entity or object if it came from source
+            --  since expansion may have created a dummy renaming under
+            --  certain circumstances.
+
+            --  Note: We check if the original node of the renaming comes
+            --  from source because the node may have been rewritten.
 
             elsif Present (Renamed_Object (E))
-              and then Comes_From_Source (Renamed_Object (E))
+              and then Comes_From_Source (Original_Node (Renamed_Object (E)))
             then
                return Accessibility_Level (Renamed_Object (E));
 
+            --  Move up renamed entities
+
+            elsif Present (Renamed_Entity (E))
+              and then Comes_From_Source (Original_Node (Renamed_Entity (E)))
+            then
+               return Accessibility_Level (Renamed_Entity (E));
+
             --  Named access types get their level from their associated type
 
             elsif Is_Named_Access_Type (Etype (E)) then