From patchwork Fri Oct 4 23:24:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Kargl X-Patchwork-Id: 1172087 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-510325-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="tjokcvEd"; 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 46lQvX4yNVz9sP7 for ; Sat, 5 Oct 2019 09:24:54 +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=eJV+VtU97g86sKSGW/QV9a3G+3b3h++mAu4rIks3n+4 HaZI6TAaL6HSqb6Krxc+b0mSPqo7orzfw2iRGMCT7Ab7fl8lR+wk/7Ddq30/8lro BXiqiBWqCfHQ3WYxnwjUkaWiWuo1qEEina44OBwqXTQukoUWKDtx3rfEx37KWZ74 = 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=/R6ZHAC9IMDOC1yzGPd+VfChb1M=; b=tjokcvEdjhmOOWrU9 Cpr4+tkAc3QvIPh7ked5NTP7C/biM7Uww+9dKQEOfNIBh+XyzSn/b63/R1nO8vhu TPpPR5lmy6NcoueeUF7laroxR5sCOKGgMBtlA8dqLl/GBtGvVq52wlAu59PnnkyU 07OSrlFVhVQcmSVRLpfTYY3j2c= Received: (qmail 107436 invoked by alias); 4 Oct 2019 23:24:41 -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 107374 invoked by uid 89); 4 Oct 2019 23:24:34 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-8.3 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS autolearn=ham version=3.3.1 spammy=yahoo 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, 04 Oct 2019 23:24:32 +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 x94NONEu051534 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Fri, 4 Oct 2019 16:24:23 -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 x94NONii051533; Fri, 4 Oct 2019 16:24:23 -0700 (PDT) (envelope-from sgk) Date: Fri, 4 Oct 2019 16:24:23 -0700 From: Steve Kargl To: fortran@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [PATCH] PR fortran/47054 -- Don't search parent namespace for symbol Message-ID: <20191004232423.GA51528@troutmask.apl.washington.edu> Reply-To: sgk@troutmask.apl.washington.edu MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.12.1 (2019-06-15) I plan to commit this as obviously correct tomorrow morning. However, as the bug has been open for nearly 9 years, I give anyone reading this a chance to speak up. 2019-10-04 Steven G. Kargl PR fortran/47045 * decl.c (variable_decl): Do not search parent namespace for symbol. 2019-10-04 Steven G. Kargl PR fortran/47045 * gfortran.dg/pr47054_1.f90: New test * gfortran.dg/pr47054_2.f90: Ditto. Index: gcc/fortran/decl.c =================================================================== --- gcc/fortran/decl.c (revision 276601) +++ gcc/fortran/decl.c (working copy) @@ -2682,7 +2682,7 @@ variable_decl (int elem) then we want to set the type & bail out. */ if (flag_cray_pointer && !gfc_comp_struct (gfc_current_state ())) { - gfc_find_symbol (name, gfc_current_ns, 1, &sym); + gfc_find_symbol (name, gfc_current_ns, 0, &sym); if (sym != NULL && sym->attr.cray_pointee) { m = MATCH_YES; @@ -7259,13 +7259,16 @@ gfc_match_function_decl (void) if (sym->attr.is_bind_c == 1) { sym->attr.is_bind_c = 0; - if (sym->old_symbol != NULL) - gfc_error_now ("BIND(C) attribute at %L can only be used for " - "variables or common blocks", - &(sym->old_symbol->declared_at)); - else - gfc_error_now ("BIND(C) attribute at %L can only be used for " - "variables or common blocks", &gfc_current_locus); + + if (gfc_state_stack->previous + && gfc_state_stack->previous->state != COMP_SUBMODULE) + { + locus loc; + loc = sym->old_symbol != NULL + ? sym->old_symbol->declared_at : gfc_current_locus; + gfc_error_now ("BIND(C) attribute at %L can only be used for " + "variables or common blocks", &loc); + } } if (found_match != MATCH_YES) @@ -7517,16 +7520,16 @@ gfc_match_entry (void) not allowed for procedures. */ if (entry->attr.is_bind_c == 1) { + locus loc; + entry->attr.is_bind_c = 0; - if (entry->old_symbol != NULL) - gfc_error_now ("BIND(C) attribute at %L can only be used for " - "variables or common blocks", - &(entry->old_symbol->declared_at)); - else - gfc_error_now ("BIND(C) attribute at %L can only be used for " - "variables or common blocks", &gfc_current_locus); - } + loc = entry->old_symbol != NULL + ? entry->old_symbol->declared_at : gfc_current_locus; + gfc_error_now ("BIND(C) attribute at %L can only be used for " + "variables or common blocks", &loc); + } + /* Check what next non-whitespace character is so we can tell if there is the required parens if we have a BIND(C). */ old_loc = gfc_current_locus; @@ -7725,13 +7728,16 @@ gfc_match_subroutine (void) if (sym->attr.is_bind_c == 1) { sym->attr.is_bind_c = 0; - if (sym->old_symbol != NULL) - gfc_error_now ("BIND(C) attribute at %L can only be used for " - "variables or common blocks", - &(sym->old_symbol->declared_at)); - else - gfc_error_now ("BIND(C) attribute at %L can only be used for " - "variables or common blocks", &gfc_current_locus); + + if (gfc_state_stack->previous + && gfc_state_stack->previous->state != COMP_SUBMODULE) + { + locus loc; + loc = sym->old_symbol != NULL + ? sym->old_symbol->declared_at : gfc_current_locus; + gfc_error_now ("BIND(C) attribute at %L can only be used for " + "variables or common blocks", &loc); + } } /* C binding names are not allowed for internal procedures. */ Index: gcc/testsuite/gfortran.dg/pr47054_1.f90 =================================================================== --- gcc/testsuite/gfortran.dg/pr47054_1.f90 (nonexistent) +++ gcc/testsuite/gfortran.dg/pr47054_1.f90 (working copy) @@ -0,0 +1,15 @@ +! { dg-do compile } +! { dg-options "-fcray-pointer" } +! PR fortran/47054 +subroutine host_sub + implicit none + real xg + pointer (paxg, xg) + call internal_sub + contains + subroutine internal_sub + implicit none + real xg + pointer (paxg, xg) + end subroutine internal_sub +end subroutine host_sub Index: gcc/testsuite/gfortran.dg/pr47054_2.f90 =================================================================== --- gcc/testsuite/gfortran.dg/pr47054_2.f90 (nonexistent) +++ gcc/testsuite/gfortran.dg/pr47054_2.f90 (working copy) @@ -0,0 +1,41 @@ +! { dg-do compile } +! { dg-options "-fcray-pointer" } +! PR fortran/47054 +! Code contributed by Deji Akingunola +subroutine host_sub(F_su,F_nk) + implicit none + + integer :: F_nk + real,dimension(F_nk) :: F_su + integer G_ni, G_nj + real*8 G_xg_8, G_yg_8 + pointer (paxg_8, G_xg_8(G_ni)) + pointer (payg_8, G_yg_8(G_nj)) + common / G_p / paxg_8,payg_8 + common / G / G_ni, G_nj + + call internal_sub(F_su,F_nk) + return +contains + + subroutine internal_sub(F_su,F_nk) + implicit none + integer G_ni, G_nj + real*8 G_xg_8, G_yg_8 + pointer (paxg_8, G_xg_8(G_ni)) + pointer (payg_8, G_yg_8(G_nj)) + common / G_p / paxg_8,payg_8 + common / G / G_ni, G_nj + + integer :: F_nk + real,dimension(F_nk) :: F_su + integer k,k2 + + k2 = 0 + do k = 1, F_nk, 2 + k2 = k2+1 + F_su(k) = F_su(k) + 1.0 + enddo + return + end subroutine internal_sub +end subroutine host_sub