[Ada] Fix attributes Version and Body_Version for concurrent units

Message ID 20210503092945.GA77575@adacore.com
State New
Headers show
Series
  • [Ada] Fix attributes Version and Body_Version for concurrent units
Related show

Commit Message

Pierre-Marie de Rodat May 3, 2021, 9:29 a.m.
Attributes Version and Body_Version can be prefixed by program units,
which include protected units and task units. Those attributes were
wrongly accepted when prefixed by protected subtype, task subtype and by
any object of a concurrent type.

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

gcc/ada/

	* sem_attr.adb (Check_Program_Unit): Fix references to
	Concurrent_Kind and Is_Concurrent_Type; avoid repeated calls to
	Entity.

Patch

diff --git a/gcc/ada/sem_attr.adb b/gcc/ada/sem_attr.adb
--- a/gcc/ada/sem_attr.adb
+++ b/gcc/ada/sem_attr.adb
@@ -2298,16 +2298,15 @@  package body Sem_Attr is
       begin
          if Is_Entity_Name (P) then
             declare
-               K : constant Entity_Kind := Ekind (Entity (P));
-               T : constant Entity_Id   := Etype (Entity (P));
-
+               E : constant Entity_Id := Entity (P);
             begin
-               if K in Concurrent_Kind
-                     | Entry_Kind
-                     | Generic_Unit_Kind
-                     | Subprogram_Kind
-                     | E_Package
-                 or else (K = E_Variable and then Is_Concurrent_Type (T))
+               if Ekind (E) in E_Protected_Type
+                             | E_Task_Type
+                             | Entry_Kind
+                             | Generic_Unit_Kind
+                             | Subprogram_Kind
+                             | E_Package
+                 or else Is_Single_Concurrent_Object (E)
                then
                   return;
                end if;