From ca0f0154622c32123c57721b39bc9585119b02d7 Mon Sep 17 00:00:00 2001 From: Ghjuvan Lacambre Date: Fri, 18 Oct 2024 16:15:04 +0200 Subject: ada: sem.adb.process_bodies_in_context: check if spec has lib body before use Inspector testing shows that calling Body_Lib_Unit on Spec can sometimes fail due to the following assertion failing: pragma Assert (Unit (N) in N_Lib_Unit_Declaration_Id | N_Lib_Unit_Renaming_Declaration_Id); Indeed, Unit (N) may sometimes be an N_Subprogram_Body instead of an N_Lib_Unit_Declaration_Id. gcc/ada/ChangeLog: * sem.adb (Process_Bodies_In_Context): check that Spec's unit is an N_Lib_Unit_Declaration_Id. --- gcc/ada/sem.adb | 41 +++++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 18 deletions(-) (limited to 'gcc') diff --git a/gcc/ada/sem.adb b/gcc/ada/sem.adb index fd52e3a..cfd0493 100644 --- a/gcc/ada/sem.adb +++ b/gcc/ada/sem.adb @@ -2123,27 +2123,32 @@ package body Sem is while Present (Clause) loop if Nkind (Clause) = N_With_Clause then Spec := Withed_Lib_Unit (Clause); - Body_CU := Body_Lib_Unit (Spec); - - -- If we are processing the spec of the main unit, load bodies - -- only if the with_clause indicates that it forced the loading - -- of the body for a generic instantiation. Note that bodies of - -- parents that are instances have been loaded already. - - if Present (Body_CU) - and then Body_CU /= Main_CU - and then Nkind (Unit (Body_CU)) /= N_Subprogram_Body - and then Nkind (Unit (Comp)) /= N_Package_Declaration + if Unit (Spec) in N_Lib_Unit_Declaration_Id + | N_Lib_Unit_Renaming_Declaration_Id then - Body_U := Get_Cunit_Unit_Number (Body_CU); + Body_CU := Body_Lib_Unit (Spec); - if not Seen (Body_U) - and then not Depends_On_Main (Body_CU) + -- If we are processing the spec of the main unit, load + -- bodies only if the with_clause indicates that it forced + -- the loading of the body for a generic instantiation. + -- Note that bodies of parents that are instances have been + -- loaded already. + + if Present (Body_CU) + and then Body_CU /= Main_CU + and then Nkind (Unit (Body_CU)) /= N_Subprogram_Body + and then Nkind (Unit (Comp)) /= N_Package_Declaration then - Seen (Body_U) := True; - Do_Withed_Units (Body_CU, Include_Limited => False); - Do_Action (Body_CU, Unit (Body_CU)); - Done (Body_U) := True; + Body_U := Get_Cunit_Unit_Number (Body_CU); + + if not Seen (Body_U) + and then not Depends_On_Main (Body_CU) + then + Seen (Body_U) := True; + Do_Withed_Units (Body_CU, Include_Limited => False); + Do_Action (Body_CU, Unit (Body_CU)); + Done (Body_U) := True; + end if; end if; end if; end if; -- cgit v1.1