https://gcc.gnu.org/g:c8d4f10ab64e23d0418d15315dbec0c6d3949322
commit r17-1297-gc8d4f10ab64e23d0418d15315dbec0c6d3949322 Author: Viljar Indus <[email protected]> Date: Thu May 7 14:40:50 2026 +0300 ada: Fix checking context of Initialized attribute 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. Diff: --- 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 afa6b97947f4..b356bed9d40f 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;
