@@ -2217,6 +2217,20 @@ static bool IsPrivatizable(const Symbol *sym) {
22172217 misc->kind () != MiscDetails::Kind::ConstructName));
22182218}
22192219
2220+ static bool IsSymbolStaticStorageDuration (const Symbol &symbol) {
2221+ LLVM_DEBUG (llvm::dbgs () << " IsSymbolStaticStorageDuration(" << symbol.name ()
2222+ << " ):\n " );
2223+ auto ultSym = symbol.GetUltimate ();
2224+ // Module-scope variable
2225+ return (ultSym.owner ().kind () == Scope::Kind::Module) ||
2226+ // Data statement variable
2227+ (ultSym.flags ().test (Symbol::Flag::InDataStmt)) ||
2228+ // Save attribute variable
2229+ (ultSym.attrs ().test (Attr::SAVE)) ||
2230+ // Referenced in a common block
2231+ (ultSym.flags ().test (Symbol::Flag::InCommonBlock));
2232+ }
2233+
22202234void OmpAttributeVisitor::CreateImplicitSymbols (const Symbol *symbol) {
22212235 if (!IsPrivatizable (symbol)) {
22222236 return ;
@@ -2310,8 +2324,7 @@ void OmpAttributeVisitor::CreateImplicitSymbols(const Symbol *symbol) {
23102324 bool targetDir = llvm::omp::allTargetSet.test (dirContext.directive );
23112325 bool parallelDir = llvm::omp::allParallelSet.test (dirContext.directive );
23122326 bool teamsDir = llvm::omp::allTeamsSet.test (dirContext.directive );
2313- bool isStaticStorageDuration =
2314- symbol->flags ().test (Symbol::Flag::InDataStmt);
2327+ bool isStaticStorageDuration = IsSymbolStaticStorageDuration (*symbol);
23152328
23162329 if (dsa.any ()) {
23172330 if (parallelDir || taskGenDir || teamsDir) {
@@ -2369,21 +2382,16 @@ void OmpAttributeVisitor::CreateImplicitSymbols(const Symbol *symbol) {
23692382 dsa = prevDSA;
23702383 } else if (taskGenDir) {
23712384 // TODO 5) dummy arg in orphaned taskgen construct -> firstprivate
2372- if (prevDSA.test (Symbol::Flag::OmpShared)) {
2385+ if (prevDSA.test (Symbol::Flag::OmpShared) || isStaticStorageDuration ) {
23732386 // 6) shared in enclosing context -> shared
23742387 dsa = {Symbol::Flag::OmpShared};
23752388 makeSymbol (dsa);
23762389 PRINT_IMPLICIT_RULE (" 6) taskgen: shared" );
2377- } else if (isStaticStorageDuration) {
2378- // 7) variables with static storage duration are predetermined as shared
2379- dsa = {Symbol::Flag::OmpShared};
2380- makeSymbol (dsa);
2381- PRINT_IMPLICIT_RULE (" 7) taskgen: shared (static storage duration)" );
23822390 } else {
2383- // 8 ) firstprivate
2391+ // 7 ) firstprivate
23842392 dsa = {Symbol::Flag::OmpFirstPrivate};
23852393 makeSymbol (dsa)->set (Symbol::Flag::OmpImplicit);
2386- PRINT_IMPLICIT_RULE (" 8 ) taskgen: firstprivate" );
2394+ PRINT_IMPLICIT_RULE (" 7 ) taskgen: firstprivate" );
23872395 }
23882396 }
23892397 prevDSA = dsa;
0 commit comments