From: Steven G. Kargl Date: Thu, 5 Sep 2019 18:37:13 +0000 (+0000) Subject: re PR fortran/91660 (Missing error on invalid type declaration) X-Git-Tag: releases/gcc-9.3.0~647 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b3ec4913dbbd15a61925980e6f2dd94f6b766a08;p=thirdparty%2Fgcc.git re PR fortran/91660 (Missing error on invalid type declaration) 2019-09-05 Steven G. Kargl PR fortran/91660 * decl.c (gfc_match_decl_type_spec): Improve and restore error message for malformed types-spec. 2019-09-05 Steven G. Kargl PR fortran/91660 * gfortran.dg/pdt_4.f03: Fix invalid code. * gfortran.dg/pr91660_1.f90: New test. * gfortran.dg/pr91660_2.f90: Ditto. From-SVN: r275427 --- diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 06e13e01d04c..7258dee9b5d1 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,9 @@ +2019-09-05 Steven G. Kargl + + PR fortran/91660 + * decl.c (gfc_match_decl_type_spec): Improve and restore error + message for malformed types-spec. + 2019-09-02 Steven G. Kargl PR fortran/91552 diff --git a/gcc/fortran/decl.c b/gcc/fortran/decl.c index 3513d177e5e8..ae16647fa67e 100644 --- a/gcc/fortran/decl.c +++ b/gcc/fortran/decl.c @@ -3991,7 +3991,6 @@ gfc_match_decl_type_spec (gfc_typespec *ts, int implicit_flag) return MATCH_YES; } - m = gfc_match (" type ("); matched_type = (m == MATCH_YES); if (matched_type) @@ -4039,7 +4038,10 @@ gfc_match_decl_type_spec (gfc_typespec *ts, int implicit_flag) m = MATCH_YES; if (matched_type && m == MATCH_YES && gfc_match_char (')') != MATCH_YES) - m = MATCH_ERROR; + { + gfc_error ("Malformed type-spec at %C"); + return MATCH_ERROR; + } return m; } @@ -4062,8 +4064,12 @@ gfc_match_decl_type_spec (gfc_typespec *ts, int implicit_flag) && !gfc_notify_std (GFC_STD_F2008, "TYPE with " "intrinsic-type-spec at %C")) return MATCH_ERROR; + if (matched_type && gfc_match_char (')') != MATCH_YES) - return MATCH_ERROR; + { + gfc_error ("Malformed type-spec at %C"); + return MATCH_ERROR; + } ts->type = BT_REAL; ts->kind = gfc_default_double_kind; @@ -4093,7 +4099,10 @@ gfc_match_decl_type_spec (gfc_typespec *ts, int implicit_flag) return MATCH_ERROR; if (matched_type && gfc_match_char (')') != MATCH_YES) - return MATCH_ERROR; + { + gfc_error ("Malformed type-spec at %C"); + return MATCH_ERROR; + } ts->type = BT_COMPLEX; ts->kind = gfc_default_double_kind; @@ -4114,7 +4123,13 @@ gfc_match_decl_type_spec (gfc_typespec *ts, int implicit_flag) if (m == MATCH_ERROR) return m; - m = gfc_match_char (')'); + gfc_gobble_whitespace (); + if (gfc_peek_ascii_char () != ')') + { + gfc_error ("Malformed type-spec at %C"); + return MATCH_ERROR; + } + m = gfc_match_char (')'); /* Burn closing ')'. */ } if (m != MATCH_YES) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 70387abaa8ed..599bb43c50e2 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,10 @@ +2019-09-05 Steven G. Kargl + + PR fortran/91660 + * gfortran.dg/pdt_4.f03: Fix invalid code. + * gfortran.dg/pr91660_1.f90: New test. + * gfortran.dg/pr91660_2.f90: Ditto. + 2019-09-04 Wilco Dijkstra Backport from mainline diff --git a/gcc/testsuite/gfortran.dg/pdt_4.f03 b/gcc/testsuite/gfortran.dg/pdt_4.f03 index 0bb58f91c67d..c1af65a52487 100644 --- a/gcc/testsuite/gfortran.dg/pdt_4.f03 +++ b/gcc/testsuite/gfortran.dg/pdt_4.f03 @@ -97,9 +97,9 @@ contains type (mytype(4, *)) :: arg ! OK end subroutine subroutine bar(arg) ! { dg-error "is neither allocatable nor a pointer" } - type (thytype(8, :, 4) :: arg + type (thytype(8, :, 4)) :: arg end subroutine subroutine foobar(arg) ! OK - type (thytype(8, *, 4) :: arg + type (thytype(8, *, 4)) :: arg end subroutine end diff --git a/gcc/testsuite/gfortran.dg/pr91660_1.f90 b/gcc/testsuite/gfortran.dg/pr91660_1.f90 new file mode 100644 index 000000000000..53a1a808a7b5 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr91660_1.f90 @@ -0,0 +1,9 @@ +! { dg-do compile } +! PR fortran/91660 +! Code contributed by Gerhard Steinmetz +program p + type t + end type + type (t x ! { dg-error "Malformed type-spec" } + x = t() ! { dg-error "Cannot convert" } +end diff --git a/gcc/testsuite/gfortran.dg/pr91660_2.f90 b/gcc/testsuite/gfortran.dg/pr91660_2.f90 new file mode 100644 index 000000000000..0072aba16802 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr91660_2.f90 @@ -0,0 +1,9 @@ +! { dg-do compile } +! PR fortran/91660 +program foo + type(doubleprecision :: x ! { dg-error "Malformed type-spec" } + type(double precision :: y ! { dg-error "Malformed type-spec" } + type(character(len=3) :: a ! { dg-error "Malformed type-spec" } + type(doublecomplex :: b ! { dg-error "Malformed type-spec" } + type(double complex :: c ! { dg-error "Malformed type-spec" } +end program foo