From a85dbeec8d84e07ee549fca50dc118234f16d3f1 Mon Sep 17 00:00:00 2001 From: Hristian Kirtchev Date: Thu, 11 Jan 2018 08:55:57 +0000 Subject: [Ada] Prohibit concurrent types in Ghost regions This patch ensures that single concurrent type declarations are marked as Ghost when they appear within a Ghost region. In addition, the patch verifies that no concurrent type is declared within a Ghost region and issues an error. ------------ -- Source -- ------------ -- types.ads package Types with Ghost is protected Prot_Obj is -- Error end Prot_Obj; protected type Prot_Typ is -- Error end Prot_Typ; task Task_Obj; -- Error task type Task_Typ; -- Error end Types; ---------------------------- -- Compilation and output -- ---------------------------- $ gcc -c types.ads types.ads:2:14: ghost type "Prot_Obj" cannot be concurrent types.ads:5:19: ghost type "Prot_Typ" cannot be concurrent types.ads:8:09: ghost type "Task_Obj" cannot be concurrent types.ads:10:14: ghost type "Task_Typ" cannot be concurrent 2018-01-11 Hristian Kirtchev gcc/ada/ * freeze.adb (Freeze_Entity): Ensure that a Ghost type is not concurrent, nor effectively volatile. * ghost.adb (Check_Ghost_Type): New routine. * ghost.ads (Check_Ghost_Type): New routine. * sem_util.adb (Is_Declaration): Reimplemented. The routine can now consider specific subsets of declarations. (Is_Declaration_Other_Than_Renaming): Removed. Its functionality is replicated by Is_Declaration. * sem_util.ads (Is_Declaration): New parameter profile. Update the comment on usage. (Is_Declaration_Other_Than_Renaming): Removed. From-SVN: r256521 --- gcc/ada/ghost.adb | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'gcc/ada/ghost.adb') diff --git a/gcc/ada/ghost.adb b/gcc/ada/ghost.adb index 6dad9c2..5997724 100644 --- a/gcc/ada/ghost.adb +++ b/gcc/ada/ghost.adb @@ -806,6 +806,42 @@ package body Ghost is end if; end Check_Ghost_Refinement; + ---------------------- + -- Check_Ghost_Type -- + ---------------------- + + procedure Check_Ghost_Type (Typ : Entity_Id) is + Conc_Typ : Entity_Id; + Full_Typ : Entity_Id; + + begin + if Is_Ghost_Entity (Typ) then + Conc_Typ := Empty; + Full_Typ := Typ; + + if Is_Single_Concurrent_Type (Typ) then + Conc_Typ := Anonymous_Object (Typ); + Full_Typ := Conc_Typ; + + elsif Is_Concurrent_Type (Typ) then + Conc_Typ := Typ; + end if; + + -- A Ghost type cannot be concurrent (SPARK RM 6.9(19)). Verify this + -- legality rule first to give a finer-grained diagnostic. + + if Present (Conc_Typ) then + Error_Msg_N ("ghost type & cannot be concurrent", Conc_Typ); + end if; + + -- A Ghost type cannot be effectively volatile (SPARK RM 6.9(7)) + + if Is_Effectively_Volatile (Full_Typ) then + Error_Msg_N ("ghost type & cannot be volatile", Full_Typ); + end if; + end if; + end Check_Ghost_Type; + ------------------ -- Ghost_Entity -- ------------------ -- cgit v1.1