[flang-commits] [flang] [Flang] [Semantics] [OpenMP] Added missing semantic check with nested target region. (PR #115344)

via flang-commits flang-commits at lists.llvm.org
Thu Nov 7 09:15:54 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-semantics

@llvm/pr-subscribers-flang-openmp

Author: Raghu Maddhipatla (raghavendhra)

<details>
<summary>Changes</summary>

Issue semantic warning for any combination of nested OMP TARGET directives inside an OMP TARGET DATA directive and vice versa.

---
Full diff: https://github.com/llvm/llvm-project/pull/115344.diff


3 Files Affected:

- (modified) flang/lib/Semantics/check-omp-structure.cpp (+16-1) 
- (modified) flang/test/Semantics/OpenMP/nested-simd.f90 (+1) 
- (modified) flang/test/Semantics/OpenMP/nested-target.f90 (+14-1) 


``````````diff
diff --git a/flang/lib/Semantics/check-omp-structure.cpp b/flang/lib/Semantics/check-omp-structure.cpp
index 014604627f2cd1..d4fa32d5f26520 100644
--- a/flang/lib/Semantics/check-omp-structure.cpp
+++ b/flang/lib/Semantics/check-omp-structure.cpp
@@ -785,7 +785,8 @@ void OmpStructureChecker::CheckTargetNest(const parser::OpenMPConstruct &c) {
                 std::get<parser::OmpBeginBlockDirective>(c.t)};
             const auto &beginDir{
                 std::get<parser::OmpBlockDirective>(beginBlockDir.t)};
-            if (beginDir.v == llvm::omp::Directive::OMPD_target_data) {
+            if (beginDir.v == llvm::omp::Directive::OMPD_target_data ||
+                llvm::omp::allTargetSet.test(beginDir.v)) {
               eligibleTarget = false;
               ineligibleTargetDir = beginDir.v;
             }
@@ -984,6 +985,20 @@ void OmpStructureChecker::Enter(const parser::OpenMPBlockConstruct &x) {
     if (llvm::omp::topTeamsSet.test(GetContextParent().directive)) {
       HasInvalidTeamsNesting(beginDir.v, beginDir.source);
     }
+    if ((llvm::omp::allTargetSet.test(GetContext().directive) ||
+            (GetContext().directive ==
+                llvm::omp::Directive::OMPD_target_data)) &&
+        (llvm::omp::allTargetSet.test(GetContextParent().directive) ||
+            (GetContextParent().directive ==
+                llvm::omp::Directive::OMPD_target_data))) {
+      context_.Warn(common::UsageWarning::OpenMPUsage,
+          parser::FindSourceLocation(x),
+          "If %s directive is nested inside %s region, the behaviour is unspecified"_port_en_US,
+          parser::ToUpperCaseLetters(
+              getDirectiveName(GetContext().directive).str()),
+          parser::ToUpperCaseLetters(
+              getDirectiveName(GetContextParent().directive).str()));
+    }
     if (GetContext().directive == llvm::omp::Directive::OMPD_master) {
       CheckMasterNesting(x);
     }
diff --git a/flang/test/Semantics/OpenMP/nested-simd.f90 b/flang/test/Semantics/OpenMP/nested-simd.f90
index 4149b6d97e9dc7..73e72cd5bf6a5a 100644
--- a/flang/test/Semantics/OpenMP/nested-simd.f90
+++ b/flang/test/Semantics/OpenMP/nested-simd.f90
@@ -166,6 +166,7 @@ SUBROUTINE NESTED_BAD(N)
       end do
       !$omp end task
       !ERROR: The only OpenMP constructs that can be encountered during execution of a 'SIMD' region are the `ATOMIC` construct, the `LOOP` construct, the `SIMD` construct and the `ORDERED` construct with the `SIMD` clause.
+      !ERROR: If TARGET directive is nested inside TARGET SIMD region, the behaviour is unspecified
       !$omp target 
       do J = 1, N
         K = 2
diff --git a/flang/test/Semantics/OpenMP/nested-target.f90 b/flang/test/Semantics/OpenMP/nested-target.f90
index 2267f70715d3ed..b054292ef54d58 100644
--- a/flang/test/Semantics/OpenMP/nested-target.f90
+++ b/flang/test/Semantics/OpenMP/nested-target.f90
@@ -5,7 +5,7 @@
 ! 2.12.5 Target Construct
 
 program main
-  integer :: i, j, N = 10
+  integer :: i, j, N = 10, n1, n2, res(100)
   real :: a, arrayA(512), arrayB(512), ai(10)
   real, allocatable :: B(:)
 
@@ -50,4 +50,17 @@ program main
   !$omp end target
   deallocate(B)
 
+  n1 = 10
+  n2 = 10
+  !$omp target teams map(to:a)
+  !PORTABILITY: If TARGET DATA directive is nested inside TARGET TEAMS region, the behaviour is unspecified
+  !$omp target data map(n1,n2)
+  do i=1, n1
+     do j=1, n2
+      res((i-1)*10+j) = i*j
+     end do
+  end do
+  !$omp end target data
+  !$omp end target teams
+
 end program main

``````````

</details>


https://github.com/llvm/llvm-project/pull/115344


More information about the flang-commits mailing list