[PATCH] D77821: [Flang][OpenMP] Avoid abort when collapse clause value is negative

Valentin Clement via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 9 12:30:13 PDT 2020


clementval created this revision.
clementval added a reviewer: ichoyjx.
Herald added subscribers: llvm-commits, guansong, yaxunl.
Herald added a reviewer: jdoerfert.
Herald added a project: LLVM.

If the value in the collapse close is negative f18 abort
without the correct error message. This PR change the size_t in 
name resolution to a int64_t and check appropriately for negative 
or zero before the privatization of induction variable.
The correct error is then catch by the OpenMP structure check.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D77821

Files:
  flang/lib/Semantics/resolve-names.cpp
  flang/test/Semantics/omp-clause-validity01.f90


Index: flang/test/Semantics/omp-clause-validity01.f90
===================================================================
--- flang/test/Semantics/omp-clause-validity01.f90
+++ flang/test/Semantics/omp-clause-validity01.f90
@@ -50,6 +50,15 @@
   enddo
   !$omp end parallel
 
+  !ERROR: The parameter of the COLLAPSE clause must be a constant positive integer expression
+  !$omp do collapse(-1)
+  do i = 1, N
+    do j = 1, N
+      a = 3.14
+    enddo
+  enddo
+  !$omp end do
+
   a = 1.0
   !$omp parallel firstprivate(a)
   do i = 1, N
Index: flang/lib/Semantics/resolve-names.cpp
===================================================================
--- flang/lib/Semantics/resolve-names.cpp
+++ flang/lib/Semantics/resolve-names.cpp
@@ -1234,7 +1234,7 @@
     // variables on Data-sharing attribute clauses
     std::map<const Symbol *, Symbol::Flag> objectWithDSA;
     bool withinConstruct{false};
-    std::size_t associatedLoopLevel{0};
+    int64_t associatedLoopLevel{0};
   };
   // back() is the top of the stack
   OmpContext &GetContext() {
@@ -1267,10 +1267,10 @@
     return it != GetContext().objectWithDSA.end();
   }
 
-  void SetContextAssociatedLoopLevel(std::size_t level) {
+  void SetContextAssociatedLoopLevel(int64_t level) {
     GetContext().associatedLoopLevel = level;
   }
-  std::size_t GetAssociatedLoopLevelFromClauses(const parser::OmpClauseList &);
+  int64_t GetAssociatedLoopLevelFromClauses(const parser::OmpClauseList &);
 
   Symbol &MakeAssocSymbol(const SourceName &name, Symbol &prev, Scope &scope) {
     const auto pair{scope.try_emplace(name, Attrs{}, HostAssocDetails{prev})};
@@ -6446,10 +6446,10 @@
   return nullptr;
 }
 
-std::size_t OmpAttributeVisitor::GetAssociatedLoopLevelFromClauses(
+int64_t OmpAttributeVisitor::GetAssociatedLoopLevelFromClauses(
     const parser::OmpClauseList &x) {
-  std::size_t orderedLevel{0};
-  std::size_t collapseLevel{0};
+  int64_t orderedLevel{0};
+  int64_t collapseLevel{0};
   for (const auto &clause : x.v) {
     if (const auto *orderedClause{
             std::get_if<parser::OmpClause::Ordered>(&clause.u)}) {
@@ -6488,7 +6488,9 @@
 //       clause has been performed (the number of nested do-loops >= n).
 void OmpAttributeVisitor::PrivatizeAssociatedLoopIndex(
     const parser::OpenMPLoopConstruct &x) {
-  std::size_t level{GetContext().associatedLoopLevel};
+  int64_t level{GetContext().associatedLoopLevel};
+  if(level <= 0)
+     return;
   Symbol::Flag ivDSA{Symbol::Flag::OmpPrivate};
   if (simdSet.test(GetContext().directive)) {
     if (level == 1) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D77821.256355.patch
Type: text/x-patch
Size: 2567 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200409/c3cec324/attachment.bin>


More information about the llvm-commits mailing list