https://gcc.gnu.org/g:7363d73e26351f42406f7ae31e985768e9a1109a
commit r14-10744-g7363d73e26351f42406f7ae31e985768e9a1109a Author: Eric Botcazou <ebotca...@adacore.com> Date: Fri Oct 4 11:27:33 2024 +0200 Fix crash with subunit of local package This is a regression present on the 14 branch only: the expander gets confused when trying to insert the finalizer of a procedure that contains a package as a subunit. The offending code no longer exists on the mainline so this adds the minimal fix to address the issue. gcc/ada PR ada/116430 * exp_ch7.adb (Build_Finalizer.Create_Finalizer): For the insertion point of the finalizer, deal with package bodies that are subunits. Diff: --- gcc/ada/exp_ch7.adb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/gcc/ada/exp_ch7.adb b/gcc/ada/exp_ch7.adb index e594a5342445..123abb632894 100644 --- a/gcc/ada/exp_ch7.adb +++ b/gcc/ada/exp_ch7.adb @@ -2051,6 +2051,12 @@ package body Exp_Ch7 is and then List_Containing (Finalizer_Insert_Nod) = Stmts) then Finalizer_Insert_Nod := Last_Top_Level_Ctrl_Construct; + if Nkind (Finalizer_Insert_Nod) = N_Package_Body + and then Nkind (Parent (Finalizer_Insert_Nod)) = N_Subunit + then + Finalizer_Insert_Nod := + Corresponding_Stub (Parent (Finalizer_Insert_Nod)); + end if; end if; Insert_After (Finalizer_Insert_Nod, Fin_Body);