From: Steve Kargl <sgk@troutmask.apl.washington.edu>
To: fortran@gcc.gnu.org, gcc-patches@gcc.gnu.org
Subject: [PATCH] PR fortran/90166 -- check F2018:C1547
Date: Fri, 19 Apr 2019 22:12:00 -0000 [thread overview]
Message-ID: <20190419214427.GA97981@troutmask.apl.washington.edu> (raw)
[-- Attachment #1: Type: text/plain, Size: 656 bytes --]
The attached patch fixes PR fortran/91066. The original
code was feeding a nonsense string of tokens to the
assembler causing it to toss its cookies. It turns out
that gfortran was not enforcing the constraint C1547
from Fortran 2018. The attached patch now performs
that check. Regression tested on x86_64-*-freebsd.
OK to commit?
2019-04-19 Steven G. Kargl <kargl@gcc.gnu.org>
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.
PR fortran/90166
* gfortran.dg/submodule_22.f08: Add additional dg-error comments.
--
Steve
[-- Attachment #2: pr90166.diff --]
[-- Type: text/x-diff, Size: 2188 bytes --]
Index: gcc/fortran/decl.c
===================================================================
--- gcc/fortran/decl.c (revision 270181)
+++ gcc/fortran/decl.c (working copy)
@@ -6070,7 +6070,29 @@ 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
can be matched. Note that if nothing matches, MATCH_YES is
@@ -6102,6 +6124,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;
Index: gcc/testsuite/gfortran.dg/submodule_22.f08
===================================================================
--- gcc/testsuite/gfortran.dg/submodule_22.f08 (revision 270181)
+++ gcc/testsuite/gfortran.dg/submodule_22.f08 (working copy)
@@ -40,8 +40,10 @@ 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
+
+found outside of a module
next reply other threads:[~2019-04-19 21:44 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-19 22:12 Steve Kargl [this message]
2019-04-20 18:37 ` Paul Richard Thomas
2019-04-20 16:57 Dominique d'Humières
2019-04-20 17:21 ` Steve Kargl
2019-04-20 19:51 ` Steve Kargl
2019-04-20 20:30 ` Dominique d'Humières
2019-04-21 18:03 ` Steve Kargl
2019-04-22 13:53 ` Dominique d'Humières
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190419214427.GA97981@troutmask.apl.washington.edu \
--to=sgk@troutmask.apl.washington.edu \
--cc=fortran@gcc.gnu.org \
--cc=gcc-patches@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).