From patchwork Tue Jun 16 11:27:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tobias Burnus X-Patchwork-Id: 1310253 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=8.43.85.97; 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 [8.43.85.97]) (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 49mQt463smz9sSS for ; Tue, 16 Jun 2020 21:27:56 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C2826388C002; Tue, 16 Jun 2020 11:27:53 +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 A4B07388B004; Tue, 16 Jun 2020 11:27:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org A4B07388B004 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: bJWCNtbxck+Ie4UCgEmFlPuZyQBiohFVPB7uBZXUC3Ab5YxASFZ2acDfhZBADWacURYesNCgHC AC5HPR1ptUyo44SvFJvwsXVND4gC6Koul87LHOPJBE/QxnL62bTQrl3tG2LR1VlxXEsejRqAOt 4u2E+QGBed2+wyG8nWg5QjtHHp3znTmd3AaJg3NpmrjexAhuAaN4ddSJNyH7iI+BVg+emPwQxA sG5egaRq0WRziN/6HZ8RMsDTquwPLtce1R2qvslETYg9F/u2xsIwEcecSt1s24cqjmuE8x/0xv Ge8= X-IronPort-AV: E=Sophos;i="5.73,518,1583222400"; d="diff'?scan'208";a="51979590" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa1.mentor.iphmx.com with ESMTP; 16 Jun 2020 03:27:49 -0800 IronPort-SDR: oO0Ji1MrKvRNNuGduR8AteBc2eNH6MCilgdiYXRhwuXAorAUz5MulWl74PuoyfZgk44fUjDbAZ bzgrXo2ycMurn9/IKguK0Uw9fZmNn9elEM+QiPJcqurTOPYk5SGbsFzc5BLAciamW5uYb7JOf/ t6wcMnSLZc+6bNab7YorGYZhzydgVF6K2GIHqJjJxWzAsaf6iRXrZZNBBeBNlsdosx2ZKxLKQv HdZdewJKy+MUYMJKmwUUjg+XLfkyuHlxmZnkv6KQxAIKp4kHy9ocHXmECW6PVKdPA+/GbXeK/O iPI= To: gcc-patches , fortran , Jakub Jelinek From: Tobias Burnus Subject: [Patch] OpenMP/Fortran: Permit impure ELEMENTAL in omp directives Message-ID: <9cd0b179-63fb-ba5d-9c31-3d3d0358b300@codesourcery.com> Date: Tue, 16 Jun 2020 13:27:43 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.9.0 MIME-Version: 1.0 Content-Language: en-US X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: svr-ies-mbx-02.mgc.mentorg.com (139.181.222.2) To SVR-IES-MBX-03.mgc.mentorg.com (139.181.222.3) X-Spam-Status: No, score=-14.3 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" Hi all, when looking into a PURE/ELEMENTAL issue with OpenACC, Thomas and I came across the analogous OpenMP code – and stumbled over ELEMENTAL. In Fortran, ELEMENTAL implies PURE but one can also have an IMPURE ELEMENTAL procedure. As PR 79154 quotes, OpenMP 4 had: "OpenMP directives may not appear in PURE or ELEMENTAL procedures." While OpenMP 4.5 (and later) have: "OpenMP directives, except SIMD and declare target directives, may not appear in pure procedures." ELEMENTAL is still mentioned – but only for: "OpenMP runtime library routines may not be called from PURE or ELEMENTAL procedures." OK for the trunk? Tobias ----------------- Mentor Graphics (Deutschland) GmbH, Arnulfstraße 201, 80634 München / Germany Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Alexander Walter OpenMP/Fortran: Permit impure ELEMENTAL in omp directives OpenMP since 4.5 permits IMPURE ELEMENTAL in directives and the code already only checked for PURE. gcc/fortran/ChangeLog: * parse.c (decode_omp_directive): Remove "or ELEMENTAL" from "in PURE" error message. gcc/testsuite/ChangeLog: * gfortran.dg/gomp/pr79154-1.f90: Update dg-*; add an impure elemental example. * gfortran.dg/gomp/pr79154-2.f90: Likewise. gcc/fortran/parse.c | 4 ++-- gcc/testsuite/gfortran.dg/gomp/pr79154-1.f90 | 15 +++++++++----- gcc/testsuite/gfortran.dg/gomp/pr79154-2.f90 | 30 +++++++++++++++++++--------- 3 files changed, 33 insertions(+), 16 deletions(-) diff --git a/gcc/fortran/parse.c b/gcc/fortran/parse.c index f71a95dd871..9d90e501bf6 100644 --- a/gcc/fortran/parse.c +++ b/gcc/fortran/parse.c @@ -849,7 +849,7 @@ decode_omp_directive (void) /* match is for directives that should be recognized only if -fopenmp, matchs for directives that should be recognized if either -fopenmp or -fopenmp-simd. - Handle only the directives allowed in PURE/ELEMENTAL procedures + Handle only the directives allowed in PURE procedures first (those also shall not turn off implicit pure). */ switch (c) { @@ -868,7 +868,7 @@ decode_omp_directive (void) if (flag_openmp && gfc_pure (NULL)) { gfc_error_now ("OpenMP directives other than SIMD or DECLARE TARGET " - "at %C may not appear in PURE or ELEMENTAL procedures"); + "at %C may not appear in PURE procedures"); gfc_error_recovery (); return ST_NONE; } diff --git a/gcc/testsuite/gfortran.dg/gomp/pr79154-1.f90 b/gcc/testsuite/gfortran.dg/gomp/pr79154-1.f90 index 69a0009e13c..ea147bfa78e 100644 --- a/gcc/testsuite/gfortran.dg/gomp/pr79154-1.f90 +++ b/gcc/testsuite/gfortran.dg/gomp/pr79154-1.f90 @@ -2,7 +2,7 @@ ! { dg-do compile } pure real function foo (a, b) ! { dg-warning "GCC does not currently support mixed size types for 'simd' functions" "" { target aarch64*-*-* } } -!$omp declare simd(foo) ! { dg-bogus "may not appear in PURE or ELEMENTAL" } +!$omp declare simd(foo) ! { dg-bogus "may not appear in PURE" } real, intent(in) :: a, b foo = a + b end function foo @@ -10,23 +10,28 @@ pure function bar (a, b) real, intent(in) :: a(8), b(8) real :: bar(8) integer :: i -!$omp simd ! { dg-bogus "may not appear in PURE or ELEMENTAL" } +!$omp simd ! { dg-bogus "may not appear in PURE" } do i = 1, 8 bar(i) = a(i) + b(i) end do end function bar pure real function baz (a, b) -!$omp declare target ! { dg-bogus "may not appear in PURE or ELEMENTAL" } +!$omp declare target ! { dg-bogus "may not appear in PURE" } real, intent(in) :: a, b baz = a + b end function baz elemental real function fooe (a, b) ! { dg-warning "GCC does not currently support mixed size types for 'simd' functions" "" { target aarch64*-*-* } } -!$omp declare simd(fooe) ! { dg-bogus "may not appear in PURE or ELEMENTAL" } +!$omp declare simd(fooe) ! { dg-bogus "may not appear in PURE" } real, intent(in) :: a, b fooe = a + b end function fooe elemental real function baze (a, b) -!$omp declare target ! { dg-bogus "may not appear in PURE or ELEMENTAL" } +!$omp declare target ! { dg-bogus "may not appear in PURE" } real, intent(in) :: a, b baze = a + b end function baze +elemental impure real function bazei (a, b) +!$omp declare target ! { dg-bogus "may not appear in PURE" } + real, intent(in) :: a, b + baze = a + b +end function bazei diff --git a/gcc/testsuite/gfortran.dg/gomp/pr79154-2.f90 b/gcc/testsuite/gfortran.dg/gomp/pr79154-2.f90 index 67344f0c028..38d3fe5c384 100644 --- a/gcc/testsuite/gfortran.dg/gomp/pr79154-2.f90 +++ b/gcc/testsuite/gfortran.dg/gomp/pr79154-2.f90 @@ -3,14 +3,14 @@ pure real function foo (a, b) real, intent(in) :: a, b -!$omp taskwait ! { dg-error "may not appear in PURE or ELEMENTAL" } +!$omp taskwait ! { dg-error "may not appear in PURE" } foo = a + b end function foo pure function bar (a, b) real, intent(in) :: a(8), b(8) real :: bar(8) integer :: i -!$omp do simd ! { dg-error "may not appear in PURE or ELEMENTAL" } +!$omp do simd ! { dg-error "may not appear in PURE" } do i = 1, 8 bar(i) = a(i) + b(i) end do @@ -19,26 +19,38 @@ pure function baz (a, b) real, intent(in) :: a(8), b(8) real :: baz(8) integer :: i -!$omp do ! { dg-error "may not appear in PURE or ELEMENTAL" } +!$omp do ! { dg-error "may not appear in PURE" } do i = 1, 8 baz(i) = a(i) + b(i) end do -!$omp end do ! { dg-error "may not appear in PURE or ELEMENTAL" } +!$omp end do ! { dg-error "may not appear in PURE" } end function baz pure real function baz2 (a, b) real, intent(in) :: a, b -!$omp target map(from:baz2) ! { dg-error "may not appear in PURE or ELEMENTAL" } +!$omp target map(from:baz2) ! { dg-error "may not appear in PURE" } baz2 = a + b -!$omp end target ! { dg-error "may not appear in PURE or ELEMENTAL" } +!$omp end target ! { dg-error "may not appear in PURE" } end function baz2 +! ELEMENTAL implies PURE elemental real function fooe (a, b) real, intent(in) :: a, b -!$omp taskyield ! { dg-error "may not appear in PURE or ELEMENTAL" } +!$omp taskyield ! { dg-error "may not appear in PURE" } fooe = a + b end function fooe elemental real function baze (a, b) real, intent(in) :: a, b -!$omp target map(from:baz) ! { dg-error "may not appear in PURE or ELEMENTAL" } +!$omp target map(from:baz) ! { dg-error "may not appear in PURE" } baze = a + b -!$omp end target ! { dg-error "may not appear in PURE or ELEMENTAL" } +!$omp end target ! { dg-error "may not appear in PURE" } end function baze +elemental impure real function fooei (a, b) + real, intent(in) :: a, b +!$omp taskyield ! { dg-bogus "may not appear in PURE" } + fooe = a + b +end function fooei +elemental impure real function bazei (a, b) + real, intent(in) :: a, b +!$omp target map(from:baz) ! { dg-bogus "may not appear in PURE" } + baze = a + b +!$omp end target ! { dg-bogus "may not appear in PURE" } +end function bazei