[flang-commits] [flang] [flang] Preserve capture metadata for host-associated globals (PR #233433)
Sergey Shcherbinin via flang-commits
flang-commits at lists.llvm.org
Mon Oct 26 06:56:49 PDT 2026
================
@@ -2550,12 +2550,24 @@ fir::FortranVariableFlagsAttr Fortran::lower::translateSymbolAttributes(
return fir::FortranVariableFlagsAttr::get(mlirContext, flags);
}
+/// Whether storage may be accessed indirectly through internal procedure calls.
static bool
isCapturedInInternalProcedure(Fortran::lower::AbstractConverter &converter,
const Fortran::semantics::Symbol &sym) {
const Fortran::lower::pft::FunctionLikeUnit *funit =
converter.getCurrentFunctionUnit();
- if (!funit || funit->getHostAssoc().empty())
+ if (!funit)
+ return false;
+ if (const auto *host =
+ funit->parent.getIf<Fortran::lower::pft::FunctionLikeUnit>()) {
+ // Only canonical host globals share storage with sibling procedures.
+ // Private copies can resolve to the same ultimate symbol but have separate
+ // storage and are absent from the canonical global capture set.
+ if (&sym.owner() == &host->getScope() &&
+ host->getHostAssoc().isAssociatedGlobal(sym))
----------------
SergeyShch01 wrote:
Thanks, clarified. The comment now lists the two required conditions separately: ownership by the immediate host, and exact membership in its global-capture set. The latter excludes private copies; the owner check keeps use-associated module globals outside this case.
https://github.com/llvm/llvm-project/pull/233433
More information about the flang-commits
mailing list