[flang-commits] [flang] [Flang][OpenMP] Fix default firstprivatization miscategorization of mod file symbols (PR #157009)

via flang-commits flang-commits at lists.llvm.org
Thu Sep 4 21:07:43 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-flang-openmp

Author: None (agozillon)

<details>
<summary>Changes</summary>

In at least certain cases, notably when equivalence is used (at least for the example this showed up as a problem in) we currently miscategorize symbols as firstprivate when they may not be, as they can throw a false positive when a use symbol from a mod file is picked up.

The fix to this is to chase up the appropriate symbol to access the correct details.

---
Full diff: https://github.com/llvm/llvm-project/pull/157009.diff


1 Files Affected:

- (modified) flang/lib/Semantics/resolve-directives.cpp (+9-8) 


``````````diff
diff --git a/flang/lib/Semantics/resolve-directives.cpp b/flang/lib/Semantics/resolve-directives.cpp
index a08e764ecf936..2eca768766887 100644
--- a/flang/lib/Semantics/resolve-directives.cpp
+++ b/flang/lib/Semantics/resolve-directives.cpp
@@ -2517,14 +2517,15 @@ static bool IsTargetCaptureImplicitlyFirstprivatizeable(const Symbol &symbol,
     return false;
   };
 
-  if (checkSymbol(symbol)) {
-    const auto *hostAssoc{symbol.detailsIf<HostAssocDetails>()};
-    if (hostAssoc) {
-      return checkSymbol(hostAssoc->symbol());
-    }
-    return true;
-  }
-  return false;
+  return common::visit(
+      common::visitors{
+          [&](const UseDetails &x) -> bool { return checkSymbol(x.symbol()); },
+          [&](const HostAssocDetails &x) -> bool {
+            return checkSymbol(x.symbol());
+          },
+          [&](const auto &) -> bool { return checkSymbol(symbol); },
+      },
+      symbol.details());
 }
 
 void OmpAttributeVisitor::CreateImplicitSymbols(const Symbol *symbol) {

``````````

</details>


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


More information about the flang-commits mailing list