Reapply [flang][OpenMP] Avoid early returns, NFC #117231#117325
Merged
Reapply [flang][OpenMP] Avoid early returns, NFC #117231#117325
Conversation
Two PRs were merged at the same time: one that modified `maybeApplyToV` function, and shortly afterwards, this (the reverted) one that had the old definition. During the merge both definitions were retained leading to compilation errors. Reapply the reverted PR (1a08b15) with the duplicate removed.
Member
|
@llvm/pr-subscribers-flang-semantics @llvm/pr-subscribers-flang-openmp Author: Krzysztof Parzyszek (kparzysz) ChangesTwo PRs were merged at the same time: one that modified During the merge both definitions were retained leading to compilation errors. Reapply the reverted PR (1a08b15) with the duplicate removed. Full diff: https://github.com/llvm/llvm-project/pull/117325.diff 2 Files Affected:
diff --git a/flang/lib/Semantics/check-omp-structure.cpp b/flang/lib/Semantics/check-omp-structure.cpp
index a4af1ce5771a891..e6398a39d979133 100644
--- a/flang/lib/Semantics/check-omp-structure.cpp
+++ b/flang/lib/Semantics/check-omp-structure.cpp
@@ -2865,45 +2865,41 @@ void OmpStructureChecker::Enter(const parser::OmpClause::Reduction &x) {
bool OmpStructureChecker::CheckReductionOperators(
const parser::OmpClause::Reduction &x) {
+ bool ok = false;
auto &modifiers{OmpGetModifiers(x.v)};
- const auto *definedOp{
- OmpGetUniqueModifier<parser::OmpReductionIdentifier>(modifiers)};
- if (!definedOp) {
- return false;
+ 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);
}
- 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 c75808a8963b3f5..107bd3b09019a05 100644
--- a/flang/lib/Semantics/resolve-directives.cpp
+++ b/flang/lib/Semantics/resolve-directives.cpp
@@ -522,49 +522,47 @@ class OmpAttributeVisitor : DirectiveAttributeVisitor<llvm::omp::Directive> {
const auto &objList{std::get<parser::OmpObjectList>(x.v.t)};
ResolveOmpObjectList(objList, Symbol::Flag::OmpReduction);
- auto &modifiers{OmpGetModifiers(x.v)};
- if (!modifiers) {
- return false;
- }
-
- 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;
- };
+ 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;
+ };
- 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);
+ 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;
|
kazutakahirata
approved these changes
Nov 23, 2024
Contributor
kazutakahirata
left a comment
There was a problem hiding this comment.
LGTM. This PR builds without a problem. Thanks!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two PRs were merged at the same time: one that modified
maybeApplyToVfunction, and shortly afterwards, this (the reverted) one that had the old definition.During the merge both definitions were retained leading to compilation errors.
Reapply the reverted PR (1a08b15) with the duplicate removed.