aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorPiotr Trojanek <trojanek@adacore.com>2021-01-05 23:54:09 +0100
committerPierre-Marie de Rodat <derodat@adacore.com>2021-05-04 05:17:31 -0400
commit0a272ac33f4baa3f616718aa9168dded33cde21b (patch)
tree5140966992e83a3f5e87a246a041b9d6dac6dd8d /gcc
parent43758c2cffeaa2eddd46ead7224a3dda24cab48f (diff)
downloadgcc-0a272ac33f4baa3f616718aa9168dded33cde21b.zip
gcc-0a272ac33f4baa3f616718aa9168dded33cde21b.tar.gz
gcc-0a272ac33f4baa3f616718aa9168dded33cde21b.tar.bz2
[Ada] Reject constants of access-to-variable type as function globals
gcc/ada/ * sem_prag.adb (Analyze_Global_Item): Take subprogram kind into account when accepting or rejecting a constant of an access-to-variable type as a global Output/In_Out; do this check inside an ELSIF branch to avoid unnecessary evaluation of the subsequent condition.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ada/sem_prag.adb30
1 files changed, 22 insertions, 8 deletions
diff --git a/gcc/ada/sem_prag.adb b/gcc/ada/sem_prag.adb
index 2e747ef..e175206 100644
--- a/gcc/ada/sem_prag.adb
+++ b/gcc/ada/sem_prag.adb
@@ -2450,17 +2450,31 @@ package body Sem_Prag is
-- Constant related checks
- elsif Ekind (Item_Id) = E_Constant
- and then not Is_Access_Type (Etype (Item_Id))
- then
+ elsif Ekind (Item_Id) = E_Constant then
- -- Unless it is of an access type, a constant is a read-only
- -- item, therefore it cannot act as an output.
+ -- Constant is a read-only item, therefore it cannot act as
+ -- an output.
if Global_Mode in Name_In_Out | Name_Output then
- SPARK_Msg_NE
- ("constant & cannot act as output", Item, Item_Id);
- return;
+
+ -- Constant of a access-to-variable type is a read-write
+ -- item in procedures, generic procedures, protected
+ -- entries and tasks.
+
+ if Is_Access_Variable (Etype (Item_Id))
+ and then (Ekind (Spec_Id) in E_Entry
+ | E_Entry_Family
+ | E_Procedure
+ | E_Generic_Procedure
+ | E_Task_Type
+ or else Is_Single_Task_Object (Spec_Id))
+ then
+ null;
+ else
+ SPARK_Msg_NE
+ ("constant & cannot act as output", Item, Item_Id);
+ return;
+ end if;
end if;
-- Loop parameter related checks