From 6e12721acde2080202889b3839acca52646b0d28 Mon Sep 17 00:00:00 2001 From: "Steven G. Kargl" Date: Wed, 28 Aug 2019 20:16:57 +0000 Subject: [PATCH] re PR fortran/91565 (ICE in gfc_simplify_reshape, at fortran/simplify.c:6707 etc.) 2019-08-28 Steven G. Kargl PR fortran/91565 * simplify.c (gfc_simplify_reshape): Add additional checks of the ORDER dummy argument. 2019-08-28 Steven G. Kargl PR fortran/91565 * gfortran.dg/pr91565.f90: New test. From-SVN: r275007 --- gcc/fortran/ChangeLog | 6 +++++ gcc/fortran/simplify.c | 34 ++++++++++++++++++++++++--- gcc/testsuite/ChangeLog | 5 ++++ gcc/testsuite/gfortran.dg/pr91565.f90 | 17 ++++++++++++++ 4 files changed, 59 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/pr91565.f90 diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index b118913aa15..5e3d7b9e9a4 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,9 @@ +2019-08-28 Steven G. Kargl + + PR fortran/91565 + * simplify.c (gfc_simplify_reshape): Add additional checks of the + ORDER dummy argument. + 2019-08-28 Steven G. Kargl PR fortran/91564 diff --git a/gcc/fortran/simplify.c b/gcc/fortran/simplify.c index 5ab7c81c13a..7fc18d53925 100644 --- a/gcc/fortran/simplify.c +++ b/gcc/fortran/simplify.c @@ -6668,6 +6668,9 @@ gfc_simplify_reshape (gfc_expr *source, gfc_expr *shape_exp, mpz_init (index); rank = 0; + for (i = 0; i < GFC_MAX_DIMENSIONS; i++) + x[i] = 0; + for (;;) { e = gfc_constructor_lookup_expr (shape_exp->value.constructor, rank); @@ -6692,8 +6695,28 @@ gfc_simplify_reshape (gfc_expr *source, gfc_expr *shape_exp, } else { - for (i = 0; i < rank; i++) - x[i] = 0; + mpz_t size; + int order_size, shape_size; + + if (order_exp->rank != shape_exp->rank) + { + gfc_error ("Shapes of ORDER at %L and SHAPE at %L are different", + &order_exp->where, &shape_exp->where); + return &gfc_bad_expr; + } + + gfc_array_size (shape_exp, &size); + shape_size = mpz_get_ui (size); + mpz_clear (size); + gfc_array_size (order_exp, &size); + order_size = mpz_get_ui (size); + mpz_clear (size); + if (order_size != shape_size) + { + gfc_error ("Sizes of ORDER at %L and SHAPE at %L are different", + &order_exp->where, &shape_exp->where); + return &gfc_bad_expr; + } for (i = 0; i < rank; i++) { @@ -6704,7 +6727,12 @@ gfc_simplify_reshape (gfc_expr *source, gfc_expr *shape_exp, gcc_assert (order[i] >= 1 && order[i] <= rank); order[i]--; - gcc_assert (x[order[i]] == 0); + if (x[order[i]] != 0) + { + gfc_error ("ORDER at %L is not a permutation of the size of " + "SHAPE at %L", &order_exp->where, &shape_exp->where); + return &gfc_bad_expr; + } x[order[i]] = 1; } } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 06d8b1bccd2..7dc95f323ec 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2019-08-28 Steven G. Kargl + + PR fortran/91565 + * gfortran.dg/pr91565.f90: New test. + 2019-08-28 Steven G. Kargl PR fortran/91564 diff --git a/gcc/testsuite/gfortran.dg/pr91565.f90 b/gcc/testsuite/gfortran.dg/pr91565.f90 new file mode 100644 index 00000000000..b43a57acf13 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr91565.f90 @@ -0,0 +1,17 @@ +! { dg-do compile } +! PR fortran/91565 +! Contributed by Gerhard Steinmetz +program p + integer, parameter :: a(2) = [2,2] ! { dg-error "\(1\)" } + print *, reshape([1,2,3,4,5,6], [2,3], order=a) ! { dg-error "not a permutation" } +end + +subroutine foo + integer, parameter :: a(1) = 1 ! { dg-error "\(1\)" } + print *, reshape([1,2,3,4,5,6], [2,3], order=a) ! { dg-error "are different" } +end + +subroutine bar + integer, parameter :: a(1,2) = 1 ! { dg-error "\(1\)" } + print *, reshape([1,2,3,4,5,6], [2,3], order=a) ! { dg-error "are different" } +end -- 2.30.2