diff options
author | Viljar Indus <indus@adacore.com> | 2025-08-21 12:14:08 +0300 |
---|---|---|
committer | Marc Poulhiès <dkm@gcc.gnu.org> | 2025-09-11 11:10:49 +0200 |
commit | 4183b13f048bec3985799a2aa4fe94f9770c7070 (patch) | |
tree | f32edf7a748e2a147d73cb3b612ea951c554a56b | |
parent | 6989e0f3f837a96a4629d0a22b12de00d6438996 (diff) | |
download | gcc-4183b13f048bec3985799a2aa4fe94f9770c7070.zip gcc-4183b13f048bec3985799a2aa4fe94f9770c7070.tar.gz gcc-4183b13f048bec3985799a2aa4fe94f9770c7070.tar.bz2 |
ada: Check instantces of ghost iterator functions
Since we do not analyze the policy errors for expanded code we need to
check the functions specified in the Iterable aspect whenever we are
analyzing an iterator spcification with that aspect.
gcc/ada/ChangeLog:
* sem_ch5.adb (Analyze_Iterator_Specification): Check ghost context
of Iterable functions when handling iterator specifications with an
Iterable aspect.
-rw-r--r-- | gcc/ada/sem_ch5.adb | 31 |
1 files changed, 25 insertions, 6 deletions
diff --git a/gcc/ada/sem_ch5.adb b/gcc/ada/sem_ch5.adb index 1db5b75..a767ee0 100644 --- a/gcc/ada/sem_ch5.adb +++ b/gcc/ada/sem_ch5.adb @@ -2160,7 +2160,10 @@ package body Sem_Ch5 is Loc : constant Source_Ptr := Sloc (N); Subt : constant Node_Id := Subtype_Indication (N); + Assoc : Node_Id; Bas : Entity_Id := Empty; -- initialize to prevent warning + Iter_Asp : Node_Id; + Iter_Func : Node_Id; Typ : Entity_Id; procedure Check_Reverse_Iteration (Typ : Entity_Id); @@ -2870,12 +2873,9 @@ package body Sem_Ch5 is -- in the container package. We obtain it by name for a predefined -- container, or through the Iterable aspect for a formal one. - if Has_Aspect (Typ, Aspect_Iterable) then - Set_Etype (Def_Id, - Get_Cursor_Type - (Parent (Find_Value_Of_Aspect (Typ, Aspect_Iterable)), - Typ)); - + Iter_Asp := Find_Aspect (Typ, Aspect_Iterable); + if Present (Iter_Asp) then + Set_Etype (Def_Id, Get_Cursor_Type (Iter_Asp, Typ)); else Set_Etype (Def_Id, Get_Cursor_Type (Typ)); Check_Reverse_Iteration (Etype (Iter_Name)); @@ -2884,6 +2884,25 @@ package body Sem_Ch5 is end if; end if; + -- Validate the ghost context of he iterator function used for the + -- iterable aspect. + + Iter_Asp := Find_Aspect (Typ, Aspect_Iterable); + if Present (Iter_Asp) then + Assoc := First (Component_Associations (Expression (Iter_Asp))); + while Present (Assoc) loop + Iter_Func := Expression (Assoc); + if Nkind (Iter_Func) in N_Has_Entity + and then Present (Entity (Iter_Func)) + and then Is_Ghost_Entity (Entity (Iter_Func)) + then + Check_Ghost_Context (Entity (Iter_Func), Parent (N)); + end if; + + Next (Assoc); + end loop; + end if; + -- Preanalyze the filter. Expansion will take place when enclosing -- loop is expanded. |