From: Viljar Indus <[email protected]>
The initialized attribute is a special attribute that can only
be used in places where ghost code can be used.
However in those cases we have no ghost entity to check. Add
guards for this situation inside Check_Ghost_Context.Is_OK_Statement.
gcc/ada/ChangeLog:
* ghost.adb (Is_OK_Statement): Avoid checking for policies and
levels when checking the context of the Initialized attribute.
Tested on x86_64-pc-linux-gnu, committed on master.
---
gcc/ada/ghost.adb | 21 ++++++++++++++++++---
1 file changed, 18 insertions(+), 3 deletions(-)
diff --git a/gcc/ada/ghost.adb b/gcc/ada/ghost.adb
index afa6b97947f..b356bed9d40 100644
--- a/gcc/ada/ghost.adb
+++ b/gcc/ada/ghost.adb
@@ -628,8 +628,15 @@ package body Ghost is
if Nkind (Stmt) = N_Assignment_Statement then
if Is_Ghost_Assignment (Stmt) then
- Check_Assignment_Levels
- (Get_Enclosing_Ghost_Entity (Name (Stmt)));
+ -- No Id is present when checking the context of the
+ -- Initialized attribute that can only appear in ghost
+ -- context. However we do not need to check the assertion
+ -- levels in this case.
+
+ if Present (Id) then
+ Check_Assignment_Levels
+ (Get_Enclosing_Ghost_Entity (Name (Stmt)));
+ end if;
return True;
end if;
@@ -637,7 +644,15 @@ package body Ghost is
elsif Nkind (Stmt) = N_Procedure_Call_Statement then
if Is_Ghost_Procedure_Call (Stmt) then
- Check_Procedure_Call_Policies (Get_Subprogram_Entity (Stmt));
+ -- No Id is present when checking the context of the
+ -- Initialized attribute that can only appear in ghost
+ -- context. However we do not need to check the policies nor
+ -- the assertion levels in this case.
+
+ if Present (Id) then
+ Check_Procedure_Call_Policies
+ (Get_Subprogram_Entity (Stmt));
+ end if;
return True;
end if;
--
2.53.0