Ada: Fix bogus warning for array variable on the LHS of aggregate assignment

That's another ancient issue with -gnatwu, but the fix is again trivial.

gcc/ada/
	PR ada/105212
	* exp_aggr.adb (Build_Array_Aggr_Code): If the aggregate comes from
	source, call Set_Referenced_Modified on the target.

gcc/testsuite/
	* gnat.dg/warn36.adb: New test.
This commit is contained in:
Eric Botcazou
2026-04-15 19:37:54 +02:00
parent 60c705cd0e
commit 7cd246560f
2 changed files with 22 additions and 0 deletions

View File

@@ -2026,6 +2026,16 @@ package body Exp_Aggr is
end;
end if;
-- Set Referenced_As_LHS if appropriate. We are neither interested
-- in compiler-generated aggregates, nor in references outside the
-- extended main source unit.
if Comes_From_Source (N)
and then In_Extended_Main_Source_Unit (Into)
then
Set_Referenced_Modified (Into, Out_Param => False);
end if;
-- First before we start, a special case. If we have a bit packed
-- array represented as a modular type, then clear the value to
-- zero first, to ensure that unused bits are properly cleared.

View File

@@ -0,0 +1,12 @@
-- { dg-do compile }
-- { dg-options "-gnatwu" }
procedure Warn36 is
type Arr is array (1 .. 65) of Integer;
A : Arr;
begin
A := (others => 1);
end;