public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
* [Patch] Fortran/OpenMP: Fix -fopenmp-simd for 'omp assume(s)'
@ 2023-02-09  8:56 Tobias Burnus
  2023-02-09  9:32 ` Jakub Jelinek
  0 siblings, 1 reply; 2+ messages in thread
From: Tobias Burnus @ 2023-02-09  8:56 UTC (permalink / raw)
  To: gcc-patches, Jakub Jelinek, fortran

[-- Attachment #1: Type: text/plain, Size: 417 bytes --]

Found by chance recently; I thought about a couple of ways to handle it
but then settled to the proposed solution.

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

[-- Attachment #2: fix-omp-simd-assumes.diff --]
[-- Type: text/x-patch, Size: 2093 bytes --]

Fortran/OpenMP: Fix -fopenmp-simd for 'omp assume(s)'

While 'omp assume' is enabled by -fopenmp-simd, 'omp assumes' is not;
however, due to the way parsing works in Fortran (esp. for fixed-form
source code), 'assumes' was parsed by 'assume' which then stumbled over
the tailing 's'.

gcc/fortran/

        * parse.cc (decode_omp_directive): Really ignore 'assumes' with
	-fopenmp-simd.

gcc/testsuite/

        * gfortran.dg/gomp/openmp-simd-8.f90: New test.

 gcc/fortran/parse.cc                             |  3 +++
 gcc/testsuite/gfortran.dg/gomp/openmp-simd-8.f90 | 25 ++++++++++++++++++++++++
 2 files changed, 28 insertions(+)

diff --git a/gcc/fortran/parse.cc b/gcc/fortran/parse.cc
index 039e7e7da53..f5154d97ae8 100644
--- a/gcc/fortran/parse.cc
+++ b/gcc/fortran/parse.cc
@@ -885,6 +885,9 @@ decode_omp_directive (void)
   switch (c)
     {
     case 'a':
+      /* For -fopenmp-simd, ignore 'assumes'; note no clause starts with 's'. */
+      if (!flag_openmp && gfc_match ("assumes") == MATCH_YES)
+	break;
       matcho ("assumes", gfc_match_omp_assumes, ST_OMP_ASSUMES);
       matchs ("assume", gfc_match_omp_assume, ST_OMP_ASSUME);
       matcho ("atomic", gfc_match_omp_atomic, ST_OMP_ATOMIC);
diff --git a/gcc/testsuite/gfortran.dg/gomp/openmp-simd-8.f90 b/gcc/testsuite/gfortran.dg/gomp/openmp-simd-8.f90
new file mode 100644
index 00000000000..cf92abf2f9e
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/gomp/openmp-simd-8.f90
@@ -0,0 +1,25 @@
+! { dg-options "-fno-openmp -fopenmp-simd -fdump-tree-original" }
+
+! While 'omp assumes' is ignored with -fopenmp-simd,
+! 'omp assume' is processed - check that this works.
+
+module m
+  !$omp assumes no_openmp invalid_clause  ! Should get ignored
+contains
+  integer function foo()
+    foo = 5
+  end function
+end
+
+program main
+  use m
+  implicit none
+  !$omp assumes no_openmp  ! likewise ignored
+  integer :: n
+  !$omp assume holds (foo() > 0) ! should be honoured
+    n = foo()
+    if (n == 0) stop
+  !$omp end assume
+end
+
+! { dg-final { scan-tree-dump "\\.ASSUME \\(foo \\(\\) > 0\\);" "original" } }

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [Patch] Fortran/OpenMP: Fix -fopenmp-simd for 'omp assume(s)'
  2023-02-09  8:56 [Patch] Fortran/OpenMP: Fix -fopenmp-simd for 'omp assume(s)' Tobias Burnus
@ 2023-02-09  9:32 ` Jakub Jelinek
  0 siblings, 0 replies; 2+ messages in thread
From: Jakub Jelinek @ 2023-02-09  9:32 UTC (permalink / raw)
  To: Tobias Burnus; +Cc: gcc-patches, fortran

On Thu, Feb 09, 2023 at 09:56:09AM +0100, Tobias Burnus wrote:
> Found by chance recently; I thought about a couple of ways to handle it
> but then settled to the proposed solution.
> 
> 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

> Fortran/OpenMP: Fix -fopenmp-simd for 'omp assume(s)'
> 
> While 'omp assume' is enabled by -fopenmp-simd, 'omp assumes' is not;
> however, due to the way parsing works in Fortran (esp. for fixed-form
> source code), 'assumes' was parsed by 'assume' which then stumbled over
> the tailing 's'.
> 
> gcc/fortran/
> 
>         * parse.cc (decode_omp_directive): Really ignore 'assumes' with
> 	-fopenmp-simd.
> 
> gcc/testsuite/
> 
>         * gfortran.dg/gomp/openmp-simd-8.f90: New test.

Ok.

	Jakub


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-02-09  9:32 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-09  8:56 [Patch] Fortran/OpenMP: Fix -fopenmp-simd for 'omp assume(s)' Tobias Burnus
2023-02-09  9:32 ` Jakub Jelinek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).