[Ada] Fix detection of access-to-variable types

Message ID 20210615102052.GA3974@adacore.com
State New
Headers show
  • [Ada] Fix detection of access-to-variable types
Related show

Commit Message

Pierre-Marie de Rodat June 15, 2021, 10:20 a.m.
Routine Is_Access_Variable, which relied on the Ekind of the type,
wrongly returned True for subtypes of an access-to-subprogram type. It
is more reliable to also use Directly_Designated_Type.

This only affects SPARK legality checks for Global and Depends
contracts; compilation is not affected, because it doesn't rely on the
modified routine.

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


	* sem_prag.adb: Fix typos in comments related to access types.
	* sem_util.adb (Is_Access_Variable): Stronger condition.


diff --git a/gcc/ada/sem_prag.adb b/gcc/ada/sem_prag.adb
--- a/gcc/ada/sem_prag.adb
+++ b/gcc/ada/sem_prag.adb
@@ -2464,7 +2464,7 @@  package body Sem_Prag is
                   if Global_Mode in Name_In_Out | Name_Output then
-                     --  Constant of a access-to-variable type is a read-write
+                     --  Constant of an access-to-variable type is a read-write
                      --  item in procedures, generic procedures, protected
                      --  entries and tasks.
@@ -13431,7 +13431,7 @@  package body Sem_Prag is
                end if;
-            --  Only other possibility is Access-to-class-wide type
+            --  Only other possibility is access-to-class-wide type
             elsif Is_Access_Type (Nm)
               and then Is_Class_Wide_Type (Designated_Type (Nm))

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
@@ -15386,8 +15386,9 @@  package body Sem_Util is
    function Is_Access_Variable (E : Entity_Id) return Boolean is
-      return Is_Access_Object_Type (E)
-        and then not Is_Access_Constant (E);
+      return Is_Access_Type (E)
+        and then not Is_Access_Constant (E)
+        and then Ekind (Directly_Designated_Type (E)) /= E_Subprogram_Type;
    end Is_Access_Variable;