[flang-commits] [flang] 525396a - [flang][OpenMP] Add semantic check for device clause (#72789)

via flang-commits flang-commits at lists.llvm.org
Mon Nov 20 17:54:26 PST 2023


Author: Shraiysh
Date: 2023-11-20T19:54:22-06:00
New Revision: 525396a3ae63a1b35695bd2c0c0a7ccef8271f3d

URL: https://github.com/llvm/llvm-project/commit/525396a3ae63a1b35695bd2c0c0a7ccef8271f3d
DIFF: https://github.com/llvm/llvm-project/commit/525396a3ae63a1b35695bd2c0c0a7ccef8271f3d.diff

LOG: [flang][OpenMP] Add semantic check for device clause (#72789)

This patch adds the following semantic check:

```
The ancestor device-modifier must not appear on the device clause on any
directive other than the target construct.
```

Added: 
    flang/test/Semantics/OpenMP/device-clause01.f90

Modified: 
    flang/lib/Semantics/check-omp-structure.cpp

Removed: 
    


################################################################################
diff  --git a/flang/lib/Semantics/check-omp-structure.cpp b/flang/lib/Semantics/check-omp-structure.cpp
index 0b1a581bf298196..6589395e06ca484 100644
--- a/flang/lib/Semantics/check-omp-structure.cpp
+++ b/flang/lib/Semantics/check-omp-structure.cpp
@@ -2748,6 +2748,17 @@ void OmpStructureChecker::Enter(const parser::OmpClause::Device &x) {
   const auto &device{std::get<1>(deviceClause.t)};
   RequiresPositiveParameter(
       llvm::omp::Clause::OMPC_device, device, "device expression");
+  std::optional<parser::OmpDeviceClause::DeviceModifier> modifier =
+      std::get<0>(deviceClause.t);
+  if (modifier &&
+      *modifier == parser::OmpDeviceClause::DeviceModifier::Ancestor) {
+    if (GetContext().directive != llvm::omp::OMPD_target) {
+      context_.Say(GetContext().clauseSource,
+          "The ANCESTOR device-modifier must not appear on the DEVICE clause on"
+          " any directive other than the TARGET construct. Found on %s construct."_err_en_US,
+          parser::ToUpperCaseLetters(getDirectiveName(GetContext().directive)));
+    }
+  }
 }
 
 void OmpStructureChecker::Enter(const parser::OmpClause::Depend &x) {

diff  --git a/flang/test/Semantics/OpenMP/device-clause01.f90 b/flang/test/Semantics/OpenMP/device-clause01.f90
new file mode 100644
index 000000000000000..6f95d162790d575
--- /dev/null
+++ b/flang/test/Semantics/OpenMP/device-clause01.f90
@@ -0,0 +1,31 @@
+! RUN: %python %S/../test_errors.py %s %flang -fopenmp
+! OpenMP Version 5.2
+! 13.2 Device clause
+
+subroutine foo
+
+  integer :: a
+
+  !$omp target device(ancestor:0)
+  !$omp end target
+  !$omp target device(device_num:0)
+  !$omp end target
+  
+  !ERROR: The ANCESTOR device-modifier must not appear on the DEVICE clause on any directive other than the TARGET construct. Found on TARGET DATA construct.
+  !$omp target data device(ancestor:0) map(tofrom:a)
+  !$omp end target data
+  !$omp target data device(device_num:0) map(tofrom:a)
+  !$omp end target data
+
+  
+  !ERROR: The ANCESTOR device-modifier must not appear on the DEVICE clause on any directive other than the TARGET construct. Found on TARGET ENTER DATA construct.
+  !$omp target enter data device(ancestor:0) map(to:a)
+  !$omp target exit data map(from:a)
+  !$omp target enter data device(device_num:0) map(to:a)
+  !$omp target exit data map(from:a)
+
+  !ERROR: The ANCESTOR device-modifier must not appear on the DEVICE clause on any directive other than the TARGET construct. Found on TARGET UPDATE construct.
+  !$omp target update device(ancestor:0) to(a)
+  !$omp target update device(device_num:0) to(a)
+
+end subroutine foo


        


More information about the flang-commits mailing list