From patchwork Sun Jan 4 18:57:47 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tobias Burnus X-Patchwork-Id: 425183 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 C0B53140082 for ; Mon, 5 Jan 2015 05:58:15 +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 :message-id:date:from:mime-version:to:cc:subject:references :in-reply-to:content-type; q=dns; s=default; b=yu3tK0vlry/vBUKTS B8H492FTYL22xeK7B2q6yvDlyFnUEY6uFUfNGRVXcnoehRsg6IdDuVWY8VDb6Oaw mOvrOtikpCX8L4g6CXQAmw6Iiq7GmeJAFu6L80xjV1ktncIKyT//W6cBIqIMdClA RuOsJkPUK4n029lbWeupqQqwB4= 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 :message-id:date:from:mime-version:to:cc:subject:references :in-reply-to:content-type; s=default; bh=/795cO6fddX3jjh+WM0t66S SN+c=; b=S5o2Yg0mQv1m1tu3VbvSFkki4lxvM1i2jB3C8BsyDWsJQ/Fbg8Pht+A e3L3j8PJApAYAk/wkOmqpx6DNu0dM/siPgS2//R7ZVkRNXecFjbJEuQQo47Jy8CF B2WtmD/kU5CUvNeQjX74XInmcAf5rV0utUm8nXDIQEcvt1Rz1gSM= Received: (qmail 10528 invoked by alias); 4 Jan 2015 18:58:06 -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 10504 invoked by uid 89); 4 Jan 2015 18:58:04 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.0 required=5.0 tests=AWL, BAYES_00 autolearn=ham version=3.3.2 X-Spam-User: qpsmtpd, 2 recipients X-HELO: outpost5.zedat.fu-berlin.de Received: from outpost5.zedat.fu-berlin.de (HELO outpost5.zedat.fu-berlin.de) (130.133.4.89) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Sun, 04 Jan 2015 18:58:02 +0000 Received: from relay1.zedat.fu-berlin.de ([130.133.4.67]) by outpost.zedat.fu-berlin.de (Exim 4.82) with esmtp (envelope-from ) id <1Y7qNC-0038Yi-AZ>; Sun, 04 Jan 2015 19:57:58 +0100 Received: from squeeze64.physik.fu-berlin.de ([160.45.66.239] helo=tux.net-b.de) by relay1.zedat.fu-berlin.de (Exim 4.82) with esmtp (envelope-from ) id <1Y7qN8-001lan-6M>; Sun, 04 Jan 2015 19:57:58 +0100 Message-ID: <54A98D2B.1090900@net-b.de> Date: Sun, 04 Jan 2015 19:57:47 +0100 From: Tobias Burnus User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.3.0 MIME-Version: 1.0 To: =?windows-1252?Q?Dominique_d=27Humi=E8res?= CC: fortran@gcc.gnu.org, gcc-patches@gcc.gnu.org, fxcoudert@gmail.com Subject: [Patch, Fortran] Fix previous patch (was: Re: [Patch, Fortran + Testsuite] Fix coarray handling in modules) References: <20150103102245.BAB57105@mailhost.lps.ens.fr> <54A855FB.3050207@net-b.de> <54A86D6A.2030101@net-b.de> In-Reply-To: Attached is a regtested patch, which fixes the issue. Additionally, the variable visibility (TREE_PUBLIC) is now depending on the private attribute (copied from the module var generation) and I mark the tree as DECL_NONALIASED. The former I also did for proc-pointers, which is an unrelated patch. Build and regtested on x86-64-gnu-linux. OK for the trunk? Dominique d'Humières wrote: > Compilation with the new patch fails with > ../../work/gcc/fortran/trans-decl.c: In function 'void gfc_build_qualified_array(tree, gfc_symbol*)': > ../../work/gcc/fortran/trans-decl.c:855:25: error: 'cur_module' was not declared in this scope > gfc_module_add_decl (cur_module, token); Which shows that w/o compiling and testing, one (usually) cannot write patches. Solution is to move the declaration up in the file. However, it turned out that that's not sufficient: the pushdecl is required. Tobias >> Le 3 janv. 2015 à 23:30, Tobias Burnus a écrit : >> >> Dominique d'Humières wrote: >>> From a quick test, with the patch I still see the error with -m32 >> It helps if one actually adds the decl. The following (still untested) should help. I also marked the token as nonaliasing (it really should!) and added for proc pointers the tree-public optimization. >> >> Tobias >> > 2015-01-02 Tobias Burnus * trans-decl.c (gfc_build_qualified_array): Fix coarray tokens for module coarrays with -fcoarray=lib. (get_proc_pointer_decl): As module variable, make only public when not marked as private. * gfortran.dg/coarray/codimension_2b.f90: New file. * gfortran.dg/coarray/codimension_2.f90: Add it to dg-extra-sources. * gfortran.dg/coarray/codimension_2.f90: Call its subroutine. diff --git a/gcc/fortran/trans-decl.c b/gcc/fortran/trans-decl.c index 9ef6bfc..dfc0f23 100644 --- a/gcc/fortran/trans-decl.c +++ b/gcc/fortran/trans-decl.c @@ -87,6 +87,8 @@ static gfc_namespace *module_namespace; /* The currently processed procedure symbol. */ static gfc_symbol* current_procedure_symbol = NULL; +/* The currently processed module. */ +static struct module_htab_entry *cur_module; /* With -fcoarray=lib: For generating the registering call of static coarrays. */ @@ -830,15 +832,33 @@ gfc_build_qualified_array (tree decl, gfc_symbol * sym) IDENTIFIER_POINTER (gfc_sym_mangled_identifier (sym)))); token = build_decl (DECL_SOURCE_LOCATION (decl), VAR_DECL, token_name, token_type); - TREE_PUBLIC (token) = 1; + if (sym->attr.use_assoc) + DECL_EXTERNAL (token) = 1; + else + TREE_STATIC (token) = 1; + + if (sym->attr.use_assoc || sym->attr.access != ACCESS_PRIVATE || + sym->attr.public_used) + TREE_PUBLIC (token) = 1; } else - token = gfc_create_var_np (token_type, "caf_token"); + { + token = gfc_create_var_np (token_type, "caf_token"); + TREE_STATIC (token) = 1; + } GFC_TYPE_ARRAY_CAF_TOKEN (type) = token; DECL_ARTIFICIAL (token) = 1; - TREE_STATIC (token) = 1; - gfc_add_decl_to_function (token); + DECL_NONALIASED (token) = 1; + + if (sym->module && !sym->attr.use_assoc) + { + pushdecl (token); + DECL_CONTEXT (token) = sym->ns->proc_name->backend_decl; + gfc_module_add_decl (cur_module, token); + } + else + gfc_add_decl_to_function (token); } for (dim = 0; dim < GFC_TYPE_ARRAY_RANK (type); dim++) @@ -1664,7 +1684,9 @@ get_proc_pointer_decl (gfc_symbol *sym) else if (sym->module && sym->ns->proc_name->attr.flavor == FL_MODULE) { /* This is the declaration of a module variable. */ - TREE_PUBLIC (decl) = 1; + if (sym->ns->proc_name->attr.flavor == FL_MODULE + && (sym->attr.access != ACCESS_PRIVATE || sym->attr.public_used)) + TREE_PUBLIC (decl) = 1; TREE_STATIC (decl) = 1; } @@ -4326,8 +4348,6 @@ gfc_module_add_decl (struct module_htab_entry *entry, tree decl) *slot = decl; } -static struct module_htab_entry *cur_module; - /* Generate debugging symbols for namelists. This function must come after generate_local_decl to ensure that the variables in the namelist are diff --git a/gcc/testsuite/gfortran.dg/coarray/codimension_2.f90 b/gcc/testsuite/gfortran.dg/coarray/codimension_2.f90 index b211f9b..45d3374 100644 --- a/gcc/testsuite/gfortran.dg/coarray/codimension_2.f90 +++ b/gcc/testsuite/gfortran.dg/coarray/codimension_2.f90 @@ -1,5 +1,5 @@ ! { dg-do link } -! { dg-additional-sources codimension_2a.f90 } +! { dg-additional-sources "codimension_2a.f90 codimension_2b.f90" } ! ! To be used with codimension_2a.f90 ! Check that the coarray declared in the module is accessible diff --git a/gcc/testsuite/gfortran.dg/coarray/codimension_2a.f90 b/gcc/testsuite/gfortran.dg/coarray/codimension_2a.f90 index 8eb472c..3dec4aa 100644 --- a/gcc/testsuite/gfortran.dg/coarray/codimension_2a.f90 +++ b/gcc/testsuite/gfortran.dg/coarray/codimension_2a.f90 @@ -11,6 +11,7 @@ program testmod use global_coarrays implicit none + external ttest integer :: me @@ -21,6 +22,8 @@ program testmod if(me==1) then b(:) = b(:)[2] write(*,*) b + elseif (me == 3) then + call ttest() end if end program testmod diff --git a/gcc/testsuite/gfortran.dg/coarray/codimension_2b.f90 b/gcc/testsuite/gfortran.dg/coarray/codimension_2b.f90 new file mode 100644 index 0000000..c30d051 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/coarray/codimension_2b.f90 @@ -0,0 +1,13 @@ +! { dg-do compile { target { ! *-*-* } } } +! SKIP THIS FILE +! +! Used by codimension_2.f90 +! +! Additional file to check that using the module doesn't generate +! a token symbol. (The module is also used by codimension_2.f90.) +! +subroutine ttest + use global_coarrays + implicit none + b(:) = b(:)[2] +end