@@ -36,12 +36,12 @@ namespace lower {
3636namespace omp {
3737bool DataSharingProcessor::OMPConstructSymbolVisitor::isSymbolDefineBy (
3838 const semantics::Symbol *symbol, lower::pft::Evaluation &eval) const {
39- return eval.visit (
40- common::visitors{ [&](const parser::OpenMPConstruct &functionParserNode) {
41- return symDefMap.count (symbol) &&
42- symDefMap.at (symbol) == &functionParserNode;
43- },
44- [](const auto &functionParserNode) { return false ; }});
39+ return eval.visit (common::visitors{
40+ [&](const parser::OpenMPConstruct &functionParserNode) {
41+ return symDefMap.count (symbol) &&
42+ symDefMap.at (symbol) == ConstructPtr ( &functionParserNode) ;
43+ },
44+ [](const auto &functionParserNode) { return false ; }});
4545}
4646
4747static bool isConstructWithTopLevelTarget (lower::pft::Evaluation &eval) {
@@ -553,8 +553,16 @@ void DataSharingProcessor::collectSymbols(
553553 return sym->test (semantics::Symbol::Flag::OmpImplicit);
554554 }
555555
556- if (collectPreDetermined)
557- return sym->test (semantics::Symbol::Flag::OmpPreDetermined);
556+ if (collectPreDetermined) {
557+ // Collect pre-determined symbols only if they are defined by the current
558+ // OpenMP evaluation. If `sym` is not defined by the current OpenMP
559+ // evaluation then it is defined by a block nested within the OpenMP
560+ // construct. This, in turn, means that the private allocation for the
561+ // symbol will be emitted as part of the nested block and there is no need
562+ // to privatize it within the OpenMP construct.
563+ return visitor.isSymbolDefineBy (sym, eval) &&
564+ sym->test (semantics::Symbol::Flag::OmpPreDetermined);
565+ }
558566
559567 return !sym->test (semantics::Symbol::Flag::OmpImplicit) &&
560568 !sym->test (semantics::Symbol::Flag::OmpPreDetermined);
0 commit comments