From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from esa4.mentor.iphmx.com (esa4.mentor.iphmx.com [68.232.137.252]) by sourceware.org (Postfix) with ESMTPS id 9BF613858D38; Thu, 20 Aug 2020 11:36:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 9BF613858D38 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: 306iM3wVJG9kznP+nG/8XHIkcCJmG2YyjrKIeJDkfiWJTisERPQHQbirCO3Pe61N6Qmc7mk2aW mZq6M2RMfQRERWmfTUuPkjc5gLVTcleu+8+0PBFjry4Kjfd5bViNmDaGuU/qAm3OaiMliIQEWZ ukgTUHZN8Wx/7ZjvNvF0OoP7l7q0D1Rm4A2Xt4z9kB+qCPvu82fIOr92X+TmAjiC03jT2TQy/S jwl4m9MEVijgIyWSfLT2U4DM9BPVTVe7jhEnaagqO6tz0syotvhNoiLdG53B2dXGOiC9eeqKpH rcM= X-IronPort-AV: E=Sophos;i="5.76,332,1592899200"; d="diff'?scan'208";a="52214459" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa4.mentor.iphmx.com with ESMTP; 20 Aug 2020 03:35:59 -0800 IronPort-SDR: kIaG53XfzdFVub7SViVo6xEC1XzzscItSqOK32nx+G8zvIiNHSuTAL+wUOgEXoKO6L9iaZwoWz qb2tMQ9wusgkHEDeCRVotW+ojTpmLORy/TE43OOOCcB43a9teCnOptUfh10hvrpTdLmW4J7rIP iFs5I66e7Df/aIqD9khT1EwY4UWT0rxssPM0YtpQZqYk1uHIr8avQ0eU7Mek/9gn9JPaO6u5nS hLkfpzBJ/I8Nqh28OwImRxfL90dTiB4q1bEhQygR+TOPwtNcW0Dzu7xcQCtJ64EdViq0fMtLA2 pdc= To: gcc-patches , fortran , Jakub Jelinek From: Tobias Burnus Subject: [Patch, committed] Fortran: Fix OpenMP's 'if(simd:' etc. conditions Message-ID: <9855240a-8185-fe09-76fb-160d565c01bb@codesourcery.com> Date: Thu, 20 Aug 2020 13:36:01 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.11.0 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------CF3BEBC6EAB74B99FAB4CA2E" Content-Language: en-US X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: svr-ies-mbx-01.mgc.mentorg.com (139.181.222.1) To svr-ies-mbx-01.mgc.mentorg.com (139.181.222.1) X-Spam-Status: No, score=-12.6 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: , X-List-Received-Date: Thu, 20 Aug 2020 11:36:02 -0000 --------------CF3BEBC6EAB74B99FAB4CA2E Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: quoted-printable This patch adds two 'simdlen' testcases by converting the respective C testcases. When doing so, it turned out that 'if (simd: x)' generated the symbol 'simd' due to: gfc_match ("if ( ") =3D=3D MATCH_YES ... gfc_match ("%e )", &c->if_expr) The latter matches "%e", which creates the symbol and then fails at ")". It frees the gfc_expr but does not undo the symbol. (In the normal parser there is some logic to do this =E2=86=92 undo_new_statement, but this is not done for "subpasing") The next match works (" simd : %e )" and parsing finishes successfully. But at resolution stage, the 'implicit none' picks up the spurious 'simd' symbol and gives an error. Solution: Simply match first the ' : %e' and only then try to match '%e )'. Committed as obvious to mainline: r11-2780-g656218ab982cc22b826227045826c92= 743143af1 Tobias PS: I note that C/C++ print an error if safelen is not >0 while Fortran only prints a warning. ----------------- Mentor Graphics (Deutschland) GmbH, Arnulfstra=C3=9Fe 201, 80634 M=C3=BCnch= en / Germany Registergericht M=C3=BCnchen HRB 106955, Gesch=C3=A4ftsf=C3=BChrer: Thomas = Heurung, Alexander Walter --------------CF3BEBC6EAB74B99FAB4CA2E Content-Type: text/x-patch; charset="UTF-8"; name="committed.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="committed.diff" commit 656218ab982cc22b826227045826c92743143af1 Author: Tobias Burnus Date: Thu Aug 20 13:33:21 2020 +0200 Fortran: Fix OpenMP's 'if(simd:' etc. conditions gcc/fortran/ChangeLog: * openmp.c (gfc_match_omp_clauses): Re-order 'if' clause pasing to avoid creating spurious symbols. libgomp/ChangeLog: * testsuite/libgomp.fortran/lastprivate-conditional-10.f90: New test. --- gcc/fortran/openmp.c | 4 +- gcc/testsuite/gfortran.dg/gomp/pr67500.f90 | 57 ++++++++++++++++++++ .../libgomp.fortran/lastprivate-conditional-10.f90 | 63 ++++++++++++++++++++++ 3 files changed, 122 insertions(+), 2 deletions(-) diff --git a/gcc/fortran/openmp.c b/gcc/fortran/openmp.c index 4d33a450a33..50983737af4 100644 --- a/gcc/fortran/openmp.c +++ b/gcc/fortran/openmp.c @@ -1299,8 +1299,6 @@ gfc_match_omp_clauses (gfc_omp_clauses **cp, const omp_mask mask, && c->if_expr == NULL && gfc_match ("if ( ") == MATCH_YES) { - if (gfc_match ("%e )", &c->if_expr) == MATCH_YES) - continue; if (!openacc) { /* This should match the enum gfc_omp_if_kind order. */ @@ -1323,6 +1321,8 @@ gfc_match_omp_clauses (gfc_omp_clauses **cp, const omp_mask mask, if (i < OMP_IF_LAST) continue; } + if (gfc_match ("%e )", &c->if_expr) == MATCH_YES) + continue; gfc_current_locus = old_loc; } if ((mask & OMP_CLAUSE_IF_PRESENT) diff --git a/gcc/testsuite/gfortran.dg/gomp/pr67500.f90 b/gcc/testsuite/gfortran.dg/gomp/pr67500.f90 new file mode 100644 index 00000000000..1cecdc48578 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/gomp/pr67500.f90 @@ -0,0 +1,57 @@ +! Fortran version of PR c/67500 +! { dg-do compile } + +subroutine f1 + !$omp declare simd simdlen(d) ! { dg-error "requires a scalar INTEGER expression" } +end subroutine + +subroutine f2 + !$omp declare simd simdlen(0.5) ! { dg-error "requires a scalar INTEGER expression" } +end + +subroutine f3 (i) + !$omp declare simd simdlen(-2) ! { dg-warning "INTEGER expression of SIMDLEN clause at .1. must be positive" } +end subroutine + +subroutine f4 + !$omp declare simd simdlen(0) ! { dg-warning "INTEGER expression of SIMDLEN clause at .1. must be positive" } +end + +subroutine foo(p, d, n) + integer, allocatable :: p(:) + real, value :: d + integer, value :: n + integer :: i + + !$omp simd safelen(d) ! { dg-error "requires a scalar INTEGER expression" } + do i = 1, 16 + end do + + !$omp simd safelen(0.5) ! { dg-error "requires a scalar INTEGER expression" } + do i = 1, 16 + end do + + !$omp simd safelen(-2) ! { dg-warning "INTEGER expression of SAFELEN clause at .1. must be positive" } + do i = 1, 16 + end do + + !$omp simd safelen(0) ! { dg-warning "INTEGER expression of SAFELEN clause at .1. must be positive" } + do i = 1, 16 + end do + + !$omp simd aligned(p:n) ! { dg-error "requires a scalar positive constant integer alignment expression" } + do i = 1, 16 + end do + + !$omp simd aligned(p:0.5) ! { dg-error "requires a scalar positive constant integer alignment expression" } + do i = 1, 16 + end do + + !$omp simd aligned(p:-2) ! { dg-error "requires a scalar positive constant integer alignment expression" } + do i = 1, 16 + end do + + !$omp simd aligned(p:0) ! { dg-error "requires a scalar positive constant integer alignment expression" } + do i = 1, 16 + end do +end diff --git a/libgomp/testsuite/libgomp.fortran/lastprivate-conditional-10.f90 b/libgomp/testsuite/libgomp.fortran/lastprivate-conditional-10.f90 new file mode 100644 index 00000000000..116166c48ee --- /dev/null +++ b/libgomp/testsuite/libgomp.fortran/lastprivate-conditional-10.f90 @@ -0,0 +1,63 @@ +! { dg-do run } +! Fortran version of libgomp.c-c++-common/lastprivate-conditional-10.c + +module m + implicit none + integer :: v = 0 + integer :: x = 0 +contains + integer function foo (a) + integer, contiguous :: a(0:) + integer i + + !$omp parallel do simd lastprivate (conditional: x) schedule(simd : static) if (simd : .false.) + do i = 0, 127 + if (a(i) /= 0) x = a(i) + end do + foo = x + end + + integer function bar (a, b) + integer, contiguous :: a(0:), b(0:) + integer :: i + !$omp parallel + !$omp do simd lastprivate (conditional: x, v) schedule(static, 16) simdlen (1) + do i = 16, 127 + if (a(i) /= 0) x = a(i); + if (b(i) /= 0) v = b(i) + 10; + end do + !$omp end parallel + bar = x + end + + integer function baz (a) + integer, contiguous :: a(0:) + integer :: i + !$omp parallel do simd if (simd : .false.) lastprivate (conditional: x) schedule(simd : dynamic, 16) + do i = 0, 127 + if (a(i) /= 0) x = a(i) + 5 + end do + baz = x + end +end module m + +program main + use m + implicit none + integer :: a(0:127), b(0:127), i + do i = 0, 127 + if (mod(i, 11) == 2) then + a(i) = i + 10 + else + a(i) = 0 + endif + if (mod(i, 13) == 5) then + b(i) = i * 2 + else + b(i) = 0 + endif + end do + if (foo (a) /= 133) stop 1 + if (bar (b, a) /= 244 .or. v /= 143) stop 2 + if (baz (b) /= 249) stop 3 +end --------------CF3BEBC6EAB74B99FAB4CA2E--