From a0875cd9636970774091e31395df2b56893e191a Mon Sep 17 00:00:00 2001 From: cdchen-ca Date: Mon, 12 Feb 2024 17:12:39 -0500 Subject: [PATCH 1/2] [Flang] Revise the fix in PR #81807 to get specific procedure from a potential generic name. --- flang/include/flang/Semantics/symbol.h | 13 +++++++++++++ flang/lib/Semantics/resolve-names.cpp | 6 ++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/flang/include/flang/Semantics/symbol.h b/flang/include/flang/Semantics/symbol.h index 4535a92ce3dd8..0577cba9587d5 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()) + return this; + if (const auto *details{detailsIf()}) + return details->symbol().GetUltimateGeneric(); + if (const auto *details{detailsIf()}) + return details->symbol().GetUltimateGeneric(); + return nullptr; +} + inline DeclTypeSpec *Symbol::GetType() { return const_cast( const_cast(this)->GetType()); diff --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp index 36deab969456d..0e21f3dabb6a0 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(x.t)}; const Symbol *procInterface{nullptr}; if (interfaceName_) { - procInterface = interfaceName_->symbol->has() - ? interfaceName_->symbol->get().specific() + const Symbol *ultimateGeneric{interfaceName_->symbol->GetUltimateGeneric()}; + procInterface = ultimateGeneric + ? ultimateGeneric->get().specific() : interfaceName_->symbol; } auto attrs{HandleSaveName(name.source, GetAttrs())}; From 37073c3d86a170a7f5bf3cb6f481f1a781b34953 Mon Sep 17 00:00:00 2001 From: cdchen-ca Date: Tue, 13 Feb 2024 12:17:08 -0500 Subject: [PATCH 2/2] [Flang] Revert the fix of PR #80738 and re-implement it in a different way by adding a GenericDetails in GetTypeImpl. --- flang/include/flang/Semantics/symbol.h | 17 ++++------------- flang/lib/Semantics/resolve-names.cpp | 6 +----- 2 files changed, 5 insertions(+), 18 deletions(-) diff --git a/flang/include/flang/Semantics/symbol.h b/flang/include/flang/Semantics/symbol.h index 0577cba9587d5..595f09b3c5ec8 100644 --- a/flang/include/flang/Semantics/symbol.h +++ b/flang/include/flang/Semantics/symbol.h @@ -786,9 +786,6 @@ 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 &); @@ -988,16 +985,6 @@ inline const Symbol &Symbol::GetUltimate() const { } } -inline const Symbol *Symbol::GetUltimateGeneric() const { - if (this->has()) - return this; - if (const auto *details{detailsIf()}) - return details->symbol().GetUltimateGeneric(); - if (const auto *details{detailsIf()}) - return details->symbol().GetUltimateGeneric(); - return nullptr; -} - inline DeclTypeSpec *Symbol::GetType() { return const_cast( const_cast(this)->GetType()); @@ -1027,6 +1014,10 @@ inline const DeclTypeSpec *Symbol::GetTypeImpl(int depth) const { [&](const HostAssocDetails &x) { return x.symbol().GetTypeImpl(depth); }, + [&](const GenericDetails &x) { + const Symbol *symbol{x.specific()}; + return symbol ? symbol->GetTypeImpl(depth) : nullptr; + }, [](const auto &) -> const DeclTypeSpec * { return nullptr; }, }, details_); diff --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp index 0e21f3dabb6a0..6914f95837f67 100644 --- a/flang/lib/Semantics/resolve-names.cpp +++ b/flang/lib/Semantics/resolve-names.cpp @@ -5644,15 +5644,11 @@ void DeclarationVisitor::Post(const parser::ProcInterface &x) { NoteInterfaceName(*name); } } - void DeclarationVisitor::Post(const parser::ProcDecl &x) { const auto &name{std::get(x.t)}; const Symbol *procInterface{nullptr}; if (interfaceName_) { - const Symbol *ultimateGeneric{interfaceName_->symbol->GetUltimateGeneric()}; - procInterface = ultimateGeneric - ? ultimateGeneric->get().specific() - : interfaceName_->symbol; + procInterface = interfaceName_->symbol; } auto attrs{HandleSaveName(name.source, GetAttrs())}; DerivedTypeDetails *dtDetails{nullptr};