diff mbox series

[COMMITTED,09/30] ada: Missing adjust of controlled component initialized from container aggregate

Message ID 20240801151738.400796-9-poulhies@adacore.com
State New
Headers show
Series [COMMITTED,01/30] ada: Remove obsolete workaround | expand

Commit Message

Marc Poulhiès Aug. 1, 2024, 3:17 p.m. UTC
From: Gary Dismukes <dismukes@adacore.com>

In the case of controlled components initialized by a container aggregate,
the compiler was suppressing the call to the needed Adjust operation,
because it was suppressed for all aggregates. But container aggregates
aren't built in place, so target adjustment should still be done in that
case.

gcc/ada/

	* exp_ch3.adb (Build_Record_Init_Proc.Build_Assignment): Do the
	component adjustment in the case of initialization by a container
	aggregate.

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

---
 gcc/ada/exp_ch3.adb | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/gcc/ada/exp_ch3.adb b/gcc/ada/exp_ch3.adb
index 1eea062210a..6fee2b41bac 100644
--- a/gcc/ada/exp_ch3.adb
+++ b/gcc/ada/exp_ch3.adb
@@ -2700,10 +2700,12 @@  package body Exp_Ch3 is
          end if;
 
          --  Adjust the component if controlled except if it is an aggregate
-         --  that will be expanded inline.
+         --  that will be expanded inline (but note that the case of container
+         --  aggregates does require component adjustment).
 
          if Needs_Finalization (Typ)
-           and then Nkind (Exp_Q) not in N_Aggregate | N_Extension_Aggregate
+           and then (Nkind (Exp_Q) not in N_Aggregate | N_Extension_Aggregate
+                      or else Is_Container_Aggregate (Exp_Q))
            and then not Is_Build_In_Place_Function_Call (Exp)
          then
             Adj_Call :=