30
30
#include " flang/Semantics/tools.h"
31
31
#include " llvm/ADT/Sequence.h"
32
32
#include " llvm/ADT/SmallSet.h"
33
+ #include < variant>
33
34
34
35
namespace Fortran {
35
36
namespace lower {
@@ -44,6 +45,13 @@ bool DataSharingProcessor::OMPConstructSymbolVisitor::isSymbolDefineBy(
44
45
[](const auto &functionParserNode) { return false ; }});
45
46
}
46
47
48
+ bool DataSharingProcessor::OMPConstructSymbolVisitor::
49
+ isSymbolDefineByNestedDeclaration (const semantics::Symbol *symbol) const {
50
+ return symDefMap.count (symbol) &&
51
+ std::holds_alternative<const parser::DeclarationConstruct *>(
52
+ symDefMap.at (symbol));
53
+ }
54
+
47
55
static bool isConstructWithTopLevelTarget (lower::pft::Evaluation &eval) {
48
56
const auto *ompEval = eval.getIf <parser::OpenMPConstruct>();
49
57
if (ompEval) {
@@ -550,17 +558,20 @@ void DataSharingProcessor::collectSymbols(
550
558
return false ;
551
559
}
552
560
553
- return sym->test (semantics::Symbol::Flag::OmpImplicit);
554
- }
555
-
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
561
+ // Collect implicit symbols only if they are not defined by a nested
562
+ // `DeclarationConstruct`. If `sym` is not defined by the current OpenMP
559
563
// evaluation then it is defined by a block nested within the OpenMP
560
564
// construct. This, in turn, means that the private allocation for the
561
565
// symbol will be emitted as part of the nested block and there is no need
562
566
// to privatize it within the OpenMP construct.
563
- return visitor.isSymbolDefineBy (sym, eval) &&
567
+ return !visitor.isSymbolDefineByNestedDeclaration (sym) &&
568
+ sym->test (semantics::Symbol::Flag::OmpImplicit);
569
+ }
570
+
571
+ if (collectPreDetermined) {
572
+ // Similar to implicit symbols, collect pre-determined symbols only if
573
+ // they are not defined by a nested `DeclarationConstruct`
574
+ return !visitor.isSymbolDefineByNestedDeclaration (sym) &&
564
575
sym->test (semantics::Symbol::Flag::OmpPreDetermined);
565
576
}
566
577
0 commit comments