[flang-commits] [flang] [flang][OpenMP] Add semantic check for target update (PR #71305)

via flang-commits flang-commits at lists.llvm.org
Sun Nov 5 00:11:02 PDT 2023


https://github.com/shraiysh created https://github.com/llvm/llvm-project/pull/71305

This patch adds the following semantic check for target update construct.

```
A list item can only appear in a to or from clause, but not in both.
```

>From fd9fb7bbb87b0e588ee249a8b5bf54ea86b0d176 Mon Sep 17 00:00:00 2001
From: Shraiysh Vaishay <shraiysh.vaishay at amd.com>
Date: Sun, 5 Nov 2023 01:08:48 -0600
Subject: [PATCH] [flang][OpenMP] Add semantic check for target update

This patch adds the following semantic check for target update
construct.

```
A list item can only appear in a to or from clause, but not in both.
```
---
 flang/lib/Semantics/check-omp-structure.cpp     | 14 ++++++++++++++
 flang/test/Semantics/OpenMP/target-update01.f90 |  3 +++
 2 files changed, 17 insertions(+)

diff --git a/flang/lib/Semantics/check-omp-structure.cpp b/flang/lib/Semantics/check-omp-structure.cpp
index a328424e0c098d0..9f8af2217e47be2 100644
--- a/flang/lib/Semantics/check-omp-structure.cpp
+++ b/flang/lib/Semantics/check-omp-structure.cpp
@@ -1401,6 +1401,20 @@ void OmpStructureChecker::CheckTargetUpdate() {
     context_.Say(GetContext().directiveSource,
         "At least one motion-clause (TO/FROM) must be specified on TARGET UPDATE construct."_err_en_US);
   }
+  if (toClause && fromClause) {
+    SymbolSourceMap toSymbols, fromSymbols;
+    GetSymbolsInObjectList(
+        std::get<parser::OmpClause::To>(toClause->u).v, toSymbols);
+    GetSymbolsInObjectList(
+        std::get<parser::OmpClause::From>(fromClause->u).v, fromSymbols);
+    for (auto &[symbol, source] : toSymbols) {
+      if (fromSymbols.find(symbol) != fromSymbols.end()) {
+        context_.Say(source,
+            "Symbol '%s': A list item can only appear in a to or from clause, but not in both."_err_en_US,
+            symbol->name());
+      }
+    }
+  }
 }
 
 void OmpStructureChecker::Enter(
diff --git a/flang/test/Semantics/OpenMP/target-update01.f90 b/flang/test/Semantics/OpenMP/target-update01.f90
index a0728e52ba3d230..f77d3f248df6a0a 100644
--- a/flang/test/Semantics/OpenMP/target-update01.f90
+++ b/flang/test/Semantics/OpenMP/target-update01.f90
@@ -13,4 +13,7 @@ subroutine foo(x)
   !ERROR: At most one NOWAIT clause can appear on the TARGET UPDATE directive
   !$omp target update to(x) nowait nowait
 
+  !ERROR: Symbol 'x': A list item can only appear in a to or from clause, but not in both.
+  !$omp target update to(x) from(x)
+
 end subroutine



More information about the flang-commits mailing list