From patchwork Fri Jan 25 01:49:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Kargl X-Patchwork-Id: 1030758 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-494714-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="IvQrmVg6"; 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 43m25d6L53z9s55 for ; Fri, 25 Jan 2019 12:49:56 +1100 (AEDT) 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=S1fwcSC3L6ZjSCLD/2wYMLSsutlsMYmY4vWSh/Im44a MLihBhe0QJdR+RBZwt7DqXNwn2ufDF+aqTK+H4rlQhwfRWF2m/JvhfyAt1vAgM0C +tDgufPq9yivugWUzPY7QwFMg6pisA7OjqTqlt4eyCm3aHM7B7HvGkGTWY8Ya634 = 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=A+q51ijNUCrsCb7S363LWutq2Ec=; b=IvQrmVg6rpe7i1w0A D4ds07BkRqvr2Tgb5R1fhK2iW4nbpX39yimwey7XpVbVaw+seiE5nO/rHsHT980p Y8fJBGCR1n9DyEcjaI7bp78Yz6Ktimf+ReHRW46ctDxuby2isuG09uYgWa+wOitM rjTB/fk5nxRL9isnIau0G8VQec= Received: (qmail 26626 invoked by alias); 25 Jan 2019 01:49:46 -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 26361 invoked by uid 89); 25 Jan 2019 01:49:42 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-10.1 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, KAM_LAZY_DOMAIN_SECURITY autolearn=ham version=3.3.2 spammy= 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, 25 Jan 2019 01:49:41 +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 x0P1ndUE089522 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Thu, 24 Jan 2019 17:49:39 -0800 (PST) (envelope-from sgk@troutmask.apl.washington.edu) Received: (from sgk@localhost) by troutmask.apl.washington.edu (8.15.2/8.15.2/Submit) id x0P1ndR5089521; Thu, 24 Jan 2019 17:49:39 -0800 (PST) (envelope-from sgk) Date: Thu, 24 Jan 2019 17:49:39 -0800 From: Steve Kargl To: fortran@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [PATCH] PR fortran/85780 -- alternate return and BIND(C) conflict Message-ID: <20190125014939.GA89513@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) All, My original patch for this PR simply fixed an ICE, which then allowed the code to compile. In reality, an alternate return is not ISO C interoperable, so an error message is a more appropriate response. So, I re-opened the PR. The attached patch has been tested on x86_64-*-freebsd. OK to commit? 2019-01-24 Steven G. Kargl PR fortran/85780 * decl.c (gfc_match_subroutine): Check for conflict between BIND(C) and alternative return. 2019-01-24 Steven G. Kargl PR fortran/85780 * gfortran.dg/pr85780.f90: Update testcase for error message. Index: gcc/fortran/decl.c =================================================================== --- gcc/fortran/decl.c (revision 268256) +++ gcc/fortran/decl.c (working copy) @@ -7558,6 +7558,7 @@ gfc_match_subroutine (void) match is_bind_c; char peek_char; bool allow_binding_name; + locus loc; if (gfc_current_state () != COMP_NONE && gfc_current_state () != COMP_INTERFACE @@ -7623,6 +7624,8 @@ gfc_match_subroutine (void) /* Here, we are just checking if it has the bind(c) attribute, and if so, then we need to make sure it's all correct. If it doesn't, we still need to continue matching the rest of the subroutine line. */ + gfc_gobble_whitespace (); + loc = gfc_current_locus; is_bind_c = gfc_match_bind_c (sym, allow_binding_name); if (is_bind_c == MATCH_ERROR) { @@ -7634,6 +7637,8 @@ gfc_match_subroutine (void) if (is_bind_c == MATCH_YES) { + gfc_formal_arglist *arg; + /* The following is allowed in the Fortran 2008 draft. */ if (gfc_current_state () == COMP_CONTAINS && sym->ns->proc_name->attr.flavor != FL_MODULE @@ -7647,8 +7652,17 @@ gfc_match_subroutine (void) gfc_error ("Missing required parentheses before BIND(C) at %C"); return MATCH_ERROR; } - if (!gfc_add_is_bind_c (&(sym->attr), sym->name, - &(sym->declared_at), 1)) + + /* Scan the dummy arguments for an alternate return. */ + for (arg = sym->formal; arg; arg = arg->next) + if (!arg->sym) + { + gfc_error ("Alternate return dummy argument cannot appear in a " + "SUBROUTINE with the BIND(C) attribute at %L", &loc); + return MATCH_ERROR; + } + + if (!gfc_add_is_bind_c (&(sym->attr), sym->name, &(sym->declared_at), 1)) return MATCH_ERROR; } Index: gcc/testsuite/gfortran.dg/pr85780.f90 =================================================================== --- gcc/testsuite/gfortran.dg/pr85780.f90 (revision 268256) +++ gcc/testsuite/gfortran.dg/pr85780.f90 (working copy) @@ -1,5 +1,6 @@ ! { dg-do compile } -! { dg-options "-std=legacy" } +! { dg-options "-fmax-errors=1" } ! PR fortran/85780 -subroutine s(*) bind(c) +subroutine s(*) bind(c) ! { dg-error "Alternate return dummy argument" } end +! { dg-prune-output "compilation terminated" }