]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Spurious unreferenced warning on selected component
authorJustin Squirek <squirek@adacore.com>
Mon, 12 Feb 2024 15:50:24 +0000 (15:50 +0000)
committerMarc Poulhiès <poulhies@adacore.com>
Tue, 14 May 2024 08:19:53 +0000 (10:19 +0200)
This patch fixes an error in the compiler whereby a selected component on the
left hand side of an assignment statement may not get marked as referenced -
leading to spurious unreferenced warnings on such objects.

gcc/ada/

* sem_util.adb (Set_Referenced_Modified): Use Original_Node to
avoid recursive calls on expanded / internal objects such that
source nodes get appropriately marked as referenced.

gcc/ada/sem_util.adb

index b5c33638b35f676e53acbeb839fe71cd71cfbbf8..4e1258e7cecd6fba2c9a23e4e4812974a22d19f9 100644 (file)
@@ -27625,7 +27625,11 @@ package body Sem_Util is
       --  Deal with indexed or selected component where prefix is modified
 
       if Nkind (N) in N_Indexed_Component | N_Selected_Component then
-         Pref := Prefix (N);
+
+         --  Grab the original node to avoid looking at internally generated
+         --  objects.
+
+         Pref := Original_Node (Prefix (N));
 
          --  If prefix is access type, then it is the designated object that is
          --  being modified, which means we have no entity to set the flag on.