[flang-commits] [flang] [Flang] Revise the fix in PR #81807 to get specific procedure from a potential generic name. (PR #81544)

via flang-commits flang-commits at lists.llvm.org
Mon Feb 12 14:16:11 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-flang-semantics

Author: Daniel Chen (DanielCChen)

<details>
<summary>Changes</summary>

This PR is to revise the fix in PR #<!-- -->81807 to handle the case that @<!-- -->psteinfeld brought up. Both test cases in PR #<!-- -->81807 now pass with this PR.

---
Full diff: https://github.com/llvm/llvm-project/pull/81544.diff


2 Files Affected:

- (modified) flang/include/flang/Semantics/symbol.h (+13) 
- (modified) flang/lib/Semantics/resolve-names.cpp (+4-2) 


``````````diff
diff --git a/flang/include/flang/Semantics/symbol.h b/flang/include/flang/Semantics/symbol.h
index 4535a92ce3dd8e..0577cba9587d55 100644
--- a/flang/include/flang/Semantics/symbol.h
+++ b/flang/include/flang/Semantics/symbol.h
@@ -786,6 +786,9 @@ class Symbol {
   inline Symbol &GetUltimate();
   inline const Symbol &GetUltimate() const;
 
+  // Get the specific procedure from a potential generic symbol.
+  inline const Symbol *GetUltimateGeneric() const;
+
   inline DeclTypeSpec *GetType();
   inline const DeclTypeSpec *GetType() const;
   void SetType(const DeclTypeSpec &);
@@ -985,6 +988,16 @@ inline const Symbol &Symbol::GetUltimate() const {
   }
 }
 
+inline const Symbol *Symbol::GetUltimateGeneric() const {
+  if (this->has<GenericDetails>())
+    return this;
+  if (const auto *details{detailsIf<UseDetails>()})
+    return details->symbol().GetUltimateGeneric();
+  if (const auto *details{detailsIf<HostAssocDetails>()})
+    return details->symbol().GetUltimateGeneric();
+  return nullptr;
+}
+
 inline DeclTypeSpec *Symbol::GetType() {
   return const_cast<DeclTypeSpec *>(
       const_cast<const Symbol *>(this)->GetType());
diff --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp
index 36deab969456d0..0e21f3dabb6a01 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -5644,12 +5644,14 @@ void DeclarationVisitor::Post(const parser::ProcInterface &x) {
     NoteInterfaceName(*name);
   }
 }
+
 void DeclarationVisitor::Post(const parser::ProcDecl &x) {
   const auto &name{std::get<parser::Name>(x.t)};
   const Symbol *procInterface{nullptr};
   if (interfaceName_) {
-    procInterface = interfaceName_->symbol->has<GenericDetails>()
-        ? interfaceName_->symbol->get<GenericDetails>().specific()
+    const Symbol *ultimateGeneric{interfaceName_->symbol->GetUltimateGeneric()};
+    procInterface = ultimateGeneric
+        ? ultimateGeneric->get<GenericDetails>().specific()
         : interfaceName_->symbol;
   }
   auto attrs{HandleSaveName(name.source, GetAttrs())};

``````````

</details>


https://github.com/llvm/llvm-project/pull/81544


More information about the flang-commits mailing list