diff options
author | Piotr Trojanek <trojanek@adacore.com> | 2021-08-27 17:48:15 +0200 |
---|---|---|
committer | Pierre-Marie de Rodat <derodat@adacore.com> | 2021-10-04 08:45:07 +0000 |
commit | f9974930bcb21fb436217972db38d04ab88eb8c4 (patch) | |
tree | ac7f0e3e8caf1d600c92d48e93808d4649d6ba88 /gcc | |
parent | 44bfdde1e96167f07b86b0dcd773931353a98ea7 (diff) | |
download | gcc-f9974930bcb21fb436217972db38d04ab88eb8c4.zip gcc-f9974930bcb21fb436217972db38d04ab88eb8c4.tar.gz gcc-f9974930bcb21fb436217972db38d04ab88eb8c4.tar.bz2 |
[Ada] Fix handling of slices with subtype names
gcc/ada/
* sem_res.adb (Resolve_Slice): Fix application of range checks
to slice range given as a subtype name.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ada/sem_res.adb | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/gcc/ada/sem_res.adb b/gcc/ada/sem_res.adb index ba733a5..ec2d5ec 100644 --- a/gcc/ada/sem_res.adb +++ b/gcc/ada/sem_res.adb @@ -11347,18 +11347,19 @@ package body Sem_Res is then null; - -- The discrete_range is specified by a subtype indication. Create a - -- shallow copy and inherit the type, parent and source location from - -- the discrete_range. This ensures that the range check is inserted - -- relative to the slice and that the runtime exception points to the - -- proper construct. + -- The discrete_range is specified by a subtype name. Create an + -- equivalent range attribute, apply checks to this attribute, but + -- insert them into the range expression of the slice itself. elsif Is_Entity_Name (Drange) then - Dexpr := New_Copy (Scalar_Range (Entity (Drange))); + Dexpr := + Make_Attribute_Reference + (Sloc (Drange), + Prefix => + New_Occurrence_Of (Entity (Drange), Sloc (Drange)), + Attribute_Name => Name_Range); - Set_Etype (Dexpr, Etype (Drange)); - Set_Parent (Dexpr, Parent (Drange)); - Set_Sloc (Dexpr, Sloc (Drange)); + Analyze_And_Resolve (Dexpr, Etype (Drange)); elsif Nkind (Drange) = N_Subtype_Indication then Dexpr := Range_Expression (Constraint (Drange)); @@ -11379,7 +11380,7 @@ package body Sem_Res is end if; if Present (Dexpr) then - Apply_Range_Check (Dexpr, Index_Type); + Apply_Range_Check (Dexpr, Index_Type, Insert_Node => Drange); end if; Set_Slice_Subtype (N); |