]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fortran: OpenMP fix declare simd inside modules and absent linear step [PR106566]
authorTobias Burnus <tobias@codesourcery.com>
Tue, 23 Aug 2022 11:00:38 +0000 (13:00 +0200)
committerTobias Burnus <tobias@codesourcery.com>
Tue, 23 Aug 2022 11:09:00 +0000 (13:09 +0200)
gcc/fortran/ChangeLog:

PR fortran/106566
* openmp.cc (gfc_match_omp_clauses): Fix setting linear-step value
to 1 when not specified.
(gfc_match_omp_declare_simd): Accept module procedures.

gcc/testsuite/ChangeLog:

PR fortran/106566
* gfortran.dg/gomp/declare-simd-4.f90: New test.
* gfortran.dg/gomp/declare-simd-5.f90: New test.
* gfortran.dg/gomp/declare-simd-6.f90: New test.

(cherry picked from commit 1513512ec7d0751cba30c9c8804f2be462acfb9b)

gcc/fortran/ChangeLog.omp
gcc/fortran/openmp.cc
gcc/testsuite/ChangeLog.omp
gcc/testsuite/gfortran.dg/gomp/declare-simd-4.f90 [new file with mode: 0644]
gcc/testsuite/gfortran.dg/gomp/declare-simd-5.f90 [new file with mode: 0644]
gcc/testsuite/gfortran.dg/gomp/declare-simd-6.f90 [new file with mode: 0644]

index 9877be5ec41b0200bbd8592aaf619d9c7f322e8d..b7ccae31907c701caadceefaf6f865f71f6db64d 100644 (file)
@@ -1,3 +1,13 @@
+2022-08-23  Tobias Burnus  <tobias@codesourcery.com>
+
+       Backport from mainline:
+       2022-08-17  Tobias Burnus  <tobias@codesourcery.com>
+
+       PR fortran/106566
+       * openmp.cc (gfc_match_omp_clauses): Fix setting linear-step value
+       to 1 when not specified.
+       (gfc_match_omp_declare_simd): Accept module procedures.
+
 2022-07-29  Tobias Burnus  <tobias@codesourcery.com>
 
        Backport from mainline:
index 91af90c3f6608cb15c0ab78a645fa651b1aeb372..771aa83979bc36b870e99a6194155f26374cd8bd 100644 (file)
@@ -3026,7 +3026,7 @@ gfc_match_omp_clauses (gfc_omp_clauses **cp, const omp_mask mask,
                      goto error;
                    }
                }
-             else
+             if (step == NULL)
                {
                  step = gfc_get_constant_expr (BT_INTEGER,
                                                gfc_default_integer_kind,
@@ -4761,9 +4761,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;
     }
index 84f762ff3cc45d4ec9ffd8b9b3486fb55469c629..88d67a987715094ea71276e927d9247e4c7dbc88 100644 (file)
@@ -1,3 +1,13 @@
+2022-08-23  Tobias Burnus  <tobias@codesourcery.com>
+
+       Backport from mainline:
+       2022-08-17  Tobias Burnus  <tobias@codesourcery.com>
+
+       PR fortran/106566
+       * gfortran.dg/gomp/declare-simd-4.f90: New test.
+       * gfortran.dg/gomp/declare-simd-5.f90: New test.
+       * gfortran.dg/gomp/declare-simd-6.f90: New test.
+
 2022-08-17  Tobias Burnus  <tobias@codesourcery.com>
 
        Backport from mainline:
diff --git a/gcc/testsuite/gfortran.dg/gomp/declare-simd-4.f90 b/gcc/testsuite/gfortran.dg/gomp/declare-simd-4.f90
new file mode 100644 (file)
index 0000000..27a75ab
--- /dev/null
@@ -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\\(0:ref,step\\(4\\)\\) simdlen\\(8\\)\\)\\)\\)" 2 "gimple" } }
+! { dg-final { scan-tree-dump-times "__attribute__\\(\\(omp declare simd \\(linear\\(0:ref,step\\(8\\)\\) simdlen\\(8\\)\\)\\)\\)" 2 "gimple" } }
+
+subroutine add_one2(p)
+  implicit none
+  !$omp declare simd(add_one2) linear(p: ref) 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(p: ref, step(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(q: ref) 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(q: ref, step(2)) simdlen(8)
+    integer(kind=4) :: q
+    q = q + 1
+  end subroutine
+end module
diff --git a/gcc/testsuite/gfortran.dg/gomp/declare-simd-5.f90 b/gcc/testsuite/gfortran.dg/gomp/declare-simd-5.f90
new file mode 100644 (file)
index 0000000..f5880f5
--- /dev/null
@@ -0,0 +1,49 @@
+! { dg-do compile }
+!
+! PR fortran/106566
+!
+
+subroutine add_one2(p)
+  implicit none
+  procedure(add_one2) :: ext1
+  !$omp declare simd(ext1) linear(p: ref) simdlen(8)  ! { dg-error "OMP DECLARE SIMD should refer to containing procedure 'add_one2'" }
+  integer :: p
+
+  p = p + 1
+end subroutine
+
+subroutine linear_add_one2(p)
+  implicit none
+  procedure(linear_add_one2) :: ext2
+  !$omp declare simd(ext2) linear(p: ref, step(2)) simdlen(8)  ! { dg-error "OMP DECLARE SIMD should refer to containing procedure 'linear_add_one2'" }
+  integer :: p
+
+  p = p + 1
+end subroutine
+
+module m
+   integer, parameter :: NN = 1023
+   integer :: a(NN)
+contains
+  subroutine some_proc(r)
+    integer :: r
+  end subroutine
+  subroutine module_add_one2(q)
+    implicit none
+    !$omp declare simd(some_proc) linear(q: ref) simdlen(8)  ! { dg-error "OMP DECLARE SIMD should refer to containing procedure 'module_add_one2'" }
+    integer :: q
+    q = q + 1
+  end subroutine
+
+  subroutine module_linear_add_one2(q)
+    implicit none
+    interface
+      subroutine other_proc(r)
+        integer :: r
+      end subroutine
+    end interface
+    !$omp declare simd(other_proc) linear(q: ref, step(2)) simdlen(8)  ! { dg-error "OMP DECLARE SIMD should refer to containing procedure 'module_linear_add_one2'" }
+    integer :: q
+    q = q + 1
+  end subroutine
+end module
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 (file)
index 0000000..83f2c0a
--- /dev/null
@@ -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