diff --git a/flang/lib/Lower/OpenMP/DataSharingProcessor.cpp b/flang/lib/Lower/OpenMP/DataSharingProcessor.cpp index 2ac4d9548b65b..2c0cbb2b6168f 100644 --- a/flang/lib/Lower/OpenMP/DataSharingProcessor.cpp +++ b/flang/lib/Lower/OpenMP/DataSharingProcessor.cpp @@ -389,42 +389,16 @@ void DataSharingProcessor::insertLastPrivateCompare(mlir::Operation *op) { } } -static const parser::CharBlock * -getSource(const semantics::SemanticsContext &semaCtx, - const lower::pft::Evaluation &eval) { - const parser::CharBlock *source = nullptr; - - auto ompConsVisit = [&](const parser::OpenMPConstruct &x) { - std::visit( - common::visitors{ - [&](const parser::OpenMPSectionsConstruct &x) { - source = &std::get<0>(x.t).source; - }, - [&](const parser::OpenMPLoopConstruct &x) { - source = &std::get<0>(x.t).source; - }, - [&](const parser::OpenMPBlockConstruct &x) { - source = &std::get<0>(x.t).source; - }, - [&](const parser::OpenMPCriticalConstruct &x) { - source = &std::get<0>(x.t).source; - }, - [&](const parser::OpenMPAtomicConstruct &x) { - source = &std::get(x.t).source; - }, - [&](const auto &x) { source = &x.source; }, - }, - x.u); - }; - - eval.visit(common::visitors{ - [&](const parser::OpenMPConstruct &x) { ompConsVisit(x); }, - [&](const parser::OpenMPDeclarativeConstruct &x) { source = &x.source; }, - [&](const parser::OmpEndLoopDirective &x) { source = &x.source; }, - [&](const auto &x) {}, +static parser::CharBlock getSource(const semantics::SemanticsContext &semaCtx, + const lower::pft::Evaluation &eval) { + return eval.visit(common::visitors{ + [&](const parser::OpenMPConstruct &x) { + return parser::omp::GetOmpDirectiveName(x).source; + }, + [&](const parser::OpenMPDeclarativeConstruct &x) { return x.source; }, + [&](const parser::OmpEndLoopDirective &x) { return x.source; }, + [&](const auto &x) { return parser::CharBlock{}; }, }); - - return source; } static void collectPrivatizingConstructs( @@ -518,11 +492,11 @@ void DataSharingProcessor::collectSymbols( for (const semantics::Scope &child : scope->children()) collectScopes(&child); }; - const parser::CharBlock *source = - clauses.empty() ? getSource(semaCtx, eval) : &clauses.front().source; + parser::CharBlock source = + clauses.empty() ? getSource(semaCtx, eval) : clauses.front().source; const semantics::Scope *curScope = nullptr; - if (source && !source->empty()) { - curScope = &semaCtx.FindScope(*source); + if (!source.empty()) { + curScope = &semaCtx.FindScope(source); collectScopes(curScope); } // Collect all symbols referenced in the evaluation being processed,