re PR fortran/68153 (ICE for intrinsic reshape with negative dim in effective shape)
authorSteven G. Kargl <kargl@gcc.gnu.org>
Sat, 7 Nov 2015 20:18:17 +0000 (20:18 +0000)
committerSteven G. Kargl <kargl@gcc.gnu.org>
Sat, 7 Nov 2015 20:18:17 +0000 (20:18 +0000)
2015-11-07  Steven G. Kargl  <kargl@gcc.gnu.org>

PR fortran/68153
* check.c (gfc_check_reshape): Improve check for valid SHAPE argument.

2015-11-07  Steven G. Kargl  <kargl@gcc.gnu.org>

PR fortran/68153
* gfortran.dg/pr68153.f90: New test.

From-SVN: r229939

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

index 15583d9848b516d32ec5b77a5feadad8d7d750a5..fc3afba3aaf1e7c43bea4233ac6a5857aeaff4a4 100644 (file)
@@ -1,3 +1,8 @@
+2015-11-07  Steven G. Kargl  <kargl@gcc.gnu.org>
+
+       PR fortran/68153
+       * check.c (gfc_check_reshape): Improve check for valid SHAPE argument.
+
 2015-11-07  Steven G. Kargl  <kargl@gcc.gnu.org>
 
        PR fortran/68151
index 6548a017f446bee3c67b0547bf2c064ca27c7f54..86dae5b000c46020b72110bad649613d672feadd 100644 (file)
@@ -3711,6 +3711,36 @@ gfc_check_reshape (gfc_expr *source, gfc_expr *shape,
            }
        }
     }
+  else if (shape->expr_type == EXPR_VARIABLE && shape->ref
+          && shape->ref->u.ar.type == AR_FULL && shape->ref->u.ar.dimen == 1
+          && shape->ref->u.ar.as
+          && shape->ref->u.ar.as->lower[0]->expr_type == EXPR_CONSTANT
+          && shape->ref->u.ar.as->lower[0]->ts.type == BT_INTEGER
+          && shape->ref->u.ar.as->upper[0]->expr_type == EXPR_CONSTANT
+          && shape->ref->u.ar.as->upper[0]->ts.type == BT_INTEGER
+          && shape->symtree->n.sym->attr.flavor == FL_PARAMETER)
+    {
+      int i, extent;
+      gfc_expr *e, *v;
+
+      v = shape->symtree->n.sym->value;
+
+      for (i = 0; i < shape_size; i++)
+       {
+         e = gfc_constructor_lookup_expr (v->value.constructor, i);
+         if (e == NULL)
+            break;
+
+         gfc_extract_int (e, &extent);
+
+         if (extent < 0)
+           {
+             gfc_error ("Element %d of actual argument of RESHAPE at %L "
+                        "cannot be negative", i + 1, &shape->where);
+             return false;
+           }
+       }
+    }
 
   if (pad != NULL)
     {
index c9df4b08166aac9e399afc587dde97c0fb34748d..65e940b1b7edd0e83691e78c5b57fe619fd98ffd 100644 (file)
@@ -1,3 +1,8 @@
+2015-11-07  Steven G. Kargl  <kargl@gcc.gnu.org>
+
+       PR fortran/68153
+       * gfortran.dg/pr68153.f90: New test.
+
 2015-11-07  Steven G. Kargl  <kargl@gcc.gnu.org>
 
        PR fortran/68151
diff --git a/gcc/testsuite/gfortran.dg/pr68153.f90 b/gcc/testsuite/gfortran.dg/pr68153.f90
new file mode 100644 (file)
index 0000000..1a360f8
--- /dev/null
@@ -0,0 +1,9 @@
+! { dg-do compile }
+! PR fortran/68153
+! Original code contribute by Gerhard Steinmetz
+! <gerhard dot steinmetz dot fortran at t-online dot de>
+!
+program foo
+   integer, parameter :: a(2) = [2, -2]
+   integer, parameter :: b(2,2) = reshape([1, 2, 3, 4], a) ! { dg-error "cannot be negative" }
+end program foo