diff options
author | Yannick Moy <moy@adacore.com> | 2023-04-11 11:24:32 +0200 |
---|---|---|
committer | Marc Poulhiès <poulhies@adacore.com> | 2023-06-13 09:31:43 +0200 |
commit | 5c266974094ec997a0e83fc763fa4a6ff4b96005 (patch) | |
tree | df9bd143567d8fdb736bc5ca592561900a9b37ff /gcc | |
parent | 416bb154d5c36f25dd6f54fb0d81bf6b0132ee20 (diff) | |
download | gcc-5c266974094ec997a0e83fc763fa4a6ff4b96005.zip gcc-5c266974094ec997a0e83fc763fa4a6ff4b96005.tar.gz gcc-5c266974094ec997a0e83fc763fa4a6ff4b96005.tar.bz2 |
ada: Mark attribute Initialized as ghost code
Implement the SPARK RM change that defines attribute Initialized
as being ghost, i.e. only allowed where a ghost entity would be allowed.
gcc/ada/
* ghost.adb (Check_Ghost_Context): Allow absence of Ghost_Id
for attribute. Update error message to mention Ghost_Predicate.
(Is_Ghost_Attribute_Reference): New query.
* ghost.ads (Is_Ghost_Attribute_Reference): New query.
* sem_attr.adb (Resolve_Attribute): Check ghost context for ghost
attributes.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ada/ghost.adb | 15 | ||||
-rw-r--r-- | gcc/ada/ghost.ads | 4 | ||||
-rw-r--r-- | gcc/ada/sem_attr.adb | 7 |
3 files changed, 25 insertions, 1 deletions
diff --git a/gcc/ada/ghost.adb b/gcc/ada/ghost.adb index ee98126..6cf87ce 100644 --- a/gcc/ada/ghost.adb +++ b/gcc/ada/ghost.adb @@ -655,7 +655,9 @@ package body Ghost is -- declaration and at the point of use match. if Is_OK_Ghost_Context (Ghost_Ref) then - Check_Ghost_Policy (Ghost_Id, Ghost_Ref); + if Present (Ghost_Id) then + Check_Ghost_Policy (Ghost_Id, Ghost_Ref); + end if; -- Otherwise the Ghost entity appears in a non-Ghost context and affects -- its behavior or value (SPARK RM 6.9(10,11)). @@ -673,6 +675,7 @@ package body Ghost is Ghost_Ref); Error_Msg_N ("\either make the type ghost " + & "or use a Ghost_Predicate " & "or use a type invariant on a private type", Ghost_Ref); end if; end if; @@ -1194,6 +1197,16 @@ package body Ghost is return False; end Is_Ghost_Assignment; + ---------------------------------- + -- Is_Ghost_Attribute_Reference -- + ---------------------------------- + + function Is_Ghost_Attribute_Reference (N : Node_Id) return Boolean is + begin + return Nkind (N) = N_Attribute_Reference + and then Attribute_Name (N) = Name_Initialized; + end Is_Ghost_Attribute_Reference; + -------------------------- -- Is_Ghost_Declaration -- -------------------------- diff --git a/gcc/ada/ghost.ads b/gcc/ada/ghost.ads index 1532117..663e70c 100644 --- a/gcc/ada/ghost.ads +++ b/gcc/ada/ghost.ads @@ -111,6 +111,10 @@ package Ghost is -- Determine whether arbitrary node N denotes an assignment statement whose -- target is a Ghost entity. + function Is_Ghost_Attribute_Reference (N : Node_Id) return Boolean; + -- Determine whether arbitrary node N denotes an attribute reference which + -- denotes a Ghost attribute. + function Is_Ghost_Declaration (N : Node_Id) return Boolean; -- Determine whether arbitrary node N denotes a declaration which defines -- a Ghost entity. diff --git a/gcc/ada/sem_attr.adb b/gcc/ada/sem_attr.adb index f5ee275..24f57ac 100644 --- a/gcc/ada/sem_attr.adb +++ b/gcc/ada/sem_attr.adb @@ -41,6 +41,7 @@ with Exp_Dist; use Exp_Dist; with Exp_Util; use Exp_Util; with Expander; use Expander; with Freeze; use Freeze; +with Ghost; use Ghost; with Gnatvsn; use Gnatvsn; with Itypes; use Itypes; with Lib; use Lib; @@ -11068,6 +11069,12 @@ package body Sem_Attr is Set_Etype (N, Typ); end if; + -- A Ghost attribute must appear in a specific context + + if Is_Ghost_Attribute_Reference (N) then + Check_Ghost_Context (Empty, N); + end if; + -- Remaining processing depends on attribute case Attr_Id is |