]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
fortran: ICE using undeclared symbol in array constructor PR93484
authorMark Eggleston <markeggleston@gcc.gnu.org>
Wed, 25 Mar 2020 13:43:23 +0000 (13:43 +0000)
committerMark Eggleston <markeggleston@gcc.gnu.org>
Wed, 25 Mar 2020 13:43:23 +0000 (13:43 +0000)
Using undeclared symbol k in an expression in the following
array constructor results in an ICE:

    print *, [real(x(k))]

If the call to the intrinsic is not in a constructor a no IMPLICIT
type error is reported and the ICE does not occur.

Matching on an expression instead of an initialisation express an
and not converting a MATCH_ERROR return value into MATCH_NO results
in the no IMPLICIT error and no ICE.

Note: Steven G. Kargl  <kargl@gcc.gnu.org> is the author of the
changes except for the test cases.

gcc/fortran/ChangeLog:

Backport from master
2020-03-25  Mark Eggleston <markeggleston@gcc.gnu.org>

PR fortran/93484
* match.c (gfc_match_type_spec): Replace gfc_match_init_expr with
gfc_match_expr. Return m if m is MATCH_NO or MATCH_ERROR.

gcc/testsuite

Backport from master
2020-03-25  Mark Eggleston <markeggleston@gcc.gnu.org>

PR fortran/93484
* gfortran.dg/pr93484_1.f90: New test.
* gfortran.dg/pr93484_2.f90: New test.

gcc/fortran/ChangeLog
gcc/fortran/match.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/pr93484_1.f90 [new file with mode: 0644]
gcc/testsuite/gfortran.dg/pr93484_2.f90 [new file with mode: 0644]

index 8fefea2b63d210f12fe80e5cf38799e66fb4041d..503b385d79c6e15cf0d3f10f36a20a7b6b7fd405 100644 (file)
@@ -1,3 +1,12 @@
+2020-03-25  Mark Eggleston <markeggleston@gcc.gnu.org>
+
+       Backport from master
+       2020-03-25  Mark Eggleston <markeggleston@gcc.gnu.org>
+
+       PR fortran/93484
+       * match.c (gfc_match_type_spec): Replace gfc_match_init_expr with
+       gfc_match_expr. Return m if m is MATCH_NO or MATCH_ERROR.
+
 2020-03-12  Release Manager
 
        * GCC 9.3.0 released.
index 088b69f8ec9dae317511b80c0ebff83f1171d1e1..f4ae9e9dfe75325c91a28609989c62e941f77675 100644 (file)
@@ -2200,9 +2200,9 @@ gfc_match_type_spec (gfc_typespec *ts)
 
 found:
 
-      m = gfc_match_init_expr (&e);
+      m = gfc_match_expr (&e);
       if (m == MATCH_NO || m == MATCH_ERROR)
-       return MATCH_NO;
+       return m;
 
       /* If a comma appears, it is an intrinsic subprogram. */
       gfc_gobble_whitespace ();
index 23fc1178346ac98a54a222f1de3fd42262caab53..e4d99050bcfd568905c933ddabf55ea7b02b7246 100644 (file)
@@ -1,3 +1,12 @@
+2020-03-25  Mark Eggleston <markeggleston@gcc.gnu.org>
+
+       Backport from master
+       2020-03-25  Mark Eggleston <markeggleston@gcc.gnu.org>
+
+       PR fortran/93484
+       * gfortran.dg/pr93484_1.f90: New test.
+       * gfortran.dg/pr93484_2.f90: New test.
+
 2020-03-25  Kewen Lin  <linkw@gcc.gnu.org>
 
        Backport from master
diff --git a/gcc/testsuite/gfortran.dg/pr93484_1.f90 b/gcc/testsuite/gfortran.dg/pr93484_1.f90
new file mode 100644 (file)
index 0000000..3b6dbc9
--- /dev/null
@@ -0,0 +1,8 @@
+! { dg-do compile }
+!
+program p
+  implicit none
+  integer :: x(4) = [1,2,3,4]
+  print *, [real(x(k))] ! { dg-error "Symbol 'k' at .1. has no IMPLICIT type" } 
+end
+
diff --git a/gcc/testsuite/gfortran.dg/pr93484_2.f90 b/gcc/testsuite/gfortran.dg/pr93484_2.f90
new file mode 100644 (file)
index 0000000..4a7f433
--- /dev/null
@@ -0,0 +1,8 @@
+! { dg-do compile }
+!
+program p
+  implicit none
+  integer, parameter :: x(4) = [1,2,3,4]
+  print *, [real(x(k))] ! { dg-error "Symbol 'k' at .1. has no IMPLICIT type" }
+end
+