From 59ec5d9be29535f41ecd7840fcb11708edd584f3 Mon Sep 17 00:00:00 2001 From: Patrick Bernardi Date: Tue, 22 May 2018 13:26:05 +0000 Subject: [PATCH] [Ada] Fix compiler abort on invalid discriminant constraint This patch fixes a compiler abort on a discriminant constraint when the constraint is a subtype indication. 2018-05-22 Patrick Bernardi gcc/ada/ * sem_ch3.adb (Build_Discriminant_Constraints): Raise an error if the user tries to use a subtype indication as a discriminant constraint. gcc/testsuite/ * gnat.dg/discr50.adb: New testcase. From-SVN: r260525 --- gcc/ada/ChangeLog | 5 +++++ gcc/ada/sem_ch3.adb | 6 ++++++ gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/gnat.dg/discr50.adb | 11 +++++++++++ 4 files changed, 26 insertions(+) create mode 100644 gcc/testsuite/gnat.dg/discr50.adb diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index aa3a1c034b7..5a5905731fa 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,8 @@ +2018-05-22 Patrick Bernardi + + * sem_ch3.adb (Build_Discriminant_Constraints): Raise an error if the + user tries to use a subtype indication as a discriminant constraint. + 2018-05-22 Ed Schonberg * exp_ch4.ads, exp_ch4.adb, exp_util.adb, expander.adb: Remove mention diff --git a/gcc/ada/sem_ch3.adb b/gcc/ada/sem_ch3.adb index 994562d8a10..83938c24b72 100644 --- a/gcc/ada/sem_ch3.adb +++ b/gcc/ada/sem_ch3.adb @@ -9877,6 +9877,12 @@ package body Sem_Ch3 is ("a range is not a valid discriminant constraint", Constr); Discr_Expr (D) := Error; + elsif Nkind (Constr) = N_Subtype_Indication then + Error_Msg_N + ("a subtype indication is not a valid discriminant constraint", + Constr); + Discr_Expr (D) := Error; + else Process_Discriminant_Expression (Constr, Discr); Discr_Expr (D) := Constr; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 74b4d34704d..8df5df8882d 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2018-05-22 Patrick Bernardi + + * gnat.dg/discr50.adb: New testcase. + 2018-05-22 Ed Schonberg * gnat.dg/discr49.adb, gnat.dg/discr49_rec1.adb, diff --git a/gcc/testsuite/gnat.dg/discr50.adb b/gcc/testsuite/gnat.dg/discr50.adb new file mode 100644 index 00000000000..e7de16d9e7c --- /dev/null +++ b/gcc/testsuite/gnat.dg/discr50.adb @@ -0,0 +1,11 @@ +-- { dg-do compile } + +procedure Discr50 is + type My_Record (D : Integer) is record + A : Integer; + end record; + + B : My_Record (Positive range 1 .. 10); -- { dg-error "a subtype indication is not a valid discriminant constraint" } +begin + null; +end Discr50; -- 2.30.2