Skip to content

Commit

Permalink
Reapply [flang][OpenMP] Avoid early returns, NFC #117231 (#117325)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kparzysz authored Nov 23, 2024
1 parent 70bd80d commit b0e7383
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 73 deletions.
70 changes: 33 additions & 37 deletions flang/lib/Semantics/check-omp-structure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2875,45 +2875,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;
}
Expand Down
70 changes: 34 additions & 36 deletions flang/lib/Semantics/resolve-directives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit b0e7383

Please sign in to comment.