[flang-commits] [flang] [flang] Fix handling of shadowed procedure name used as interface (PR #82837)

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Fri Feb 23 14:13:08 PST 2024


https://github.com/klausler created https://github.com/llvm/llvm-project/pull/82837

Use BypassGeneric() to process the name of an interface in a procedure declaration statement, so that if it's the name of a generic with a homonymous specific procedure, that's what defines the interface.

Fixes https://github.com/llvm/llvm-project/issues/82267.

>From 257bbf6cef4338273b759d6a9d99efb0448c6c34 Mon Sep 17 00:00:00 2001
From: Peter Klausler <pklausler at nvidia.com>
Date: Fri, 23 Feb 2024 14:10:41 -0800
Subject: [PATCH] [flang] Fix handling of shadowed procedure name used as
 interface

Use BypassGeneric() to process the name of an interface in a
procedure declaration statement, so that if it's the name of
a generic with a homonymous specific procedure, that's what
defines the interface.

Fixes https://github.com/llvm/llvm-project/issues/82267.
---
 flang/lib/Semantics/resolve-names.cpp | 6 ++----
 flang/test/Semantics/bind-c03.f90     | 6 ++++++
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp
index 36deab969456d0..71af694fb95120 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -5647,10 +5647,8 @@ void DeclarationVisitor::Post(const parser::ProcInterface &x) {
 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()
-        : interfaceName_->symbol;
+  if (interfaceName_ && interfaceName_->symbol) {
+    procInterface = &BypassGeneric(*interfaceName_->symbol);
   }
   auto attrs{HandleSaveName(name.source, GetAttrs())};
   DerivedTypeDetails *dtDetails{nullptr};
diff --git a/flang/test/Semantics/bind-c03.f90 b/flang/test/Semantics/bind-c03.f90
index 03a544b1954d7c..65d52e964ca46e 100644
--- a/flang/test/Semantics/bind-c03.f90
+++ b/flang/test/Semantics/bind-c03.f90
@@ -13,7 +13,13 @@ subroutine proc2()
     end
   end interface
 
+  interface proc3
+    subroutine proc3() bind(c)
+    end
+  end interface
+
   procedure(proc1), bind(c) :: pc1 ! no error
+  procedure(proc3), bind(c) :: pc4 ! no error
 
   !ERROR: An interface name with BIND attribute must be specified if the BIND attribute is specified in a procedure declaration statement
   procedure(proc2), bind(c) :: pc2



More information about the flang-commits mailing list