[Ada] Guard against illegal items in Global but not Depends
authorPiotr Trojanek <trojanek@adacore.com>
Mon, 25 Oct 2021 14:33:24 +0000 (16:33 +0200)
committerPierre-Marie de Rodat <derodat@adacore.com>
Tue, 9 Nov 2021 09:44:46 +0000 (09:44 +0000)
gcc/ada/

* sem_prag.adb (Check_Usage): Guard against calling Usage_Error
with illegal Item_Id. The intention to do this was already
described in the comment but not implemented.

gcc/ada/sem_prag.adb

index 10ad82f..1c04814 100644 (file)
@@ -1684,7 +1684,15 @@ package body Sem_Prag is
                --  States and global objects are not used properly only when
                --  the subprogram is subject to pragma Global.
 
-               elsif Global_Seen then
+               elsif Global_Seen
+                 and then Ekind (Item_Id) in E_Abstract_State
+                                           | E_Constant
+                                           | E_Loop_Parameter
+                                           | E_Protected_Type
+                                           | E_Task_Type
+                                           | E_Variable
+                                           | Formal_Kind
+               then
                   Usage_Error (Item_Id);
                end if;
             end if;