]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
[Ada] Fix detection of valid renamings for overlapping checks
authorPiotr Trojanek <trojanek@adacore.com>
Wed, 10 Mar 2021 22:40:13 +0000 (23:40 +0100)
committerPierre-Marie de Rodat <derodat@adacore.com>
Thu, 17 Jun 2021 14:32:15 +0000 (10:32 -0400)
gcc/ada/

* sem_util.adb (Is_Valid_Renaming): Check not only indexed
components, but slices too.

gcc/ada/sem_util.adb

index 855195dd220123926f9578ccb77381f02c8ccd03..b71efde8567641fff2fa0f338ea24bb7c6c513a8 100644 (file)
@@ -7301,6 +7301,9 @@ package body Sem_Util is
             return False;
          end if;
 
+         --  Check if any expression within the renamed object_name contains no
+         --  references to variables nor calls on nonstatic functions.
+
          if Nkind (N) = N_Indexed_Component then
             declare
                Indx : Node_Id;
@@ -7315,6 +7318,33 @@ package body Sem_Util is
                   Next_Index (Indx);
                end loop;
             end;
+
+         elsif Nkind (N) = N_Slice then
+            declare
+               Rng : constant Node_Id := Discrete_Range (N);
+            begin
+               --  Bounds specified as a range
+
+               if Nkind (Rng) = N_Range then
+                  if not Is_OK_Static_Range (Rng) then
+                     return False;
+                  end if;
+
+               --  Bounds specified as a constrained subtype indication
+
+               elsif Nkind (Rng) = N_Subtype_Indication then
+                  if not Is_OK_Static_Range
+                       (Range_Expression (Constraint (Rng)))
+                  then
+                     return False;
+                  end if;
+
+               --  Bounds specified as a subtype name
+
+               elsif not Is_OK_Static_Expression (Rng) then
+                  return False;
+               end if;
+            end;
          end if;
 
          if Has_Prefix (N) then