diff options
author | Mark Eggleston <markeggleston@gcc.gnu.org> | 2020-02-18 10:00:50 +0000 |
---|---|---|
committer | Mark Eggleston <markeggleston@gcc.gnu.org> | 2020-02-18 10:00:50 +0000 |
commit | d4c10c9f4bff616e7ed07e92504fe31a700e2af1 (patch) | |
tree | 72b83cccb0605d3367f12ddf4d03494ae62e3496 /gcc/fortran/primary.c | |
parent | da67227bfc407dd1412b3396ed962f30084f9401 (diff) | |
download | gcc-d4c10c9f4bff616e7ed07e92504fe31a700e2af1.zip gcc-d4c10c9f4bff616e7ed07e92504fe31a700e2af1.tar.gz gcc-d4c10c9f4bff616e7ed07e92504fe31a700e2af1.tar.bz2 |
[fortran] ICE in gfc_validate_kind(): Got bad kind [PR93580]
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.
gcc/fortran/ChangeLog:
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.
gcc/testsuite/ChangeLog:
PR fortran/93580
* gfortran.dg/dg/pr93580.f90: New test.
Diffstat (limited to 'gcc/fortran/primary.c')
-rw-r--r-- | gcc/fortran/primary.c | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/gcc/fortran/primary.c b/gcc/fortran/primary.c index bd50827..d738984 100644 --- a/gcc/fortran/primary.c +++ b/gcc/fortran/primary.c @@ -2241,8 +2241,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; |