diff mbox series

[Ada] Fix PR ada/116430

Message ID 2521834.XAFRqVoOGU@fomalhaut
State New
Headers show
Series [Ada] Fix PR ada/116430 | expand

Commit Message

Eric Botcazou Oct. 4, 2024, 9:29 a.m. UTC
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  <ebotcazou@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.
diff mbox series

Patch

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);