]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR fortran/68566 (ICE on using unusable array in reshape (double free...
authorSteven G. Kargl <kargl@gcc.gnu.org>
Fri, 30 Sep 2016 17:54:15 +0000 (17:54 +0000)
committerSteven G. Kargl <kargl@gcc.gnu.org>
Fri, 30 Sep 2016 17:54:15 +0000 (17:54 +0000)
2016-09-30  Steven G. Kargl  <kargl@gcc.gnu.org>

Backport from trunk

PR fortran/68566
* check.c (gfc_check_reshape): Check for constant expression.

PR fortran/68566
* gfortran.dg/pr68566.f90: new test.

From-SVN: r240671

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

index 3f0d9267831f56206ca42282d067f8969aba78df..1cfa9e4acc34a04658a4eeaee28f7facf3f2f932 100644 (file)
@@ -1,3 +1,10 @@
+2016-09-30  Steven G. Kargl  <kargl@gcc.gnu.org>
+
+       Backport from trunk
+       PR fortran/68566
+       * check.c (gfc_check_reshape): Check for constant expression.
+
 2016-09-30  Steven G. Kargl  <kargl@gcc.gnu.org>
 
        Backport from trunk
index 049a6fb18dd12e0ea824d2e5faec07b0ac269c35..de7ed0fd0e36417206eb8879318d8bb999f371c0 100644 (file)
@@ -3820,7 +3820,7 @@ gfc_check_reshape (gfc_expr *source, gfc_expr *shape,
       if (!type_check (order, 3, BT_INTEGER))
        return false;
 
-      if (order->expr_type == EXPR_ARRAY)
+      if (order->expr_type == EXPR_ARRAY && gfc_is_constant_expr (order))
        {
          int i, order_size, dim, perm[GFC_MAX_DIMENSIONS];
          gfc_expr *e;
index a77db1176edd70f9d05d87a97a7de491355d5957..8f541d5c8615cfd52527120101da6595d8ea0d4a 100644 (file)
@@ -1,3 +1,10 @@
+2016-09-30  Steven G. Kargl  <kargl@gcc.gnu.org>
+
+       Backport from trunk
+
+       PR fortran/68566
+       * gfortran.dg/pr68566.f90: new test.
+
 2016-09-30  Steven G. Kargl  <kargl@gcc.gnu.org>
 
        Backport from trunk
diff --git a/gcc/testsuite/gfortran.dg/pr68566.f90 b/gcc/testsuite/gfortran.dg/pr68566.f90
new file mode 100644 (file)
index 0000000..160e9ac
--- /dev/null
@@ -0,0 +1,13 @@
+! { dg-do run }
+program p
+   character(len=20) s1, s2
+   integer, allocatable :: n(:)
+   n = [2,1]
+   s1 = '1 5 2 6 3 0 4 0'
+   write(s2,'(8(I0,1x))') reshape ([1,2,3,4,5,6], [2,4], [0,0], [2,1])
+   if (trim(s1) /= trim(s2)) call abort
+   write(s2,'(8(I0,1x))') reshape ([1,2,3,4,5,6], [2,4], [0,0], n)
+   if (trim(s1) /= trim(s2)) call abort
+   write(s2,'(8(I0,1x))') reshape ([1,2,3,4,5,6], [2,4], [0,0], [n])
+   if (trim(s1) /= trim(s2)) call abort
+end