[flang-commits] [flang] f472c09 - [flang] Handle USE association in parse tree rewriting
Peter Klausler via flang-commits
flang-commits at lists.llvm.org
Mon Jun 13 16:26:40 PDT 2022
Author: Peter Klausler
Date: 2022-06-13T16:20:51-07:00
New Revision: f472c099be07593be2a1ea9f5c61793d348a4f52
URL: https://github.com/llvm/llvm-project/commit/f472c099be07593be2a1ea9f5c61793d348a4f52
DIFF: https://github.com/llvm/llvm-project/commit/f472c099be07593be2a1ea9f5c61793d348a4f52.diff
LOG: [flang] Handle USE association in parse tree rewriting
f18 was treating "f() = 1" as a statement function definition
if it could be viewed as being in the specification part and
"f" was a USE-associated function returning a data pointer.
(The non-USE-associated case is fine.) Fix to allow for "f"
to be USE associated.
Differential Revision: https://reviews.llvm.org/D127430
Added:
Modified:
flang/lib/Semantics/rewrite-parse-tree.cpp
Removed:
################################################################################
diff --git a/flang/lib/Semantics/rewrite-parse-tree.cpp b/flang/lib/Semantics/rewrite-parse-tree.cpp
index 1e0b9105dda8..8fb7673bbfac 100644
--- a/flang/lib/Semantics/rewrite-parse-tree.cpp
+++ b/flang/lib/Semantics/rewrite-parse-tree.cpp
@@ -79,6 +79,19 @@ void RewriteMutator::Post(parser::Name &name) {
}
}
+static bool ReturnsDataPointer(const Symbol &symbol) {
+ if (const Symbol * funcRes{FindFunctionResult(symbol)}) {
+ return IsPointer(*funcRes) && !IsProcedure(*funcRes);
+ } else if (const auto *generic{symbol.detailsIf<GenericDetails>()}) {
+ 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<std::list<parser::DeclarationConstruct>>(x.t)};
@@ -87,9 +100,9 @@ void RewriteMutator::Post(parser::SpecificationPart &x) {
if (auto *stmt{std::get_if<stmtFuncType>(&it->u)}) {
if (const Symbol *
symbol{std::get<parser::Name>(stmt->statement.value().t).symbol}) {
- const Symbol *funcRes{FindFunctionResult(*symbol)};
- isAssignment = symbol->has<ObjectEntityDetails>() ||
- (funcRes && IsPointer(*funcRes) && !IsProcedure(*funcRes));
+ const Symbol &ultimate{symbol->GetUltimate()};
+ isAssignment =
+ ultimate.has<ObjectEntityDetails>() || ReturnsDataPointer(ultimate);
if (isAssignment) {
stmtFuncsToConvert_.emplace_back(std::move(*stmt));
}
More information about the flang-commits
mailing list