]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fortran : ICE in gfc_check_reshape PR95585
authorMark Eggleston <markeggleston@gcc.gnu.org>
Thu, 11 Jun 2020 05:42:36 +0000 (06:42 +0100)
committerMark Eggleston <markeggleston@gcc.gnu.org>
Sun, 26 Jul 2020 07:47:22 +0000 (08:47 +0100)
Issue an error where an array is used before its definition
instead of an ICE.

2020-07-26  Steven G. Kargl  <kargl@gcc.gnu.org>

gcc/fortran/

PR fortran/95585
* check.c (gfc_check_reshape): Add check for a value when
the symbol has an attribute flavor FL_PARAMETER.

2020-07-26  Mark Eggleston  <markeggleston@gcc.gnu.org>

gcc/testsuite/

PR fortran/95585
* gfortran.dg/pr95585.f90: New test.

(cherry picked from commit d9aed5f1ccffc019ddf980e349caa3d092755cb4)

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

index 148a326981564975f47f47a08bae55aff1e76ac4..4d50906a3f372482d4921a8776ca9cab21078fac 100644 (file)
@@ -4742,7 +4742,8 @@ gfc_check_reshape (gfc_expr *source, gfc_expr *shape,
           && 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)
+          && shape->symtree->n.sym->attr.flavor == FL_PARAMETER
+          && shape->symtree->n.sym->value)
     {
       int i, extent;
       gfc_expr *e, *v;
diff --git a/gcc/testsuite/gfortran.dg/pr95585.f90 b/gcc/testsuite/gfortran.dg/pr95585.f90
new file mode 100644 (file)
index 0000000..b0e6cdc
--- /dev/null
@@ -0,0 +1,6 @@
+! { dg-do compile }
+
+program test
+  integer, parameter :: a(2) = reshape([1, 2], a) ! { dg-error "before its definition" }
+end program
+