[PATCH] D97964: [flang][OpenMP] Add semantic check for occurrence of multiple list items in aligned clause for simd directive

Arnamoy B via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 4 09:08:00 PST 2021


arnamoy10 created this revision.
arnamoy10 added reviewers: kiranchandramohan, clementval, richard.barton.arm, jdoerfert, praveen, sameeranjoshi, SouraVX.
Herald added subscribers: guansong, yaxunl.
Herald added a reviewer: sscalpone.
arnamoy10 requested review of this revision.
Herald added subscribers: llvm-commits, sstefan1.
Herald added a project: LLVM.

Add semantic check for occurrence of multiple list items in aligned clause for simd directive.  Also adds a test case


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D97964

Files:
  flang/lib/Semantics/check-omp-structure.cpp
  flang/test/Semantics/omp-simd-aligned.f90


Index: flang/test/Semantics/omp-simd-aligned.f90
===================================================================
--- /dev/null
+++ flang/test/Semantics/omp-simd-aligned.f90
@@ -0,0 +1,37 @@
+! RUN: %S/test_errors.sh %s %t %flang -fopenmp
+
+! OpenMP Version 4.5
+! 2.8.1 simd Construct
+! Semantic error for correct test case
+
+program omp_simd
+  integer i, j, k
+  integer, allocatable :: a(:), b(:)
+
+  allocate(a(10))
+  allocate(b(10))
+
+  !ERROR: List item 'a' present at multiple ALIGNED clauses
+  !$omp simd aligned(a, a)
+  do i = 1, 10
+    a(i) = i
+  end do
+  !$omp end simd
+
+  !ERROR: List item 'a' present at multiple ALIGNED clauses
+  !$omp simd aligned(a) aligned(a)
+  do i = 1, 10
+    a(i) = i
+  end do
+  !$omp end simd
+
+  !$omp simd aligned(a) aligned(b)
+  do i = 1, 10
+    a(i) = i
+    b(i) = i
+  end do
+  !$omp end simd
+
+  print *, a
+
+end program omp_simd
Index: flang/lib/Semantics/check-omp-structure.cpp
===================================================================
--- flang/lib/Semantics/check-omp-structure.cpp
+++ flang/lib/Semantics/check-omp-structure.cpp
@@ -534,7 +534,7 @@
 // 2. Checks on clauses which fall under 'struct OmpClause' from parse-tree.h.
 // 3. Checks on clauses which are not in 'struct OmpClause' from parse-tree.h.
 
-void OmpStructureChecker::Leave(const parser::OmpClauseList &) {
+void OmpStructureChecker::Leave(const parser::OmpClauseList &clauseList) {
   // 2.7 Loop Construct Restriction
   if (llvm::omp::doSet.test(GetContext().directive)) {
     if (auto *clause{FindClause(llvm::omp::Clause::OMPC_schedule)}) {
@@ -606,7 +606,30 @@
         }
       }
     }
-    // TODO: A list-item cannot appear in more than one aligned clause
+    // A list-item cannot appear in more than one aligned clause
+    std::set<std::string> alignedVars = {};
+    bool foundErr = false;
+    for (auto const &clause : clauseList.v) {
+      if (const auto *alignedClause{
+              std::get_if<parser::OmpClause::Aligned>(&clause.u)}) {
+        const auto &alignedNameList{
+            std::get<std::list<parser::Name>>(alignedClause->v.t)};
+        for (auto const &var : alignedNameList) {
+          if (alignedVars.count(var.ToString()) == 1) {
+            context_.Say(
+                clause.source,
+                "List item '%s' present at multiple ALIGNED clauses"_err_en_US,
+                var.ToString());
+            foundErr = true;
+            break;
+          }
+          alignedVars.insert(var.ToString());
+        }
+      }
+      // Report only once for multiple error within the same directive
+      if (foundErr)
+        break;
+    }
   } // SIMD
 
   // 2.7.3 Single Construct Restriction


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D97964.328199.patch
Type: text/x-patch
Size: 2711 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210304/c664c940/attachment-0001.bin>


More information about the llvm-commits mailing list