diff mbox series

[Ada] Fix failed assertion on a slice indexed by a subtype_indication

Message ID 20200618091320.GA2019@adacore.com
State New
Headers show
Series [Ada] Fix failed assertion on a slice indexed by a subtype_indication | expand

Commit Message

Pierre-Marie de Rodat June 18, 2020, 9:13 a.m. UTC
An assignment with a slice indexed by a subtype_indication, e.g.:

   Y : T := X (Positive range Low .. High);

is expanded into:

   [subtype S is Positive range Low .. High;]
   Y : S := X (Positive range Low .. High);

The bounds of the target subtype S were queried with Scalar_Range, which
might return N_Subtype_Indication node (as documented in einfo.ads) and
we didn't expect it. Now fixed.

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

2020-06-18  Piotr Trojanek  <trojanek@adacore.com>

gcc/ada/

	* checks.adb (Generate_Index_Checks): Handle
	N_Subtype_Indication returned from Scalar_Range.
diff mbox series

Patch

--- gcc/ada/checks.adb
+++ gcc/ada/checks.adb
@@ -6842,6 +6842,10 @@  package body Checks is
                   elsif Nkind_In (A_Idx, N_Identifier, N_Expanded_Name) then
                      A_Range := Scalar_Range (Entity (A_Idx));
 
+                     if Nkind (A_Range) = N_Subtype_Indication then
+                        A_Range := Range_Expression (Constraint (A_Range));
+                     end if;
+
                   else pragma Assert (Nkind (A_Idx) = N_Subtype_Indication);
                      A_Range := Range_Expression (Constraint (A_Idx));
                   end if;