* [Ada] Reject constants of access-to-variable type as function globals
@ 2021-05-04 9:52 Pierre-Marie de Rodat
0 siblings, 0 replies; only message in thread
From: Pierre-Marie de Rodat @ 2021-05-04 9:52 UTC (permalink / raw)
To: gcc-patches; +Cc: Piotr Trojanek
[-- Attachment #1: Type: text/plain, Size: 468 bytes --]
Constants of an access-to-variable type can only appear as global
outputs in procedures, tasks and protected entries, not in functions.
Tested on x86_64-pc-linux-gnu, committed on trunk
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.
[-- Attachment #2: patch.diff --]
[-- Type: text/x-diff, Size: 1895 bytes --]
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
@@ -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
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2021-05-04 9:52 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-04 9:52 [Ada] Reject constants of access-to-variable type as function globals Pierre-Marie de Rodat
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).