[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:11 PDT 2025


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

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.

>From 732d3a9f6bbaf5dd3a0e36c715ef407e2808ddea Mon Sep 17 00:00:00 2001
From: agozillon <Andrew.Gozillon at amd.com>
Date: Thu, 4 Sep 2025 22:58:34 -0500
Subject: [PATCH] [Flang][OpenMP] Fix default firstprivatization
 miscategorization of mod file symbols

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 yse symbol from a mod
file is picked up.

The fix to this is to chase up the appropriate symbol to access the correct details.
---
 flang/lib/Semantics/resolve-directives.cpp | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

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) {



More information about the flang-commits mailing list