]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
[fortran] ICE in gfc_validate_kind(): Got bad kind [PR93580]
authorMark Eggleston <markeggleston@gcc.gnu.org>
Tue, 18 Feb 2020 10:56:38 +0000 (10:56 +0000)
committerMark Eggleston <markeggleston@gcc.gnu.org>
Tue, 18 Feb 2020 10:56:38 +0000 (10:56 +0000)
Caused by using invalid part_refs in kind specifications,
e.g. %re or %im on non-complex expressions and %len on
non character expressions.

Check whether %re, %im and %len are valid when checking
kind specification.

The original patch from Steven G. Kargl  <kargl@gcc.gnu.org> only
checked for %re and %im.

Backported from mainline
2020-02-18  Mark Eggleston <markeggleston@gcc.gnu.org>

PR fortran/93580
* primary.c (gfc_match_varspec): If the symbol following %
is re or im and the primary expression type is not BT_COMPLEX
issue an error. If the symbol is len and the primary
expression type is not BT_CHARACTER is an error.

PR fortran/93580
* gfortran.dg/dg/pr93580.f90: New test.

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

index f31e052b10acb468c3e37157defdaf8046a42a4b..c4257c1c7f7c2274e40d1f63dd64d7aea21dafe2 100644 (file)
@@ -1,3 +1,15 @@
+2020-02-18  Mark Eggleston  <markeggleston@gcc.gnu.org>
+
+       Backported from mainline
+       2020-02-18  Steven G. Kargl  <kargl@gcc.gnu.org>
+                   Mark Eggleston  <markeggleston@gcc.gnu.org>
+
+       PR fortran/93580
+       * primary.c (gfc_match_varspec): If the symbol following %
+       is re or im and the primary expression type is not BT_COMPLEX
+       issue an error. If the symbol is len and the primary
+       expression type is not BT_CHARACTER is an error.
+
 2020-02-13  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
index 8408e9c3d0d7e55dc1602e2528c70014c29e10d6..ff93698f47891630308e3dfea4d26a1e7ba538fc 100644 (file)
@@ -2202,8 +2202,28 @@ gfc_match_varspec (gfc_expr *primary, int equiv_flag, bool sub_flag,
          if (inquiry)
            sym = NULL;
 
-         if (sep == '%' && primary->ts.type != BT_UNKNOWN)
-           intrinsic = true;
+         if (sep == '%')
+           {
+             if (tmp)
+               {
+                 if ((tmp->u.i == INQUIRY_RE || tmp->u.i == INQUIRY_IM)
+                     && primary->ts.type != BT_COMPLEX)
+                   {
+                       gfc_error ("The RE or IM part_ref at %C must be "
+                                  "applied to a COMPLEX expression");
+                       return MATCH_ERROR;
+                   }
+                 else if (tmp->u.i == INQUIRY_LEN
+                          && primary->ts.type != BT_CHARACTER)
+                   {
+                       gfc_error ("The LEN part_ref at %C must be applied "
+                                  "to a CHARACTER expression");
+                       return MATCH_ERROR;
+                   }
+               }
+             if (primary->ts.type != BT_UNKNOWN)
+               intrinsic = true;
+           }
        }
       else
        inquiry = false;
index 62b7b329eeeb9982a346f2abc9f60851c448783a..81926efcbbdb5bc9b01fe2a5f1588b6caaf80fb3 100644 (file)
@@ -1,3 +1,11 @@
+2020-02-18  Mark Eggleston <markeggleston@gcc.gnu.org>
+
+       Back-ported from mainline
+       2020-02-18 Mark Eggleston <markeggleston@gcc.gnu.org>
+
+       PR fortran/93580
+       * gfortran.dg/dg/pr93580.f90: New test.
+
 2020-02-18  Richard Sandiford  <richard.sandiford@arm.com>
 
        PR tree-optimization/93434
diff --git a/gcc/testsuite/gfortran.dg/pr93580.f90 b/gcc/testsuite/gfortran.dg/pr93580.f90
new file mode 100644 (file)
index 0000000..4feaa11
--- /dev/null
@@ -0,0 +1,13 @@
+! { dg-do compile }
+! PR fortran/93580
+
+program p
+   integer, parameter :: n = 4
+   complex(n%re) :: x    ! { dg-error "The RE or IM part_ref at" }
+   complex(n%im) :: y    ! { dg-error "The RE or IM part_ref at" }
+   complex(n%len) :: z   ! { dg-error "The LEN part_ref at" }
+   character(n%im) :: a  ! { dg-error "The RE or IM part_ref at" }
+   character(n%re) :: b  ! { dg-error "The RE or IM part_ref at" }
+   character(n%len) :: c ! { dg-error "The LEN part_ref at" }
+end
+