From 2810dfab5c2abd27245d8b4e508bb40e955c095f Mon Sep 17 00:00:00 2001 From: "Steven G. Kargl" Date: Mon, 22 Apr 2019 21:00:40 +0000 Subject: [PATCH] re PR fortran/90166 (Compiler Fails at Assembler) 2019-04-19 Steven G. Kargl PR fortran/90166 * decl.c (in_module_or_interface): New function to check that the current state is in a module, submodule, or interface. (gfc_match_prefix): Use it. 2019-04-19 Steven G. Kargl PR fortran/90166 * gfortran.dg/submodule_22.f08: Add additional dg-error comments. From-SVN: r270495 --- gcc/fortran/ChangeLog | 7 ++++++ gcc/fortran/decl.c | 29 ++++++++++++++++++++++ gcc/testsuite/ChangeLog | 5 ++++ gcc/testsuite/gfortran.dg/submodule_22.f08 | 8 +++--- 4 files changed, 45 insertions(+), 4 deletions(-) diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 6a11bf5514b..12cb55c2dcb 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,10 @@ +2019-04-19 Steven G. Kargl + + PR fortran/90166 + * decl.c (in_module_or_interface): New function to check that the + current state is in a module, submodule, or interface. + (gfc_match_prefix): Use it. + 2019-04-22 Paul Thomas PR fortran/57284 diff --git a/gcc/fortran/decl.c b/gcc/fortran/decl.c index 749faf9fabe..66f1094aa3d 100644 --- a/gcc/fortran/decl.c +++ b/gcc/fortran/decl.c @@ -6070,6 +6070,28 @@ cleanup: return m; } +static bool +in_module_or_interface(void) +{ + if (gfc_current_state () == COMP_MODULE + || gfc_current_state () == COMP_SUBMODULE + || gfc_current_state () == COMP_INTERFACE) + return true; + + if (gfc_state_stack->state == COMP_CONTAINS + || gfc_state_stack->state == COMP_FUNCTION + || gfc_state_stack->state == COMP_SUBROUTINE) + { + gfc_state_data *p; + for (p = gfc_state_stack->previous; p ; p = p->previous) + { + if (p->state == COMP_MODULE || p->state == COMP_SUBMODULE + || p->state == COMP_INTERFACE) + return true; + } + } + return false; +} /* Match a prefix associated with a function or subroutine declaration. If the typespec pointer is nonnull, then a typespec @@ -6103,6 +6125,13 @@ gfc_match_prefix (gfc_typespec *ts) if (!gfc_notify_std (GFC_STD_F2008, "MODULE prefix at %C")) goto error; + if (!in_module_or_interface ()) + { + gfc_error ("MODULE prefix at %C found outside of a module, " + "submodule, or interface"); + goto error; + } + current_attr.module_procedure = 1; found_prefix = true; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 4d10bfd0b08..e22996fde9c 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2019-04-22 Steven G. Kargl + + PR fortran/90166 + * gfortran.dg/submodule_22.f08: Add additional dg-error comments. + 2019-04-22 Paul Thomas PR fortran/57284 diff --git a/gcc/testsuite/gfortran.dg/submodule_22.f08 b/gcc/testsuite/gfortran.dg/submodule_22.f08 index 8ff5421c77e..eab398fd3d3 100644 --- a/gcc/testsuite/gfortran.dg/submodule_22.f08 +++ b/gcc/testsuite/gfortran.dg/submodule_22.f08 @@ -40,8 +40,8 @@ end submodule (mtop:submod:subsubmod) subsubsubmod ! { dg-error "Syntax error in SUBMODULE statement" } contains - module subroutine sub3 - r = 2.0 - s = 2.0 - end subroutine sub3 + module subroutine sub3 ! { dg-error "found outside of a module" } + r = 2.0 ! { dg-error "Unexpected assignment" } + s = 2.0 ! { dg-error "Unexpected assignment" } + end subroutine sub3 ! { dg-error "Expecting END PROGRAM statement" } end -- 2.30.2