From patchwork Wed Jun 8 07:54:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tobias Burnus X-Patchwork-Id: 54932 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A1BBA383E6B7 for ; Wed, 8 Jun 2022 07:54:40 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from esa1.mentor.iphmx.com (esa1.mentor.iphmx.com [68.232.129.153]) by sourceware.org (Postfix) with ESMTPS id 55A16385840F; Wed, 8 Jun 2022 07:54:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 55A16385840F Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mentor.com X-IronPort-AV: E=Sophos;i="5.91,285,1647331200"; d="diff'?scan'208";a="79608762" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa1.mentor.iphmx.com with ESMTP; 07 Jun 2022 23:54:12 -0800 IronPort-SDR: 3Vna52xcRz2Rdua8kBca4SyHYwIXcCiBuZ4fBliVFX0aRpfeE3Lmyq3uInnJjxAox/kRbLJdZn jEgE3yaeGrPMb136LhIF4mUEmTCqZKlZqdvTNRxQ9x1gksw7txaezDdO4n6jbxVPmTYS00zPq5 +yrP1WO1psIztjyQmFyPKcntavtXQ04BFgljAPOVws0u7gCh2VsHWzCR9yD5btRxZjkZV93O1i BL+5JYoV1k/HqK7j+LY5OtqICyu8ILkWdzF0BLhPiPW9D6E9Rr8PzW/j1RqVEN0j8GrQq48A0P +dQ= Message-ID: <35ed17a9-2429-1428-2825-c4076321a068@codesourcery.com> Date: Wed, 8 Jun 2022 09:54:07 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.10.0 Content-Language: en-US To: Jakub Jelinek , fortran , gcc-patches From: Tobias Burnus Subject: [Patch] OpenMP: Fortran - fix ancestor's requires reverse_offload check X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: svr-ies-mbx-09.mgc.mentorg.com (139.181.222.9) To svr-ies-mbx-12.mgc.mentorg.com (139.181.222.12) X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" The OpenMP requires directive may only be placed in the specification part of a program unit (except it happens via the USE of a module). But the target directive ancestor-requires-'reverse_offload' only checked the current namespace. OK for mainline? Tobias ----------------- Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955 OpenMP: Fortran - fix ancestor's requires reverse_offload check gcc/fortran/ * openmp.cc (gfc_match_omp_clauses): Check also parent namespace for 'requires reverse_offload'. gcc/testsuite/ * gfortran.dg/gomp/target-device-ancestor-5.f90: New test. gcc/fortran/openmp.cc | 9 ++- .../gfortran.dg/gomp/target-device-ancestor-5.f90 | 69 ++++++++++++++++++++++ 2 files changed, 77 insertions(+), 1 deletion(-) diff --git a/gcc/fortran/openmp.cc b/gcc/fortran/openmp.cc index d12cec43d64..aeb8a43e12e 100644 --- a/gcc/fortran/openmp.cc +++ b/gcc/fortran/openmp.cc @@ -2014,8 +2014,15 @@ gfc_match_omp_clauses (gfc_omp_clauses **cp, const omp_mask mask, } else if (gfc_match ("ancestor : ") == MATCH_YES) { + bool has_requires = false; c->ancestor = true; - if (!(gfc_current_ns->omp_requires & OMP_REQ_REVERSE_OFFLOAD)) + for (gfc_namespace *ns = gfc_current_ns; ns; ns = ns->parent) + if (ns->omp_requires & OMP_REQ_REVERSE_OFFLOAD) + { + has_requires = true; + break; + } + if (!has_requires) { gfc_error ("% device modifier not " "preceded by % directive " diff --git a/gcc/testsuite/gfortran.dg/gomp/target-device-ancestor-5.f90 b/gcc/testsuite/gfortran.dg/gomp/target-device-ancestor-5.f90 new file mode 100644 index 00000000000..06a11eb5092 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/gomp/target-device-ancestor-5.f90 @@ -0,0 +1,69 @@ +! { dg-do compile } +! +! Check that a requires directive is still recognized +! if it is in the associated parent namespace of the +! target directive. +! + +module m + !$omp requires reverse_offload ! { dg-error "REQUIRES directive is not yet supported" } +contains + subroutine foo() + !$omp target device(ancestor:1) + !$omp end target + end subroutine foo + + subroutine bar() + block + block + block + !$omp target device(ancestor:1) + !$omp end target + end block + end block + end block + end subroutine bar +end module m + +subroutine foo() + !$omp requires reverse_offload ! { dg-error "REQUIRES directive is not yet supported" } + block + block + block + !$omp target device(ancestor:1) + !$omp end target + end block + end block + end block +contains + subroutine bar() + block + block + block + !$omp target device(ancestor:1) + !$omp end target + end block + end block + end block + end subroutine bar +end subroutine foo + +program main + !$omp requires reverse_offload ! { dg-error "REQUIRES directive is not yet supported" } +contains + subroutine foo() + !$omp target device(ancestor:1) + !$omp end target + end subroutine foo + + subroutine bar() + block + block + block + !$omp target device(ancestor:1) + !$omp end target + end block + end block + end block + end subroutine bar +end