diff mbox series

[COMMITTED] ada: Fix small inaccuracy in previous change

Message ID 20240514082357.834344-1-poulhies@adacore.com
State New
Headers show
Series [COMMITTED] ada: Fix small inaccuracy in previous change | expand

Commit Message

Marc Poulhiès May 14, 2024, 8:23 a.m. UTC
From: Eric Botcazou <ebotcazou@adacore.com>

The call to Build_Allocate_Deallocate_Proc must occur before the special
accessibility check for class-wide allocation is generated, because this
check comes with cleanup code.

gcc/ada/

	* exp_ch4.adb (Expand_Allocator_Expression): Move the first call to
	Build_Allocate_Deallocate_Proc up to before the accessibility check.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/exp_ch4.adb | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/gcc/ada/exp_ch4.adb b/gcc/ada/exp_ch4.adb
index b1f7593de2a..762e75616a7 100644
--- a/gcc/ada/exp_ch4.adb
+++ b/gcc/ada/exp_ch4.adb
@@ -960,12 +960,18 @@  package body Exp_Ch4 is
             end if;
          end if;
 
+         --  This needs to done before generating the accessibility check below
+         --  because the check comes with cleanup code that invokes Free on the
+         --  temporary and, therefore, expects the object to be attached to its
+         --  finalization collection if it is controlled.
+
+         Build_Allocate_Deallocate_Proc (Declaration_Node (Temp), Mark => N);
+
          --  Note: the accessibility check must be inserted after the call to
          --  [Deep_]Adjust to ensure proper completion of the assignment.
 
          Apply_Accessibility_Check_For_Allocator (N, Exp, Temp);
 
-         Build_Allocate_Deallocate_Proc (Declaration_Node (Temp), Mark => N);
          Rewrite (N, New_Occurrence_Of (Temp, Loc));
          Analyze_And_Resolve (N, PtrT);