Index: flang/include/flang/Lower/AbstractConverter.h =================================================================== --- flang/include/flang/Lower/AbstractConverter.h +++ flang/include/flang/Lower/AbstractConverter.h @@ -103,13 +103,15 @@ virtual void copyHostAssociateVar(const Fortran::semantics::Symbol &sym) = 0; - /// Collect the set of ultimate symbols of symbols with \p flag in \p eval - /// region if \p isUltimateSymbol is true. Otherwise, collect the set of - /// symbols with \p flag. + /// Collect the set of symbols with \p flag in \p eval region. Also collect + /// the host symbols with \p flag when the symbols are host associated if \p + /// checkHostAssocSymbols is true, in which case note that the host symbols + /// may not be in \p eval region. virtual void collectSymbolSet( pft::Evaluation &eval, llvm::SetVector &symbolSet, - Fortran::semantics::Symbol::Flag flag, bool isUltimateSymbol = true) = 0; + Fortran::semantics::Symbol::Flag flag, + bool checkHostAssocSymbols = true) = 0; //===--------------------------------------------------------------------===// // Expressions Index: flang/lib/Lower/Bridge.cpp =================================================================== --- flang/lib/Lower/Bridge.cpp +++ flang/lib/Lower/Bridge.cpp @@ -535,12 +535,19 @@ Fortran::lower::pft::Evaluation &eval, llvm::SetVector &symbolSet, Fortran::semantics::Symbol::Flag flag, - bool isUltimateSymbol) override final { + bool checkHostAssocSymbols) override final { auto addToList = [&](const Fortran::semantics::Symbol &sym) { - const Fortran::semantics::Symbol &symbol = - isUltimateSymbol ? sym.GetUltimate() : sym; - if (symbol.test(flag)) - symbolSet.insert(&symbol); + std::function insertSymbols = + [&](const Fortran::semantics::Symbol &oriSymbol) { + if (oriSymbol.test(flag)) + symbolSet.insert(&oriSymbol); + if (checkHostAssocSymbols) + if (const auto *details{ + oriSymbol + .detailsIf()}) + insertSymbols(details->symbol()); + }; + insertSymbols(sym); }; Fortran::lower::pft::visitAllSymbols(eval, addToList); } Index: flang/lib/Lower/OpenMP.cpp =================================================================== --- flang/lib/Lower/OpenMP.cpp +++ flang/lib/Lower/OpenMP.cpp @@ -162,7 +162,7 @@ llvm::SetVector threadprivateSyms; converter.collectSymbolSet(eval, threadprivateSyms, Fortran::semantics::Symbol::Flag::OmpThreadprivate, - /*isUltimateSymbol=*/false); + /*checkHostAssocSymbols=*/false); std::set threadprivateSymNames; // For a COMMON block, the ThreadprivateOp is generated for itself instead of