diff --git a/flang/lib/Semantics/resolve-directives.cpp b/flang/lib/Semantics/resolve-directives.cpp --- a/flang/lib/Semantics/resolve-directives.cpp +++ b/flang/lib/Semantics/resolve-directives.cpp @@ -42,6 +42,7 @@ std::map objectWithDSA; bool withinConstruct{false}; std::int64_t associatedLoopLevel{0}; + const parser::OmpClause *clause{nullptr}; }; DirContext &GetContext() { @@ -73,6 +74,12 @@ void SetContextAssociatedLoopLevel(std::int64_t level) { GetContext().associatedLoopLevel = level; } + void SetContextAssociatedClause(const parser::OmpClause &c) { + GetContext().clause = &c; + } + const parser::OmpClause *GetContextAssociatedClause() { + return GetContext().clause; + } Symbol &MakeAssocSymbol(const SourceName &name, Symbol &prev, Scope &scope) { const auto pair{scope.try_emplace(name, Attrs{}, HostAssocDetails{prev})}; return *pair.first->second; @@ -788,12 +795,14 @@ if (const auto v{EvaluateInt64(context_, orderedClause->v)}) { orderedLevel = *v; } + SetContextAssociatedClause(clause); } if (const auto *collapseClause{ std::get_if(&clause.u)}) { if (const auto v{EvaluateInt64(context_, collapseClause->v)}) { collapseLevel = *v; } + SetContextAssociatedClause(clause); } } @@ -845,7 +854,15 @@ const auto it{block.begin()}; loop = it != block.end() ? GetDoConstructIf(*it) : nullptr; } - CHECK(level == 0); + // CHECK(level == 0); + if (auto *clause{GetContextAssociatedClause()}) { + if (level != 0) { + context_.Say(clause->source, + "The value of the parameter in the collapse or ordered clause must" + " not be larger than the number of nested loops" + " following the construct."_err_en_US); + } + } } bool OmpAttributeVisitor::Pre(const parser::OpenMPSectionsConstruct &x) { diff --git a/flang/test/Semantics/omp-do-collapse.f90 b/flang/test/Semantics/omp-do-collapse.f90 new file mode 100644 --- /dev/null +++ b/flang/test/Semantics/omp-do-collapse.f90 @@ -0,0 +1,15 @@ +!RUN: %S/test_errors.sh %s %t %f18 -fopenmp +! OpenMP Version 4.5 +! 2.7.1 Collapse Clause +program omp_doCollapse + integer:: i,j + !ERROR: The value of the parameter in the collapse or ordered clause must not be larger than the number of nested loops following the construct. + !$omp do collapse(3) + do i = 1,10 + do j = 1, 10 + print *, "hello" + end do + end do + !$omp end do +end program omp_doCollapse + diff --git a/flang/test/Semantics/omp-do-ordered.f90 b/flang/test/Semantics/omp-do-ordered.f90 new file mode 100644 --- /dev/null +++ b/flang/test/Semantics/omp-do-ordered.f90 @@ -0,0 +1,14 @@ +!RUN: %S/test_errors.sh %s %t %f18 -fopenmp +! OpenMP Version 4.5 +! 2.7.1 Ordered Clause +program omp_doOrdered + integer:: i,j + !ERROR: The value of the parameter in the collapse or ordered clause must not be larger than the number of nested loops following the construct. + !$omp do ordered(3) + do i = 1,10 + do j = 1, 10 + print *, "hello" + end do + end do + !$omp end do +end program omp_doOrdered