Commit d4c10c9f by Mark Eggleston

[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.
parent da67227b
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-10 Andrew Benson <abensonca@gmail.com> 2020-02-10 Andrew Benson <abensonca@gmail.com>
PR fortran/83113 PR fortran/83113
......
...@@ -2241,8 +2241,28 @@ gfc_match_varspec (gfc_expr *primary, int equiv_flag, bool sub_flag, ...@@ -2241,8 +2241,28 @@ gfc_match_varspec (gfc_expr *primary, int equiv_flag, bool sub_flag,
if (inquiry) if (inquiry)
sym = NULL; sym = NULL;
if (sep == '%' && primary->ts.type != BT_UNKNOWN) if (sep == '%')
intrinsic = true; {
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 else
inquiry = false; inquiry = false;
......
2020-02-20 Mark Eggleston <markeggleston@gcc.gnu.org>
PR fortran/93580
* gfortran.dg/dg/pr93580.f90: New test.
2020-02-18 Jakub Jelinek <jakub@redhat.com> 2020-02-18 Jakub Jelinek <jakub@redhat.com>
PR tree-optimization/93780 PR tree-optimization/93780
......
! { 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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment