From patchwork Mon Nov 9 11:24:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tobias Burnus X-Patchwork-Id: 1396694 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CV7tf6tQqz9sVX for ; Mon, 9 Nov 2020 22:24:25 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 952593870913; Mon, 9 Nov 2020 11:24:20 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from esa3.mentor.iphmx.com (esa3.mentor.iphmx.com [68.232.137.180]) by sourceware.org (Postfix) with ESMTPS id 967C43857C65; Mon, 9 Nov 2020 11:24:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 967C43857C65 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=Tobias_Burnus@mentor.com IronPort-SDR: /0cS7neV3tAUzyCT7as3auSLq2yLulodzmR7tUTwhrBdgJT+59azRGjo9GoicVtKlHTk438ceI deTQmfA4pnMEVz45J9leBJdV6nmAgRj7wzY0so8MesWVvcNGABpknT/mqEn+TQAeelzEHkIVpz zyJr9OXgSCPlq23QSvX21JP1j3JfOaDgYVzaeZNAiKIsiOjp4IStyrRWUa4AmBmMzWnVnUOtDZ hMMyZVAYmSz1R5x5FMxe1a6gUa0Jn6fftiUTzg3MEN33vd49Ufvt8lKOq/gqAE6qssReRXlxPg Yvk= X-IronPort-AV: E=Sophos;i="5.77,463,1596528000"; d="diff'?scan'208";a="54835858" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa3.mentor.iphmx.com with ESMTP; 09 Nov 2020 03:24:16 -0800 IronPort-SDR: PPm/aWnSfBSaTpjx+pVV4UjOhPlUqbcuqS+bjY43byjBRvH7dQiNope+TMaIdi0FGhLNqswEeh gS7F8ebeVAqk/PhikWmZUA1BBgk0vT1ldjtsy01H2ZqIrdGIej9uQk1bFkWYkRKZIMtJ2Eqhr5 FITBJU3p04nF9wTs5PO6dH0/tM6/XY87fibVviZMC6Aksm3dyvmz85enYNLRSXAvfrIKOEZwQd Vv+v44Jgf8+E+THSEMe4Ja71OZksWO5dqaIPgX3vI1GlnCP5ERhAhnI+LJRvhwZCqhoC3/EZS8 mrg= To: gcc-patches , fortran , Thomas Schwinge From: Tobias Burnus Subject: [Patch] Fortran: Fix OpenACC in specification-part checks [PR90111] Message-ID: Date: Mon, 9 Nov 2020 12:24:10 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.4.1 MIME-Version: 1.0 Content-Language: en-US X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: svr-ies-mbx-09.mgc.mentorg.com (139.181.222.9) To svr-ies-mbx-01.mgc.mentorg.com (139.181.222.1) X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" OpenACC (as OpenMP) permits some directives in the 'specification part' In Fortran (here: Fortran 2018), the latter is: R504 specification-part is [use-stmt]... [import-stmt]... [implicit-part] [declaration-construct]... which is an ordered list (first use, then import etc.). Hence, gfortran's state_order lists the latter separately: enum state_order {ORDER_START, ORDER_USE, ORDER_IMPORT, ORDER_IMPLICIT_NONE, ORDER_IMPLICIT, ORDER_SPEC, ORDER_EXEC}; Currently, 'acc declare' and 'acc routine' are placed into '#define case_decl' which implies ORDER_SPEC. This patch adds them to the related OpenMP constructs ('case_omp_decl'), which does not touch the current state and just checks that the ST_... appear before ORDER_EXEC. If there are no comments, I intent to commit it later today. Tobias PS: Thanks to Thomas for pointing me to the PR. ----------------- Mentor Graphics (Deutschland) GmbH, Arnulfstraße 201, 80634 München / Germany Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Alexander Walter Fortran: Fix OpenACC in specification-part checks [PR90111] OpenACC's routine and declare directives can appear anywhere in the specification part, i.e. before/after use-stmts, import-stmt, implicit-part, or declaration-constructs. gcc/fortran/ChangeLog: PR fortran/90111 * parse.c (case_decl): Move ST_OACC_ROUTINE and ST_OACC_DECLARE to ... (case_omp_decl): ... here: (verify_st_order): Update comment. gcc/testsuite/ChangeLog: PR fortran/90111 * gfortran.dg/goacc/specification-part.f90: New test. gcc/fortran/parse.c | 11 +-- .../gfortran.dg/goacc/specification-part.f90 | 100 +++++++++++++++++++++ 2 files changed, 106 insertions(+), 5 deletions(-) diff --git a/gcc/fortran/parse.c b/gcc/fortran/parse.c index e57669c51e5..ec7abc240d6 100644 --- a/gcc/fortran/parse.c +++ b/gcc/fortran/parse.c @@ -1628,24 +1628,25 @@ next_statement (void) case ST_OACC_DATA: case ST_OACC_HOST_DATA: case ST_OACC_LOOP: \ case ST_OACC_KERNELS_LOOP: case ST_OACC_SERIAL_LOOP: case ST_OACC_SERIAL: \ case ST_OACC_ATOMIC /* Declaration statements */ #define case_decl case ST_ATTR_DECL: case ST_COMMON: case ST_DATA_DECL: \ case ST_EQUIVALENCE: case ST_NAMELIST: case ST_STATEMENT_FUNCTION: \ - case ST_TYPE: case ST_INTERFACE: case ST_PROCEDURE: case ST_OACC_ROUTINE: \ - case ST_OACC_DECLARE + case ST_TYPE: case ST_INTERFACE: case ST_PROCEDURE -/* OpenMP declaration statements. */ +/* OpenMP and OpenACC declaration statements, which may appear anywhere in + the specification part. */ #define case_omp_decl case ST_OMP_THREADPRIVATE: case ST_OMP_DECLARE_SIMD: \ case ST_OMP_DECLARE_TARGET: case ST_OMP_DECLARE_REDUCTION: \ - case ST_OMP_REQUIRES + case ST_OMP_REQUIRES: case ST_OACC_ROUTINE: case ST_OACC_DECLARE + /* Block end statements. Errors associated with interchanging these are detected in gfc_match_end(). */ #define case_end case ST_END_BLOCK_DATA: case ST_END_FUNCTION: \ case ST_END_PROGRAM: case ST_END_SUBROUTINE: \ case ST_END_BLOCK: case ST_END_ASSOCIATE @@ -2808,17 +2809,17 @@ verify_st_order (st_state *p, gfc_statement st, bool silent) case_decl: if (p->state >= ORDER_EXEC) goto order; if (p->state < ORDER_SPEC) p->state = ORDER_SPEC; break; case_omp_decl: - /* The OpenMP directives have to be somewhere in the specification + /* The OpenMP/OpenACC directives have to be somewhere in the specification part, but there are no further requirements on their ordering. Thus don't adjust p->state, just ignore them. */ if (p->state >= ORDER_EXEC) goto order; break; case_executable: case_exec_markers: diff --git a/gcc/testsuite/gfortran.dg/goacc/specification-part.f90 b/gcc/testsuite/gfortran.dg/goacc/specification-part.f90 new file mode 100644 index 00000000000..14af6aecc7d --- /dev/null +++ b/gcc/testsuite/gfortran.dg/goacc/specification-part.f90 @@ -0,0 +1,100 @@ +! { dg-do compile } +! +! PR fortran/90111 +! +! Check that OpenACC directives in everywhere in specification part, +! i.e. it may appear before/after the use, import, implicit, and declaration +! + +module m +end module m + +subroutine foo0(kk) + use m + implicit none + integer :: jj, kk + !$acc routine +end + +subroutine foo1() + use m + implicit none + !$acc routine + integer :: jj +end + +subroutine foo2() + use m + !$acc routine + implicit none +end + +subroutine foo3() + !$acc routine + use m + implicit none +end + +module m2 + interface + subroutine foo0(kk) + use m + import + implicit none + integer :: kk + !$acc routine + end + subroutine foo1() + use m + import + implicit none + !$acc routine + end + subroutine foo2() + use m + import + !$acc routine + implicit none + end + subroutine foo3() + use m + !$acc routine + import + implicit none + end + subroutine foo4() + use m + !$acc routine + import + implicit none + end + end interface +end module m2 + +subroutine bar0() + use m + implicit none + integer :: ii + !$acc declare copyin(ii) +end + +subroutine bar1() + use m + implicit none + !$acc declare copyin(ii) + integer :: ii +end + +subroutine bar2() + use m + !$acc declare copyin(ii) + implicit none + integer :: ii +end + +subroutine bar3() + !$acc declare copyin(ii) + use m + implicit none + integer :: ii +end