[flang-commits] [flang] e73b803 - [flang][OpenMP] Extract check into separate function, NFC (#170728)
via flang-commits
flang-commits at lists.llvm.org
Thu Dec 4 12:01:32 PST 2025
Author: Krzysztof Parzyszek
Date: 2025-12-04T14:01:28-06:00
New Revision: e73b8036f82b70117c4707378018e354fd6aeae0
URL: https://github.com/llvm/llvm-project/commit/e73b8036f82b70117c4707378018e354fd6aeae0
DIFF: https://github.com/llvm/llvm-project/commit/e73b8036f82b70117c4707378018e354fd6aeae0.diff
LOG: [flang][OpenMP] Extract check into separate function, NFC (#170728)
Added:
Modified:
flang/lib/Semantics/check-omp-loop.cpp
flang/lib/Semantics/check-omp-structure.h
Removed:
################################################################################
diff --git a/flang/lib/Semantics/check-omp-loop.cpp b/flang/lib/Semantics/check-omp-loop.cpp
index 46ae3adaa6a68..fc4b9222d91b3 100644
--- a/flang/lib/Semantics/check-omp-loop.cpp
+++ b/flang/lib/Semantics/check-omp-loop.cpp
@@ -588,6 +588,42 @@ void OmpStructureChecker::CheckNestedFuse(
}
}
+void OmpStructureChecker::CheckScanModifier(
+ const parser::OmpClause::Reduction &x) {
+ using ReductionModifier = parser::OmpReductionModifier;
+
+ auto checkReductionSymbolInScan{[&](const parser::Name &name) {
+ if (auto *symbol{name.symbol}) {
+ if (!symbol->test(Symbol::Flag::OmpInclusiveScan) &&
+ !symbol->test(Symbol::Flag::OmpExclusiveScan)) {
+ context_.Say(name.source,
+ "List item %s must appear in EXCLUSIVE or INCLUSIVE clause of an enclosed SCAN directive"_err_en_US,
+ name.ToString());
+ }
+ }
+ }};
+
+ auto &modifiers{OmpGetModifiers(x.v)};
+ auto *maybeModifier{OmpGetUniqueModifier<ReductionModifier>(modifiers)};
+ if (maybeModifier && maybeModifier->v == ReductionModifier::Value::Inscan) {
+ for (const auto &ompObj : parser::omp::GetOmpObjectList(x)->v) {
+ common::visit(
+ common::visitors{
+ [&](const parser::Designator &desg) {
+ if (auto *name{parser::GetDesignatorNameIfDataRef(desg)}) {
+ checkReductionSymbolInScan(*name);
+ }
+ },
+ [&](const parser::Name &name) {
+ checkReductionSymbolInScan(name);
+ },
+ [&](const parser::OmpObject::Invalid &invalid) {},
+ },
+ ompObj.u);
+ }
+ }
+}
+
void OmpStructureChecker::Leave(const parser::OpenMPLoopConstruct &x) {
const parser::OmpClauseList &clauseList{x.BeginDir().Clauses()};
@@ -595,43 +631,9 @@ void OmpStructureChecker::Leave(const parser::OpenMPLoopConstruct &x) {
// constructs inside LOOP may add the relevant information. Scan reduction is
// supported only in loop constructs, so same checks are not applicable to
// other directives.
- using ReductionModifier = parser::OmpReductionModifier;
for (const auto &clause : clauseList.v) {
- if (const auto *reductionClause{
- std::get_if<parser::OmpClause::Reduction>(&clause.u)}) {
- auto &modifiers{OmpGetModifiers(reductionClause->v)};
- auto *maybeModifier{OmpGetUniqueModifier<ReductionModifier>(modifiers)};
- if (maybeModifier &&
- maybeModifier->v == ReductionModifier::Value::Inscan) {
- auto checkReductionSymbolInScan = [&](const parser::Name *name) {
- if (auto &symbol = name->symbol) {
- if (!symbol->test(Symbol::Flag::OmpInclusiveScan) &&
- !symbol->test(Symbol::Flag::OmpExclusiveScan)) {
- context_.Say(name->source,
- "List item %s must appear in EXCLUSIVE or "
- "INCLUSIVE clause of an "
- "enclosed SCAN directive"_err_en_US,
- name->ToString());
- }
- }
- };
- for (const auto &ompObj : parser::omp::GetOmpObjectList(clause)->v) {
- common::visit(
- common::visitors{
- [&](const parser::Designator &designator) {
- if (const auto *name{
- parser::GetDesignatorNameIfDataRef(designator)}) {
- checkReductionSymbolInScan(name);
- }
- },
- [&](const parser::Name &name) {
- checkReductionSymbolInScan(&name);
- },
- [&](const parser::OmpObject::Invalid &invalid) {},
- },
- ompObj.u);
- }
- }
+ if (auto *reduction{std::get_if<parser::OmpClause::Reduction>(&clause.u)}) {
+ CheckScanModifier(*reduction);
}
}
if (llvm::omp::allSimdSet.test(GetContext().directive)) {
diff --git a/flang/lib/Semantics/check-omp-structure.h b/flang/lib/Semantics/check-omp-structure.h
index a99d7c32a3f2b..5bd5ae050be64 100644
--- a/flang/lib/Semantics/check-omp-structure.h
+++ b/flang/lib/Semantics/check-omp-structure.h
@@ -321,6 +321,7 @@ class OmpStructureChecker : public OmpStructureCheckerBase {
void CheckAtomicWrite(const parser::OpenMPAtomicConstruct &x);
void CheckAtomicUpdate(const parser::OpenMPAtomicConstruct &x);
+ void CheckScanModifier(const parser::OmpClause::Reduction &x);
void CheckLooprangeBounds(const parser::OpenMPLoopConstruct &x);
void CheckNestedFuse(const parser::OpenMPLoopConstruct &x);
void CheckDistLinear(const parser::OpenMPLoopConstruct &x);
More information about the flang-commits
mailing list