[flang-commits] [flang] f6262fa - [flang] Extend `omp loop` semantic checks for `reduction` (#128823)
via flang-commits
flang-commits at lists.llvm.org
Thu Feb 27 03:08:07 PST 2025
Author: Kareem Ergawy
Date: 2025-02-27T12:08:04+01:00
New Revision: f6262fa035d8b942bf76e084fa875409bc8ff83a
URL: https://github.com/llvm/llvm-project/commit/f6262fa035d8b942bf76e084fa875409bc8ff83a
DIFF: https://github.com/llvm/llvm-project/commit/f6262fa035d8b942bf76e084fa875409bc8ff83a.diff
LOG: [flang] Extend `omp loop` semantic checks for `reduction` (#128823)
Extend semantic checks for `omp loop` directive to report errors when a
`reduction` clause is specified on a standalone `loop` directive with
`teams` binding.
This is similar to how clang behaves.
Added:
Modified:
flang/lib/Semantics/check-omp-structure.cpp
flang/test/Semantics/OpenMP/loop-bind.f90
Removed:
################################################################################
diff --git a/flang/lib/Semantics/check-omp-structure.cpp b/flang/lib/Semantics/check-omp-structure.cpp
index c95cf0d5921cf..906aed2dc0922 100644
--- a/flang/lib/Semantics/check-omp-structure.cpp
+++ b/flang/lib/Semantics/check-omp-structure.cpp
@@ -3134,6 +3134,18 @@ void OmpStructureChecker::Enter(const parser::OmpClause::Reduction &x) {
if (llvm::omp::nestedReduceWorkshareAllowedSet.test(GetContext().directive)) {
CheckSharedBindingInOuterContext(objects);
}
+
+ if (GetContext().directive == llvm::omp::Directive::OMPD_loop) {
+ for (auto clause : GetContext().clauseInfo) {
+ if (const auto *bindClause{
+ std::get_if<parser::OmpClause::Bind>(&clause.second->u)}) {
+ if (bindClause->v.v == parser::OmpBindClause::Binding::Teams) {
+ context_.Say(GetContext().clauseSource,
+ "'REDUCTION' clause not allowed with '!$OMP LOOP BIND(TEAMS)'."_err_en_US);
+ }
+ }
+ }
+ }
}
void OmpStructureChecker::Enter(const parser::OmpClause::InReduction &x) {
diff --git a/flang/test/Semantics/OpenMP/loop-bind.f90 b/flang/test/Semantics/OpenMP/loop-bind.f90
index f3aa9d19fe989..337a4521339fb 100644
--- a/flang/test/Semantics/OpenMP/loop-bind.f90
+++ b/flang/test/Semantics/OpenMP/loop-bind.f90
@@ -30,4 +30,9 @@ program main
end do
!$omp end teams loop
+ !ERROR: 'REDUCTION' clause not allowed with '!$OMP LOOP BIND(TEAMS)'.
+ !$omp loop bind(teams) reduction(+: x)
+ do i = 0, 10
+ x = x + i
+ end do
end program main
More information about the flang-commits
mailing list