diff --git a/flang/lib/Semantics/rewrite-parse-tree.cpp b/flang/lib/Semantics/rewrite-parse-tree.cpp --- a/flang/lib/Semantics/rewrite-parse-tree.cpp +++ b/flang/lib/Semantics/rewrite-parse-tree.cpp @@ -79,6 +79,19 @@ } } +static bool ReturnsDataPointer(const Symbol &symbol) { + if (const Symbol * funcRes{FindFunctionResult(symbol)}) { + return IsPointer(*funcRes) && !IsProcedure(*funcRes); + } else if (const auto *generic{symbol.detailsIf()}) { + for (auto ref : generic->specificProcs()) { + if (ReturnsDataPointer(*ref)) { + return true; + } + } + } + return false; +} + // Find mis-parsed statement functions and move to stmtFuncsToConvert_ list. void RewriteMutator::Post(parser::SpecificationPart &x) { auto &list{std::get>(x.t)}; @@ -87,9 +100,9 @@ if (auto *stmt{std::get_if(&it->u)}) { if (const Symbol * symbol{std::get(stmt->statement.value().t).symbol}) { - const Symbol *funcRes{FindFunctionResult(*symbol)}; - isAssignment = symbol->has() || - (funcRes && IsPointer(*funcRes) && !IsProcedure(*funcRes)); + const Symbol &ultimate{symbol->GetUltimate()}; + isAssignment = + ultimate.has() || ReturnsDataPointer(ultimate); if (isAssignment) { stmtFuncsToConvert_.emplace_back(std::move(*stmt)); }