Skip to content

Commit f6262fa

Browse files
authored
[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.
1 parent 8150ab9 commit f6262fa

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

flang/lib/Semantics/check-omp-structure.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3134,6 +3134,18 @@ void OmpStructureChecker::Enter(const parser::OmpClause::Reduction &x) {
31343134
if (llvm::omp::nestedReduceWorkshareAllowedSet.test(GetContext().directive)) {
31353135
CheckSharedBindingInOuterContext(objects);
31363136
}
3137+
3138+
if (GetContext().directive == llvm::omp::Directive::OMPD_loop) {
3139+
for (auto clause : GetContext().clauseInfo) {
3140+
if (const auto *bindClause{
3141+
std::get_if<parser::OmpClause::Bind>(&clause.second->u)}) {
3142+
if (bindClause->v.v == parser::OmpBindClause::Binding::Teams) {
3143+
context_.Say(GetContext().clauseSource,
3144+
"'REDUCTION' clause not allowed with '!$OMP LOOP BIND(TEAMS)'."_err_en_US);
3145+
}
3146+
}
3147+
}
3148+
}
31373149
}
31383150

31393151
void OmpStructureChecker::Enter(const parser::OmpClause::InReduction &x) {

flang/test/Semantics/OpenMP/loop-bind.f90

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,9 @@ program main
3030
end do
3131
!$omp end teams loop
3232

33+
!ERROR: 'REDUCTION' clause not allowed with '!$OMP LOOP BIND(TEAMS)'.
34+
!$omp loop bind(teams) reduction(+: x)
35+
do i = 0, 10
36+
x = x + i
37+
end do
3338
end program main

0 commit comments

Comments
 (0)