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.

Tested on x86-64/Linux, applied on the 14 branch only.


2024-10-04  Eric Botcazou  <ebotca...@adacore.com>

        PR ada/116430
        * exp_ch7.adb (Build_Finalizer.Create_Finalizer): For the insertion
        point of the finalizer, deal with package bodies that are subunits.

-- 
Eric Botcazou
diff --git a/gcc/ada/exp_ch7.adb b/gcc/ada/exp_ch7.adb
index e594a534244..123abb63289 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);

Reply via email to