aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEd Schonberg <schonberg@adacore.com>2019-12-12 10:02:23 +0000
committerPierre-Marie de Rodat <pmderodat@gcc.gnu.org>2019-12-12 10:02:23 +0000
commitc2f3e1a3e369fe549fa76e9821d2e17bc3d55dc7 (patch)
tree4473ec6305948f9e8d6c881453c1469573a929f7
parent0e3a687f8c5351a52f48c4062c2cf88cdc7d4424 (diff)
downloadgcc-c2f3e1a3e369fe549fa76e9821d2e17bc3d55dc7.zip
gcc-c2f3e1a3e369fe549fa76e9821d2e17bc3d55dc7.tar.gz
gcc-c2f3e1a3e369fe549fa76e9821d2e17bc3d55dc7.tar.bz2
[Ada] Missing length check on private type with unknown discriminants
2019-12-12 Ed Schonberg <schonberg@adacore.com> gcc/ada/ * exp_ch5.adb (Expand_N_Assognment_Statement): Extend the processing involving private types with unknown discriminants to handle the case where the full view of the type is an unconstrained array type. From-SVN: r279286
-rw-r--r--gcc/ada/ChangeLog7
-rw-r--r--gcc/ada/exp_ch5.adb23
2 files changed, 23 insertions, 7 deletions
diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog
index 150ee56..a4dc138 100644
--- a/gcc/ada/ChangeLog
+++ b/gcc/ada/ChangeLog
@@ -1,3 +1,10 @@
+2019-12-12 Ed Schonberg <schonberg@adacore.com>
+
+ * exp_ch5.adb (Expand_N_Assognment_Statement): Extend the
+ processing involving private types with unknown discriminants to
+ handle the case where the full view of the type is an
+ unconstrained array type.
+
2019-12-12 Bob Duff <duff@adacore.com>
* sem_ch4.adb (Transform_Object_Operation): Deal properly with
diff --git a/gcc/ada/exp_ch5.adb b/gcc/ada/exp_ch5.adb
index 4bbe86a..f3139bd 100644
--- a/gcc/ada/exp_ch5.adb
+++ b/gcc/ada/exp_ch5.adb
@@ -2409,14 +2409,23 @@ package body Exp_Ch5 is
-- checking. Convert Lhs as well, otherwise the actual subtype might
-- not be constructible. If the discriminants have defaults the type
-- is unconstrained and there is nothing to check.
+ -- Ditto if a private type with unknown discriminants has a full view
+ -- that is an unconstrained array, in which case a length check is
+ -- needed.
- elsif Has_Unknown_Discriminants (Base_Type (Etype (Lhs)))
- and then Has_Discriminants (Typ)
- and then not Has_Defaulted_Discriminants (Typ)
- then
- Rewrite (Rhs, OK_Convert_To (Base_Type (Typ), Rhs));
- Rewrite (Lhs, OK_Convert_To (Base_Type (Typ), Lhs));
- Apply_Discriminant_Check (Rhs, Typ, Lhs);
+ elsif Has_Unknown_Discriminants (Base_Type (Etype (Lhs))) then
+ if Has_Discriminants (Typ)
+ and then not Has_Defaulted_Discriminants (Typ)
+ then
+ Rewrite (Rhs, OK_Convert_To (Base_Type (Typ), Rhs));
+ Rewrite (Lhs, OK_Convert_To (Base_Type (Typ), Lhs));
+ Apply_Discriminant_Check (Rhs, Typ, Lhs);
+
+ elsif Is_Array_Type (Typ) and then Is_Constrained (Typ) then
+ Rewrite (Rhs, OK_Convert_To (Base_Type (Typ), Rhs));
+ Rewrite (Lhs, OK_Convert_To (Base_Type (Typ), Lhs));
+ Apply_Length_Check (Rhs, Typ);
+ end if;
-- In the access type case, we need the same discriminant check, and
-- also range checks if we have an access to constrained array.