[flang-commits] [flang] [flang][OpenMP] Privatize vars referenced in statement functions (PR #103390)

Leandro Lupori via flang-commits flang-commits at lists.llvm.org
Wed Aug 21 05:53:17 PDT 2024


================
@@ -2075,13 +2084,30 @@ void OmpAttributeVisitor::Post(const parser::Name &name) {
       if (found->test(semantics::Symbol::Flag::OmpThreadprivate))
         return;
     }
-    if (!IsPrivatizable(symbol)) {
+
+    std::set<const Symbol *> stmtFunctionSymbols;
+    if (auto *stmtFunction{symbol->detailsIf<semantics::SubprogramDetails>()};
+        stmtFunction && stmtFunction->stmtFunction()) {
+      // Each non-dummy argument from a statement function must be handled too,
+      // as if it was explicitly referenced.
+      semantics::UnorderedSymbolSet symbols{
+          CollectSymbols(stmtFunction->stmtFunction().value())};
+      for (const auto &sym : symbols) {
+        if (!IsStmtFunctionDummy(sym) && IsPrivatizable(&*sym) &&
+            !IsObjectWithDSA(*sym)) {
+          stmtFunctionSymbols.insert(&*sym);
+        }
+      }
+      if (stmtFunctionSymbols.empty()) {
+        return;
+      }
+    } else if (!IsPrivatizable(symbol)) {
       return;
     }
 
     // Implicitly determined DSAs
     // OMP 5.2 5.1.1 - Variables Referenced in a Construct
-    Symbol *lastDeclSymbol = nullptr;
+    std::vector<const Symbol *> lastDeclSymbols;
----------------
luporl wrote:

Reverted to using `Symbol *lastDeclSymbol = nullptr` with the refactoring.

https://github.com/llvm/llvm-project/pull/103390


More information about the flang-commits mailing list