From patchwork Fri Apr 19 21:44:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Kargl X-Patchwork-Id: 1088240 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-499494-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=troutmask.apl.washington.edu Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="f1KXJn2g"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44m8dc5s9Sz9s4Y for ; Sat, 20 Apr 2019 07:44:46 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:reply-to:mime-version:content-type; q=dns; s=default; b=L00raqQ5vLj1FMVpkLJiN+uSE7fQs2Wiyn/y1fUo260 tinpX65xR7gd1i4WILMyAtV4k32rW3RgJqpnhwqHQ6nvvPn2FQlHC23YlUjVrPpx 1WxkxxUGc4CLSKmiSMkiA56hbJOCuIMIxl3VVKhhD+aRnUrdZ67Zebo3A+KrxJWU = DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:reply-to:mime-version:content-type; s=default; bh=lD5byRkGMCCo3EvHKrkh71JrsIs=; b=f1KXJn2g6UBXij9M8 XZ//NkXLinSBP0lq7UZ+KTXyMku1vzWAqXQq4OubK+wYi4xS46wG6JIsC4mLFBtx twaRkXq0uX7UzMXVtFv797hnsQnjdIcX6X9ooQdcL3G84pHGXWoUX5h6u1JngXjs PGefiTIaC0H1Q5J2T2oF8JFq+Q= Received: (qmail 5308 invoked by alias); 19 Apr 2019 21:44:35 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 5217 invoked by uid 89); 19 Apr 2019 21:44:31 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-7.5 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, KAM_NUMSUBJECT autolearn=ham version=3.3.1 spammy=PROGRAM, Steven, feeding, tokens X-HELO: troutmask.apl.washington.edu Received: from troutmask.apl.washington.edu (HELO troutmask.apl.washington.edu) (128.95.76.21) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 19 Apr 2019 21:44:30 +0000 Received: from troutmask.apl.washington.edu (localhost [127.0.0.1]) by troutmask.apl.washington.edu (8.15.2/8.15.2) with ESMTPS id x3JLiSlV098009 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Fri, 19 Apr 2019 14:44:28 -0700 (PDT) (envelope-from sgk@troutmask.apl.washington.edu) Received: (from sgk@localhost) by troutmask.apl.washington.edu (8.15.2/8.15.2/Submit) id x3JLiRoW098008; Fri, 19 Apr 2019 14:44:27 -0700 (PDT) (envelope-from sgk) Date: Fri, 19 Apr 2019 14:44:27 -0700 From: Steve Kargl To: fortran@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [PATCH] PR fortran/90166 -- check F2018:C1547 Message-ID: <20190419214427.GA97981@troutmask.apl.washington.edu> Reply-To: sgk@troutmask.apl.washington.edu MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.11.2 (2019-01-07) 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 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. 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