re PR fortran/91801 (ICE in gfc_simplify_reshape, at fortran/simplify.c:6733)
authorSteven G. Kargl <kargl@gcc.gnu.org>
Tue, 8 Oct 2019 16:31:16 +0000 (16:31 +0000)
committerSteven G. Kargl <kargl@gcc.gnu.org>
Tue, 8 Oct 2019 16:31:16 +0000 (16:31 +0000)
2019-10-08  Steven G. Kargl  <kargl@gcc.gnu.org>

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  <kargl@gcc.gnu.org>

PR fortran/91801
* gfortran.dg/pr91801.f90: New test.

From-SVN: r276706

gcc/fortran/ChangeLog
gcc/fortran/simplify.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/pr91801.f90 [new file with mode: 0644]

index b5bef54a29733c53f44e2c72e489814f1e63f53d..784704293b926d0ff4ac0296a87efe6fd14bc55d 100644 (file)
@@ -1,3 +1,9 @@
+2019-10-08  Steven G. Kargl  <kargl@gcc.gnu.org>
+
+       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  <tobias@codesourcery.com>
 
        * parse.c (parse_executable): Add missing ST_OMP_TARGET_SIMD.
index 8c1577ec269bf21b755703b5ae2a18a023084666..fa5aefe20c6801de9e4d0234a53e4c8ad819b6e8 100644 (file)
@@ -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)
            {
index f3da169e2fe8f6d3f4dc52565187d96098911b79..cad47cc92190c747005dc0b693b58d88c63f69be 100644 (file)
@@ -1,3 +1,8 @@
+2019-10-08  Steven G. Kargl  <kargl@gcc.gnu.org>
+
+       PR fortran/91801
+       * gfortran.dg/pr91801.f90: New test.
+
 2019-10-08  Marek Polacek  <polacek@redhat.com>
 
        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 (file)
index 0000000..d2d82b8
--- /dev/null
@@ -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