]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Ada: Fix bogus warning for array variable on the LHS of aggregate assignment
authorEric Botcazou <ebotcazou@adacore.com>
Wed, 15 Apr 2026 17:37:54 +0000 (19:37 +0200)
committerEric Botcazou <ebotcazou@adacore.com>
Wed, 15 Apr 2026 17:39:22 +0000 (19:39 +0200)
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.

gcc/ada/exp_aggr.adb
gcc/testsuite/gnat.dg/warn36.adb [new file with mode: 0644]

index 4b14043d276e18b2f322bcc591cd0891bd4154e5..82afcaaa0e80fb10ddb0e7b973a0dfeda55d4c59 100644 (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.
diff --git a/gcc/testsuite/gnat.dg/warn36.adb b/gcc/testsuite/gnat.dg/warn36.adb
new file mode 100644 (file)
index 0000000..fa3d25e
--- /dev/null
@@ -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;