[flang-commits] [PATCH] D127430: [flang] Handle USE association in parse tree rewriting

Peter Klausler via Phabricator via flang-commits flang-commits at lists.llvm.org
Thu Jun 9 12:15:54 PDT 2022


klausler created this revision.
klausler added a project: Flang.
Herald added a subscriber: jdoerfert.
Herald added a project: All.
klausler requested review of this revision.

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.


https://reviews.llvm.org/D127430

Files:
  flang/lib/Semantics/rewrite-parse-tree.cpp


Index: flang/lib/Semantics/rewrite-parse-tree.cpp
===================================================================
--- flang/lib/Semantics/rewrite-parse-tree.cpp
+++ 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<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 @@
     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));
         }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D127430.435639.patch
Type: text/x-patch
Size: 1494 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20220609/cc1ba893/attachment.bin>


More information about the flang-commits mailing list