[gcc r12-8704] Fortran: OpenMP fix declare simd inside modules and absent linear step [PR106566]

Tobias Burnus burnus@gcc.gnu.org
Tue Aug 23 11:52:30 GMT 2022


https://gcc.gnu.org/g:50b7cf395656ccd32d4d5d8e0e338135d28f52f6

commit r12-8704-g50b7cf395656ccd32d4d5d8e0e338135d28f52f6
Author: Tobias Burnus <tobias@codesourcery.com>
Date:   Tue Aug 23 11:29:23 2022 +0200

    Fortran: OpenMP fix declare simd inside modules and absent linear step [PR106566]
    
    Partial backport from commit r13-2093, only, as 'OpenMP 5.2 linear
    clause syntax' is not on GCC 12.
    
    gcc/fortran/ChangeLog:
    
            PR fortran/106566
            * openmp.cc (gfc_match_omp_declare_simd): Accept module procedures.
    
    gcc/testsuite/ChangeLog:
    
            PR fortran/106566
            * gfortran.dg/gomp/declare-simd-6.f90: New test.
    
    (cherry picked from commit 1513512ec7d0751cba30c9c8804f2be462acfb9b)

Diff:
---
 gcc/fortran/openmp.cc                             |  8 +++--
 gcc/testsuite/gfortran.dg/gomp/declare-simd-6.f90 | 42 +++++++++++++++++++++++
 2 files changed, 48 insertions(+), 2 deletions(-)

diff --git a/gcc/fortran/openmp.cc b/gcc/fortran/openmp.cc
index 5018a37ec46..14f2521f1df 100644
--- a/gcc/fortran/openmp.cc
+++ b/gcc/fortran/openmp.cc
@@ -4027,9 +4027,13 @@ gfc_match_omp_declare_simd (void)
   gfc_omp_declare_simd *ods;
   bool needs_space = false;
 
-  switch (gfc_match (" ( %s ) ", &proc_name))
+  switch (gfc_match (" ( "))
     {
-    case MATCH_YES: break;
+    case MATCH_YES:
+      if (gfc_match_symbol (&proc_name, /* host assoc = */ true) != MATCH_YES
+	  || gfc_match (" ) ") != MATCH_YES)
+	return MATCH_ERROR;
+      break;
     case MATCH_NO: proc_name = NULL; needs_space = true; break;
     case MATCH_ERROR: return MATCH_ERROR;
     }
diff --git a/gcc/testsuite/gfortran.dg/gomp/declare-simd-6.f90 b/gcc/testsuite/gfortran.dg/gomp/declare-simd-6.f90
new file mode 100644
index 00000000000..83f2c0ab7cb
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/gomp/declare-simd-6.f90
@@ -0,0 +1,42 @@
+! { dg-do compile }
+! { dg-additional-options "-fdump-tree-gimple" }
+!
+! PR fortran/106566
+!
+! { dg-final { scan-tree-dump-times "__attribute__\\(\\(omp declare simd \\(linear\\(ref\\(0\\):4\\) simdlen\\(8\\)\\)\\)\\)" 2 "gimple" } }
+! { dg-final { scan-tree-dump-times "__attribute__\\(\\(omp declare simd \\(linear\\(ref\\(0\\):8\\) simdlen\\(8\\)\\)\\)\\)" 2 "gimple" } }
+
+subroutine add_one2(p)
+  implicit none
+  !$omp declare simd(add_one2) linear(ref(p)) simdlen(8)
+  integer(kind=4) :: p
+
+  p = p + 1
+end subroutine
+
+subroutine linear_add_one2(p)
+  implicit none
+  !$omp declare simd(linear_add_one2) linear(ref(p) : 2) simdlen(8)
+  integer(kind=4) :: p
+
+  p = p + 1
+end subroutine
+
+module m
+   integer, parameter :: NN = 1023
+   integer(kind=4) :: a(NN)
+contains
+  subroutine module_add_one2(q)
+    implicit none
+    !$omp declare simd(module_add_one2) linear(ref(q)) simdlen(8)
+    integer(kind=4) :: q
+    q = q + 1
+  end subroutine
+
+  subroutine linear_add_one2(q)
+    implicit none
+    !$omp declare simd(linear_add_one2) linear(ref(q) : 2) simdlen(8)
+    integer(kind=4) :: q
+    q = q + 1
+  end subroutine
+end module


More information about the Gcc-cvs mailing list