diff mbox series

[Ada] Fix detection of valid renamings for overlapping checks

Message ID 20210617143311.GA10260@adacore.com
State New
Headers show
Series [Ada] Fix detection of valid renamings for overlapping checks | expand

Commit Message

Pierre-Marie de Rodat June 17, 2021, 2:33 p.m. UTC
Checks for overlapping actuals only apply to "valid renamings", i.e.
renamings whose renamed object_name contains no references to non-static
expressions; RM 6.4.1 (6.11/3). Such references can appear both in
indexed components and slices.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

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

Patch

diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb
--- a/gcc/ada/sem_util.adb
+++ b/gcc/ada/sem_util.adb
@@ -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