Skip to content

Commit b0e7383

Browse files
authored
Reapply [flang][OpenMP] Avoid early returns, NFC #117231 (#117325)
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.
1 parent 70bd80d commit b0e7383

File tree

2 files changed

+67
-73
lines changed

2 files changed

+67
-73
lines changed

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

Lines changed: 33 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2875,45 +2875,41 @@ void OmpStructureChecker::Enter(const parser::OmpClause::Reduction &x) {
28752875

28762876
bool OmpStructureChecker::CheckReductionOperators(
28772877
const parser::OmpClause::Reduction &x) {
2878+
bool ok = false;
28782879
auto &modifiers{OmpGetModifiers(x.v)};
2879-
const auto *definedOp{
2880-
OmpGetUniqueModifier<parser::OmpReductionIdentifier>(modifiers)};
2881-
if (!definedOp) {
2882-
return false;
2880+
if (const auto *ident{
2881+
OmpGetUniqueModifier<parser::OmpReductionIdentifier>(modifiers)}) {
2882+
2883+
auto visitOperator{[&](const parser::DefinedOperator &dOpr) {
2884+
if (const auto *intrinsicOp{
2885+
std::get_if<parser::DefinedOperator::IntrinsicOperator>(
2886+
&dOpr.u)}) {
2887+
ok = CheckIntrinsicOperator(*intrinsicOp);
2888+
} else {
2889+
context_.Say(GetContext().clauseSource,
2890+
"Invalid reduction operator in REDUCTION clause."_err_en_US,
2891+
ContextDirectiveAsFortran());
2892+
}
2893+
}};
2894+
2895+
auto visitDesignator{[&](const parser::ProcedureDesignator &procD) {
2896+
const parser::Name *name{std::get_if<parser::Name>(&procD.u)};
2897+
if (name && name->symbol) {
2898+
const SourceName &realName{name->symbol->GetUltimate().name()};
2899+
if (realName == "max" || realName == "min" || realName == "iand" ||
2900+
realName == "ior" || realName == "ieor") {
2901+
ok = true;
2902+
}
2903+
}
2904+
if (!ok) {
2905+
context_.Say(GetContext().clauseSource,
2906+
"Invalid reduction identifier in REDUCTION "
2907+
"clause."_err_en_US,
2908+
ContextDirectiveAsFortran());
2909+
}
2910+
}};
2911+
common::visit(common::visitors{visitOperator, visitDesignator}, ident->u);
28832912
}
2884-
bool ok = false;
2885-
common::visit(
2886-
common::visitors{
2887-
[&](const parser::DefinedOperator &dOpr) {
2888-
if (const auto *intrinsicOp{
2889-
std::get_if<parser::DefinedOperator::IntrinsicOperator>(
2890-
&dOpr.u)}) {
2891-
ok = CheckIntrinsicOperator(*intrinsicOp);
2892-
} else {
2893-
context_.Say(GetContext().clauseSource,
2894-
"Invalid reduction operator in REDUCTION clause."_err_en_US,
2895-
ContextDirectiveAsFortran());
2896-
}
2897-
},
2898-
[&](const parser::ProcedureDesignator &procD) {
2899-
const parser::Name *name{std::get_if<parser::Name>(&procD.u)};
2900-
if (name && name->symbol) {
2901-
const SourceName &realName{name->symbol->GetUltimate().name()};
2902-
if (realName == "max" || realName == "min" ||
2903-
realName == "iand" || realName == "ior" ||
2904-
realName == "ieor") {
2905-
ok = true;
2906-
}
2907-
}
2908-
if (!ok) {
2909-
context_.Say(GetContext().clauseSource,
2910-
"Invalid reduction identifier in REDUCTION "
2911-
"clause."_err_en_US,
2912-
ContextDirectiveAsFortran());
2913-
}
2914-
},
2915-
},
2916-
definedOp->u);
29172913

29182914
return ok;
29192915
}

flang/lib/Semantics/resolve-directives.cpp

Lines changed: 34 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -522,49 +522,47 @@ class OmpAttributeVisitor : DirectiveAttributeVisitor<llvm::omp::Directive> {
522522
const auto &objList{std::get<parser::OmpObjectList>(x.v.t)};
523523
ResolveOmpObjectList(objList, Symbol::Flag::OmpReduction);
524524

525-
auto &modifiers{OmpGetModifiers(x.v)};
526-
if (!modifiers) {
527-
return false;
528-
}
529-
530-
auto createDummyProcSymbol = [&](const parser::Name *name) {
531-
// If name resolution failed, create a dummy symbol
532-
const auto namePair{
533-
currScope().try_emplace(name->source, Attrs{}, ProcEntityDetails{})};
534-
auto &newSymbol{*namePair.first->second};
535-
if (context_.intrinsics().IsIntrinsic(name->ToString())) {
536-
newSymbol.attrs().set(Attr::INTRINSIC);
537-
}
538-
name->symbol = &newSymbol;
539-
};
525+
if (auto &modifiers{OmpGetModifiers(x.v)}) {
526+
auto createDummyProcSymbol = [&](const parser::Name *name) {
527+
// If name resolution failed, create a dummy symbol
528+
const auto namePair{currScope().try_emplace(
529+
name->source, Attrs{}, ProcEntityDetails{})};
530+
auto &newSymbol{*namePair.first->second};
531+
if (context_.intrinsics().IsIntrinsic(name->ToString())) {
532+
newSymbol.attrs().set(Attr::INTRINSIC);
533+
}
534+
name->symbol = &newSymbol;
535+
};
540536

541-
for (auto &mod : *modifiers) {
542-
if (!std::holds_alternative<parser::OmpReductionIdentifier>(mod.u)) {
543-
continue;
544-
}
545-
auto &opr{std::get<parser::OmpReductionIdentifier>(mod.u)};
546-
if (auto *procD{parser::Unwrap<parser::ProcedureDesignator>(opr.u)}) {
547-
if (auto *name{parser::Unwrap<parser::Name>(procD->u)}) {
548-
if (!name->symbol) {
549-
if (!ResolveName(name)) {
550-
createDummyProcSymbol(name);
537+
for (auto &mod : *modifiers) {
538+
if (!std::holds_alternative<parser::OmpReductionIdentifier>(mod.u)) {
539+
continue;
540+
}
541+
auto &opr{std::get<parser::OmpReductionIdentifier>(mod.u)};
542+
if (auto *procD{parser::Unwrap<parser::ProcedureDesignator>(opr.u)}) {
543+
if (auto *name{parser::Unwrap<parser::Name>(procD->u)}) {
544+
if (!name->symbol) {
545+
if (!ResolveName(name)) {
546+
createDummyProcSymbol(name);
547+
}
551548
}
552549
}
553-
}
554-
if (auto *procRef{parser::Unwrap<parser::ProcComponentRef>(procD->u)}) {
555-
if (!procRef->v.thing.component.symbol) {
556-
if (!ResolveName(&procRef->v.thing.component)) {
557-
createDummyProcSymbol(&procRef->v.thing.component);
550+
if (auto *procRef{
551+
parser::Unwrap<parser::ProcComponentRef>(procD->u)}) {
552+
if (!procRef->v.thing.component.symbol) {
553+
if (!ResolveName(&procRef->v.thing.component)) {
554+
createDummyProcSymbol(&procRef->v.thing.component);
555+
}
558556
}
559557
}
560558
}
561559
}
562-
}
563-
using ReductionModifier = parser::OmpReductionModifier;
564-
if (auto *maybeModifier{
565-
OmpGetUniqueModifier<ReductionModifier>(modifiers)}) {
566-
if (maybeModifier->v == ReductionModifier::Value::Inscan) {
567-
ResolveOmpObjectList(objList, Symbol::Flag::OmpInScanReduction);
560+
using ReductionModifier = parser::OmpReductionModifier;
561+
if (auto *maybeModifier{
562+
OmpGetUniqueModifier<ReductionModifier>(modifiers)}) {
563+
if (maybeModifier->v == ReductionModifier::Value::Inscan) {
564+
ResolveOmpObjectList(objList, Symbol::Flag::OmpInScanReduction);
565+
}
568566
}
569567
}
570568
return false;

0 commit comments

Comments
 (0)