]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
OpenMP: Fortran - fix ancestor's requires reverse_offload check
authorTobias Burnus <tobias@codesourcery.com>
Wed, 8 Jun 2022 08:06:57 +0000 (10:06 +0200)
committerTobias Burnus <tobias@codesourcery.com>
Wed, 8 Jun 2022 08:06:57 +0000 (10:06 +0200)
gcc/fortran/

* openmp.cc (gfc_match_omp_clauses): Check also parent namespace
for 'requires reverse_offload'.

gcc/testsuite/

* gfortran.dg/gomp/target-device-ancestor-5.f90: New test.

gcc/fortran/openmp.cc
gcc/testsuite/gfortran.dg/gomp/target-device-ancestor-5.f90 [new file with mode: 0644]

index d12cec43d64ebe9f07f9ae0db3f8be5eb256d5fd..aeb8a43e12e7e99c3ce36f960a1ce95cd7d21274 100644 (file)
@@ -2014,8 +2014,15 @@ gfc_match_omp_clauses (gfc_omp_clauses **cp, const omp_mask mask,
                }
              else if (gfc_match ("ancestor : ") == MATCH_YES)
                {
+                 bool has_requires = false;
                  c->ancestor = true;
-                 if (!(gfc_current_ns->omp_requires & OMP_REQ_REVERSE_OFFLOAD))
+                 for (gfc_namespace *ns = gfc_current_ns; ns; ns = ns->parent)
+                   if (ns->omp_requires & OMP_REQ_REVERSE_OFFLOAD)
+                     {
+                       has_requires = true;
+                       break;
+                     }
+                 if (!has_requires)
                    {
                      gfc_error ("%<ancestor%> device modifier not "
                                 "preceded by %<requires%> directive "
diff --git a/gcc/testsuite/gfortran.dg/gomp/target-device-ancestor-5.f90 b/gcc/testsuite/gfortran.dg/gomp/target-device-ancestor-5.f90
new file mode 100644 (file)
index 0000000..06a11eb
--- /dev/null
@@ -0,0 +1,69 @@
+! { dg-do compile }
+!
+! Check that a requires directive is still recognized
+! if it is in the associated parent namespace of the
+! target directive.
+!
+
+module m
+  !$omp requires reverse_offload  ! { dg-error "REQUIRES directive is not yet supported" }
+contains
+  subroutine foo()
+    !$omp target device(ancestor:1)
+    !$omp end target
+  end subroutine foo
+
+  subroutine bar()
+    block
+      block
+        block
+          !$omp target device(ancestor:1)
+          !$omp end target
+        end block
+      end block
+    end block
+  end subroutine bar
+end module m
+
+subroutine foo()
+  !$omp requires reverse_offload  ! { dg-error "REQUIRES directive is not yet supported" }
+  block
+    block
+      block
+        !$omp target device(ancestor:1)
+        !$omp end target
+      end block
+    end block
+  end block
+contains
+  subroutine bar()
+    block
+      block
+        block
+          !$omp target device(ancestor:1)
+          !$omp end target
+        end block
+      end block
+    end block
+  end subroutine bar
+end subroutine foo
+
+program main
+  !$omp requires reverse_offload  ! { dg-error "REQUIRES directive is not yet supported" }
+contains
+  subroutine foo()
+    !$omp target device(ancestor:1)
+    !$omp end target
+  end subroutine foo
+
+  subroutine bar()
+    block
+      block
+        block
+          !$omp target device(ancestor:1)
+          !$omp end target
+        end block
+      end block
+    end block
+  end subroutine bar
+end