aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorViljar Indus <indus@adacore.com>2025-08-25 11:52:06 +0300
committerMarc Poulhiès <dkm@gcc.gnu.org>2025-09-11 11:10:49 +0200
commit354a1c35a20662215d282d20b0cdf68796debe7a (patch)
tree7db5a03e88f0c1fe35581a948e33e8bd2cc55331
parent28b38b266d312e85ceae7f1b605eaa5b6583561d (diff)
downloadgcc-354a1c35a20662215d282d20b0cdf68796debe7a.zip
gcc-354a1c35a20662215d282d20b0cdf68796debe7a.tar.gz
gcc-354a1c35a20662215d282d20b0cdf68796debe7a.tar.bz2
ada: Ignore ghost policy errors inside aspect Iterable
It is OK to define a checked ghost type with an iterable aspect that has ignored Iterable functions. gcc/ada/ChangeLog: * ghost.adb (Check_Ghost_Policy): Avoid triggering a ghost policy error if the policy is referenced within the Iterable aspect.
-rw-r--r--gcc/ada/ghost.adb29
1 files changed, 29 insertions, 0 deletions
diff --git a/gcc/ada/ghost.adb b/gcc/ada/ghost.adb
index 0fbcf20..0918d27 100644
--- a/gcc/ada/ghost.adb
+++ b/gcc/ada/ghost.adb
@@ -807,8 +807,28 @@ package body Ghost is
------------------------
procedure Check_Ghost_Policy (Id : Entity_Id; Ref : Node_Id) is
+ function Is_From_Aspect_Iterable (Ref : Node_Id) return Boolean;
+ -- Returns true when the node is contained within an Iterable aspect.
+
+ function Is_From_Aspect_Iterable (Ref : Node_Id) return Boolean is
+ P : Node_Id := Parent (Ref);
+ begin
+ while Present (P) loop
+ if Nkind (P) = N_Aspect_Specification then
+ return Get_Aspect_Id (P) = Aspect_Iterable;
+ end if;
+ P := Parent (P);
+ end loop;
+ return False;
+ end Is_From_Aspect_Iterable;
+
+ -- Local variables
+
Applic_Policy : Ghost_Mode_Type := Ghost_Config.Ghost_Mode;
Ghost_Region : constant Node_Id := Ghost_Config.Current_Region;
+
+ -- Start of processing for Check_Ghost_Policy
+
begin
-- The policy is allowed to change within renaming and instantiation
-- statements.
@@ -844,6 +864,14 @@ package body Ghost is
Error_Msg_NE ("\& used # with ghost policy `Ignore`", Ref, Id);
end if;
+ -- A ghost entity E shall not be referenced within an aspect
+ -- specification [(including an aspect-specifying pragma)] which
+ -- specifies an aspect of an entity that is either non-ghost or not
+ -- assertion-level-dependent on E except in the following cases the
+ -- specified aspect is either Global, Depends, Refined_Global,
+ -- Refined_Depends, Initializes, Refined_State, or Iterable (SPARK RM
+ -- 6.9(15)).
+
if No (Ghost_Region)
or else (Nkind (Ghost_Region) = N_Pragma
and then Get_Pragma_Id (Ghost_Region)
@@ -853,6 +881,7 @@ package body Ghost is
| Pragma_Refined_Depends
| Pragma_Initializes
| Pragma_Refined_State)
+ or else Is_From_Aspect_Iterable (Ref)
then
return;
end if;