[flang-commits] [flang] 764cfd7 - Revert "[flang][OpenMP] Avoid early returns, NFC (#117231)"
Kazu Hirata via flang-commits
flang-commits at lists.llvm.org
Thu Nov 21 19:16:43 PST 2024
Author: Kazu Hirata
Date: 2024-11-21T19:16:36-08:00
New Revision: 764cfd7d09647d7d49d5e0ae7b19ce0bd4b0968d
URL: https://github.com/llvm/llvm-project/commit/764cfd7d09647d7d49d5e0ae7b19ce0bd4b0968d
DIFF: https://github.com/llvm/llvm-project/commit/764cfd7d09647d7d49d5e0ae7b19ce0bd4b0968d.diff
LOG: Revert "[flang][OpenMP] Avoid early returns, NFC (#117231)"
This reverts commit 1a08b155899ee3ed6a6c441799991a8be5df801e.
Buildbot failure:
https://lab.llvm.org/buildbot/#/builders/157/builds/13427
Added:
Modified:
flang/lib/Lower/OpenMP/Clauses.h
flang/lib/Semantics/check-omp-structure.cpp
flang/lib/Semantics/resolve-directives.cpp
Removed:
################################################################################
diff --git a/flang/lib/Lower/OpenMP/Clauses.h b/flang/lib/Lower/OpenMP/Clauses.h
index 3aa8cd3dda803f..9c74404801bbc0 100644
--- a/flang/lib/Lower/OpenMP/Clauses.h
+++ b/flang/lib/Lower/OpenMP/Clauses.h
@@ -163,16 +163,6 @@ std::optional<ResultTy> maybeApplyToV(FuncTy &&func, const ArgTy *arg) {
return func(arg->v);
}
-template <
- typename FuncTy, //
- typename ArgTy, //
- typename ResultTy = std::invoke_result_t<FuncTy, typename ArgTy::Value>>
-std::optional<ResultTy> maybeApplyToV(FuncTy &&func, const ArgTy *arg) {
- if (!arg)
- return std::nullopt;
- return std::move(func(arg->v));
-}
-
std::optional<Object> getBaseObject(const Object &object,
semantics::SemanticsContext &semaCtx);
diff --git a/flang/lib/Semantics/check-omp-structure.cpp b/flang/lib/Semantics/check-omp-structure.cpp
index e6398a39d97913..a4af1ce5771a89 100644
--- a/flang/lib/Semantics/check-omp-structure.cpp
+++ b/flang/lib/Semantics/check-omp-structure.cpp
@@ -2865,41 +2865,45 @@ void OmpStructureChecker::Enter(const parser::OmpClause::Reduction &x) {
bool OmpStructureChecker::CheckReductionOperators(
const parser::OmpClause::Reduction &x) {
- bool ok = false;
auto &modifiers{OmpGetModifiers(x.v)};
- if (const auto *ident{
- OmpGetUniqueModifier<parser::OmpReductionIdentifier>(modifiers)}) {
-
- auto visitOperator{[&](const parser::DefinedOperator &dOpr) {
- if (const auto *intrinsicOp{
- std::get_if<parser::DefinedOperator::IntrinsicOperator>(
- &dOpr.u)}) {
- ok = CheckIntrinsicOperator(*intrinsicOp);
- } else {
- context_.Say(GetContext().clauseSource,
- "Invalid reduction operator in REDUCTION clause."_err_en_US,
- ContextDirectiveAsFortran());
- }
- }};
-
- auto visitDesignator{[&](const parser::ProcedureDesignator &procD) {
- const parser::Name *name{std::get_if<parser::Name>(&procD.u)};
- if (name && name->symbol) {
- const SourceName &realName{name->symbol->GetUltimate().name()};
- if (realName == "max" || realName == "min" || realName == "iand" ||
- realName == "ior" || realName == "ieor") {
- ok = true;
- }
- }
- if (!ok) {
- context_.Say(GetContext().clauseSource,
- "Invalid reduction identifier in REDUCTION "
- "clause."_err_en_US,
- ContextDirectiveAsFortran());
- }
- }};
- common::visit(common::visitors{visitOperator, visitDesignator}, ident->u);
+ const auto *definedOp{
+ OmpGetUniqueModifier<parser::OmpReductionIdentifier>(modifiers)};
+ if (!definedOp) {
+ return false;
}
+ bool ok = false;
+ common::visit(
+ common::visitors{
+ [&](const parser::DefinedOperator &dOpr) {
+ if (const auto *intrinsicOp{
+ std::get_if<parser::DefinedOperator::IntrinsicOperator>(
+ &dOpr.u)}) {
+ ok = CheckIntrinsicOperator(*intrinsicOp);
+ } else {
+ context_.Say(GetContext().clauseSource,
+ "Invalid reduction operator in REDUCTION clause."_err_en_US,
+ ContextDirectiveAsFortran());
+ }
+ },
+ [&](const parser::ProcedureDesignator &procD) {
+ const parser::Name *name{std::get_if<parser::Name>(&procD.u)};
+ if (name && name->symbol) {
+ const SourceName &realName{name->symbol->GetUltimate().name()};
+ if (realName == "max" || realName == "min" ||
+ realName == "iand" || realName == "ior" ||
+ realName == "ieor") {
+ ok = true;
+ }
+ }
+ if (!ok) {
+ context_.Say(GetContext().clauseSource,
+ "Invalid reduction identifier in REDUCTION "
+ "clause."_err_en_US,
+ ContextDirectiveAsFortran());
+ }
+ },
+ },
+ definedOp->u);
return ok;
}
diff --git a/flang/lib/Semantics/resolve-directives.cpp b/flang/lib/Semantics/resolve-directives.cpp
index 107bd3b09019a0..c75808a8963b3f 100644
--- a/flang/lib/Semantics/resolve-directives.cpp
+++ b/flang/lib/Semantics/resolve-directives.cpp
@@ -522,47 +522,49 @@ class OmpAttributeVisitor : DirectiveAttributeVisitor<llvm::omp::Directive> {
const auto &objList{std::get<parser::OmpObjectList>(x.v.t)};
ResolveOmpObjectList(objList, Symbol::Flag::OmpReduction);
- if (auto &modifiers{OmpGetModifiers(x.v)}) {
- auto createDummyProcSymbol = [&](const parser::Name *name) {
- // If name resolution failed, create a dummy symbol
- const auto namePair{currScope().try_emplace(
- name->source, Attrs{}, ProcEntityDetails{})};
- auto &newSymbol{*namePair.first->second};
- if (context_.intrinsics().IsIntrinsic(name->ToString())) {
- newSymbol.attrs().set(Attr::INTRINSIC);
- }
- name->symbol = &newSymbol;
- };
+ auto &modifiers{OmpGetModifiers(x.v)};
+ if (!modifiers) {
+ return false;
+ }
- for (auto &mod : *modifiers) {
- if (!std::holds_alternative<parser::OmpReductionIdentifier>(mod.u)) {
- continue;
- }
- auto &opr{std::get<parser::OmpReductionIdentifier>(mod.u)};
- if (auto *procD{parser::Unwrap<parser::ProcedureDesignator>(opr.u)}) {
- if (auto *name{parser::Unwrap<parser::Name>(procD->u)}) {
- if (!name->symbol) {
- if (!ResolveName(name)) {
- createDummyProcSymbol(name);
- }
+ auto createDummyProcSymbol = [&](const parser::Name *name) {
+ // If name resolution failed, create a dummy symbol
+ const auto namePair{
+ currScope().try_emplace(name->source, Attrs{}, ProcEntityDetails{})};
+ auto &newSymbol{*namePair.first->second};
+ if (context_.intrinsics().IsIntrinsic(name->ToString())) {
+ newSymbol.attrs().set(Attr::INTRINSIC);
+ }
+ name->symbol = &newSymbol;
+ };
+
+ for (auto &mod : *modifiers) {
+ if (!std::holds_alternative<parser::OmpReductionIdentifier>(mod.u)) {
+ continue;
+ }
+ auto &opr{std::get<parser::OmpReductionIdentifier>(mod.u)};
+ if (auto *procD{parser::Unwrap<parser::ProcedureDesignator>(opr.u)}) {
+ if (auto *name{parser::Unwrap<parser::Name>(procD->u)}) {
+ if (!name->symbol) {
+ if (!ResolveName(name)) {
+ createDummyProcSymbol(name);
}
}
- if (auto *procRef{
- parser::Unwrap<parser::ProcComponentRef>(procD->u)}) {
- if (!procRef->v.thing.component.symbol) {
- if (!ResolveName(&procRef->v.thing.component)) {
- createDummyProcSymbol(&procRef->v.thing.component);
- }
+ }
+ if (auto *procRef{parser::Unwrap<parser::ProcComponentRef>(procD->u)}) {
+ if (!procRef->v.thing.component.symbol) {
+ if (!ResolveName(&procRef->v.thing.component)) {
+ createDummyProcSymbol(&procRef->v.thing.component);
}
}
}
}
- using ReductionModifier = parser::OmpReductionModifier;
- if (auto *maybeModifier{
- OmpGetUniqueModifier<ReductionModifier>(modifiers)}) {
- if (maybeModifier->v == ReductionModifier::Value::Inscan) {
- ResolveOmpObjectList(objList, Symbol::Flag::OmpInScanReduction);
- }
+ }
+ using ReductionModifier = parser::OmpReductionModifier;
+ if (auto *maybeModifier{
+ OmpGetUniqueModifier<ReductionModifier>(modifiers)}) {
+ if (maybeModifier->v == ReductionModifier::Value::Inscan) {
+ ResolveOmpObjectList(objList, Symbol::Flag::OmpInScanReduction);
}
}
return false;
More information about the flang-commits
mailing list