[PATCH] D89860: [Flang][OpenMP 4.5] Add semantic check for OpenMP ordered and collapse clause
Yashaswini Hegde via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 21 02:23:00 PDT 2020
yhegde created this revision.
yhegde added reviewers: kiranchandramohan, richard.barton.arm, DavidTruby.
yhegde added projects: Flang, OpenMP, LLVM.
Herald added subscribers: llvm-commits, jdoerfert, guansong, yaxunl.
yhegde requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added a subscriber: sstefan1.
Semantic check for OpenMP 4.5 - 2.7.1 ordered and collapse clause
File:
1. resolve-directives.cpp CHECK(level == 0); is commented ; because semantic checks are invoked after this function is called, so the check will fail before checking the semantic errors.
Test cases:
1. omp-do-ordered.f90
2.omp-do-collapse.f90
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D89860
Files:
flang/lib/Semantics/resolve-directives.cpp
flang/test/Semantics/omp-do-collapse.f90
flang/test/Semantics/omp-do-ordered.f90
Index: flang/test/Semantics/omp-do-ordered.f90
===================================================================
--- /dev/null
+++ 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
Index: flang/test/Semantics/omp-do-collapse.f90
===================================================================
--- /dev/null
+++ 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
+
Index: flang/lib/Semantics/resolve-directives.cpp
===================================================================
--- flang/lib/Semantics/resolve-directives.cpp
+++ flang/lib/Semantics/resolve-directives.cpp
@@ -42,6 +42,7 @@
std::map<const Symbol *, Symbol::Flag> 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<parser::OmpClause::Collapse>(&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) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D89860.299604.patch
Type: text/x-patch
Size: 3227 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201021/20f2135a/attachment.bin>
More information about the llvm-commits
mailing list