aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorGhjuvan Lacambre <lacambre@adacore.com>2024-10-18 16:15:04 +0200
committerMarc Poulhiès <dkm@gcc.gnu.org>2024-11-12 14:00:45 +0100
commitca0f0154622c32123c57721b39bc9585119b02d7 (patch)
tree493caeec0ccacd5c5dbda90504cc220e31ae1613 /gcc
parentea497d17c11ee7465140aa13a18a0033ba5a2a27 (diff)
downloadgcc-ca0f0154622c32123c57721b39bc9585119b02d7.zip
gcc-ca0f0154622c32123c57721b39bc9585119b02d7.tar.gz
gcc-ca0f0154622c32123c57721b39bc9585119b02d7.tar.bz2
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.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ada/sem.adb41
1 files changed, 23 insertions, 18 deletions
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;