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 <troja...@adacore.com>
gcc/ada/
* checks.adb (Generate_Index_Checks): Handle
N_Subtype_Indication returned from Scalar_Range.
--- 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;