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

via flang-commits flang-commits at lists.llvm.org
Mon Nov 6 15:16:18 PST 2023


Author: Shraiysh
Date: 2023-11-06T17:16:14-06:00
New Revision: ee1000573e5063f26dcc110983e98fde31e76c87

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

LOG: [flang][OpenMP] Add semantic check for target update (#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.
```

Added: 
    

Modified: 
    flang/lib/Semantics/check-omp-structure.cpp
    flang/test/Semantics/OpenMP/target-update01.f90

Removed: 
    


################################################################################
diff  --git a/flang/lib/Semantics/check-omp-structure.cpp b/flang/lib/Semantics/check-omp-structure.cpp
index 2054a13bd92e790..512a44ba77da16f 100644
--- a/flang/lib/Semantics/check-omp-structure.cpp
+++ b/flang/lib/Semantics/check-omp-structure.cpp
@@ -1401,6 +1401,26 @@ 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) {
+      auto fromSymbol = fromSymbols.find(symbol);
+      if (fromSymbol != fromSymbols.end()) {
+        context_.Say(source,
+            "A list item ('%s') can only appear in a TO or FROM clause, but not in both."_err_en_US,
+            symbol->name());
+        context_.Say(source, "'%s' appears in the TO clause."_because_en_US,
+            symbol->name());
+        context_.Say(fromSymbol->second,
+            "'%s' appears in the FROM clause."_because_en_US,
+            fromSymbol->first->name());
+      }
+    }
+  }
 }
 
 void OmpStructureChecker::Enter(

diff  --git a/flang/test/Semantics/OpenMP/target-update01.f90 b/flang/test/Semantics/OpenMP/target-update01.f90
index a0728e52ba3d230..84dc60dcd75f5c1 100644
--- a/flang/test/Semantics/OpenMP/target-update01.f90
+++ b/flang/test/Semantics/OpenMP/target-update01.f90
@@ -13,4 +13,9 @@ subroutine foo(x)
   !ERROR: At most one NOWAIT clause can appear on the TARGET UPDATE directive
   !$omp target update to(x) nowait nowait
 
+  !ERROR: A list item ('x') can only appear in a TO or FROM clause, but not in both.
+  !BECAUSE: 'x' appears in the TO clause.
+  !BECAUSE: 'x' appears in the FROM clause.
+  !$omp target update to(x) from(x)
+
 end subroutine


        


More information about the flang-commits mailing list