From c4770ba091d96aea469c79067b549bbc8f8c7c63 Mon Sep 17 00:00:00 2001 From: "Steven G. Kargl" Date: Sun, 29 Sep 2019 16:19:58 +0000 Subject: [PATCH] re PR fortran/91714 (Accepts type statement without delimiter in free form) 2019-09-29 Steven G. Kargl PR fortran/91714 * decl.c (gfc_match_decl_type_spec): Issue errors for a few mangled types. 2019-09-29 Steven G. Kargl PR fortran/91714 * gfortran.dg/dec_type_print_3.f90: Update dg-error regex. * gfortran.dg/pr91714.f90: New test. From-SVN: r276270 --- gcc/fortran/ChangeLog | 6 +++++ gcc/fortran/decl.c | 22 +++++++++++++++++-- gcc/testsuite/ChangeLog | 6 +++++ .../gfortran.dg/dec_type_print_3.f90 | 4 ++-- gcc/testsuite/gfortran.dg/pr91714.f90 | 10 +++++++++ 5 files changed, 44 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/pr91714.f90 diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 8fc562531c9..d4f39cc6dfa 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,9 @@ +2019-09-29 Steven G. Kargl + + PR fortran/91714 + * decl.c (gfc_match_decl_type_spec): Issue errors for a few + mangled types. + 2019-09-29 Paul Thomas PR fortran/91726 diff --git a/gcc/fortran/decl.c b/gcc/fortran/decl.c index b6add1c0bb8..3ba61a08381 100644 --- a/gcc/fortran/decl.c +++ b/gcc/fortran/decl.c @@ -4444,6 +4444,7 @@ get_kind: gfc_next_ascii_char (); return MATCH_YES; } + gfc_error ("Malformed type-spec at %C"); return MATCH_NO; } } @@ -4457,7 +4458,10 @@ get_kind: } if (matched_type && gfc_match_char (')') != MATCH_YES) - return MATCH_ERROR; + { + gfc_error ("Malformed type-spec at %C"); + return MATCH_ERROR; + } /* Defer association of the KIND expression of function results until after USE and IMPORT statements. */ @@ -10240,6 +10244,20 @@ gfc_match_derived_decl (void) return MATCH_ERROR; } + /* In free source form, need to check for TYPE XXX as oppose to TYPEXXX. + But, we need to simply return for TYPE(. */ + if (m == MATCH_NO && gfc_current_form == FORM_FREE) + { + char c = gfc_peek_ascii_char (); + if (c == '(') + return m; + if (!gfc_is_whitespace (c)) + { + gfc_error ("Mangled derived type definition at %C"); + return MATCH_NO; + } + } + m = gfc_match (" %n ", name); if (m != MATCH_YES) return m; @@ -10247,7 +10265,7 @@ gfc_match_derived_decl (void) /* Make sure that we don't identify TYPE IS (...) as a parameterized derived type named 'is'. TODO Expand the check, when 'name' = "is" by matching " (tname) " - and checking if this is a(n intrinsic) typename. his picks up + and checking if this is a(n intrinsic) typename. This picks up misplaced TYPE IS statements such as in select_type_1.f03. */ if (gfc_peek_ascii_char () == '(') { diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index a23c7286a6d..052fd2e1f8a 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2019-09-29 Steven G. Kargl + + PR fortran/91714 + * gfortran.dg/dec_type_print_3.f90: Update dg-error regex. + * gfortran.dg/pr91714.f90: New test. + 2019-09-29 Paul Thomas PR fortran/91726 diff --git a/gcc/testsuite/gfortran.dg/dec_type_print_3.f90 b/gcc/testsuite/gfortran.dg/dec_type_print_3.f90 index 409e991b84b..27f117d3f86 100644 --- a/gcc/testsuite/gfortran.dg/dec_type_print_3.f90 +++ b/gcc/testsuite/gfortran.dg/dec_type_print_3.f90 @@ -8,9 +8,9 @@ include 'dec_type_print.f90' -! { dg-error "Invalid character in name" "" { target *-*-* } 52 } +! { dg-error "Mangled derived type definition" "" { target *-*-* } 52 } ! { dg-error "Invalid character in name" "" { target *-*-* } 53 } -! { dg-error "Invalid character in name" "" { target *-*-* } 54 } +! { dg-error "Mangled derived type definition" "" { target *-*-* } 54 } ! { dg-error "Invalid character in name" "" { target *-*-* } 55 } ! { dg-error "Invalid character in name" "" { target *-*-* } 56 } ! { dg-error "Invalid character in name" "" { target *-*-* } 57 } diff --git a/gcc/testsuite/gfortran.dg/pr91714.f90 b/gcc/testsuite/gfortran.dg/pr91714.f90 new file mode 100644 index 00000000000..8b855d90318 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr91714.f90 @@ -0,0 +1,10 @@ +! { dg-do compile } +! Contributed by Gerhard Steinmetz +program p + typea ! { dg-error "Mangled derived type" } + integer b + end type ! { dg-error "Expecting END PROGRAM" } + type(a) :: c ! { dg-error "is being used before it" } + c = a(1) + print *, c +end -- 2.30.2