]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Do not count comparison of addresses as a modification
authorViljar Indus <indus@adacore.com>
Tue, 12 Dec 2023 15:03:13 +0000 (17:03 +0200)
committerMarc Poulhiès <poulhies@adacore.com>
Tue, 9 Jan 2024 13:13:32 +0000 (14:13 +0100)
In some extended code we generate comparisons between
the Addresses of some variables. This causes those
variables to be considered modified. Whereas in this
particular scenario the variables are just referenced.

gcc/ada/

* sem_attr.adb: avoid marking a use of the Address attribute
as a modification of its prefix.

gcc/ada/sem_attr.adb

index a194360a60135779765adfbeb2265a211dde42c0..f52103f28ddce5fd715c93fb6917f4e1d6c5a59d 100644 (file)
@@ -12133,9 +12133,13 @@ package body Sem_Attr is
             | Attribute_Code_Address
          =>
             --  To be safe, assume that if the address of a variable is taken,
-            --  it may be modified via this address, so note modification.
+            --  it may be modified via this address, so note modification,
+            --  unless the address is compared directly, which should not be
+            --  considered a modification.
 
-            if Is_Variable (P) then
+            if Is_Variable (P)
+              and then Nkind (Parent (N)) not in N_Op_Compare
+            then
                Note_Possible_Modification (P, Sure => False);
             end if;