From 8cad1ad5ade3fac0a2a796361bf5400d5f385036 Mon Sep 17 00:00:00 2001 From: "Steven G. Kargl" Date: Tue, 8 Oct 2019 16:31:16 +0000 Subject: [PATCH] re PR fortran/91801 (ICE in gfc_simplify_reshape, at fortran/simplify.c:6733) 2019-10-08 Steven G. Kargl PR fortran/91801 * simplify.c (gfc_simplify_reshape): Convert a gcc_assert into a gfc_error as a user can easily hit the condition. 2019-10-08 Steven G. Kargl PR fortran/91801 * gfortran.dg/pr91801.f90: New test. From-SVN: r276706 --- gcc/fortran/ChangeLog | 6 ++++++ gcc/fortran/simplify.c | 10 +++++++++- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gfortran.dg/pr91801.f90 | 7 +++++++ 4 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gfortran.dg/pr91801.f90 diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index b5bef54..7847042 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,9 @@ +2019-10-08 Steven G. Kargl + + PR fortran/91801 + * simplify.c (gfc_simplify_reshape): Convert a gcc_assert into a + gfc_error as a user can easily hit the condition. + 2019-10-08 Tobias Burnus * parse.c (parse_executable): Add missing ST_OMP_TARGET_SIMD. diff --git a/gcc/fortran/simplify.c b/gcc/fortran/simplify.c index 8c1577e..fa5aefe 100644 --- a/gcc/fortran/simplify.c +++ b/gcc/fortran/simplify.c @@ -6762,7 +6762,15 @@ gfc_simplify_reshape (gfc_expr *source, gfc_expr *shape_exp, gfc_extract_int (e, &order[i]); - gcc_assert (order[i] >= 1 && order[i] <= rank); + if (order[i] < 1 || order[i] > rank) + { + gfc_error ("Element with a value of %d in ORDER at %L must be " + "in the range [1, ..., %d] for the RESHAPE intrinsic " + "near %L", order[i], &order_exp->where, rank, + &shape_exp->where); + return &gfc_bad_expr; + } + order[i]--; if (x[order[i]] != 0) { diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index f3da169..cad47cc 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2019-10-08 Steven G. Kargl + + PR fortran/91801 + * gfortran.dg/pr91801.f90: New test. + 2019-10-08 Marek Polacek DR 685 - Integral promotion of enum ignores fixed underlying type. diff --git a/gcc/testsuite/gfortran.dg/pr91801.f90 b/gcc/testsuite/gfortran.dg/pr91801.f90 new file mode 100644 index 0000000..d2d82b8 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr91801.f90 @@ -0,0 +1,7 @@ +! { dg-do compile } +! PR fortran/91801 +! Code contributed by Gerhard Steinmetz +program p + integer, parameter :: a(2) = [2,0] ! { dg-error "Element with a value of" } + print *, reshape([1,2,3,4,5,6], [2,3], order=a) ! { dg-error "for the RESHAPE intrinsic near" } +end -- 2.7.4