[flang-commits] [flang] 69a82d7 - [flang] Fix spurious "already declared" errors for interfaces

peter klausler via flang-commits flang-commits at lists.llvm.org
Thu Jun 3 15:30:57 PDT 2021


Author: peter klausler
Date: 2021-06-03T15:30:43-07:00
New Revision: 69a82d7c08be4c7d7ab6f3de7711944a00d3e4cc

URL: https://github.com/llvm/llvm-project/commit/69a82d7c08be4c7d7ab6f3de7711944a00d3e4cc
DIFF: https://github.com/llvm/llvm-project/commit/69a82d7c08be4c7d7ab6f3de7711944a00d3e4cc.diff

LOG: [flang] Fix spurious "already declared" errors for interfaces

When a subroutine or function symbol is defined in an INTERFACE
block, it's okay if a symbol of the same name appears in a
scope between the global scope and the scope of the INTERFACE.

Differential Revision: https://reviews.llvm.org/D103580

Added: 
    

Modified: 
    flang/lib/Semantics/resolve-names.cpp

Removed: 
    


################################################################################
diff  --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp
index 4d37dd841d57..5533bdccab50 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -749,8 +749,8 @@ class SubprogramVisitor : public virtual ScopeHandler, public InterfaceVisitor {
   // Edits an existing symbol created for earlier calls to a subprogram or ENTRY
   // so that it can be replaced by a later definition.
   bool HandlePreviousCalls(const parser::Name &, Symbol &, Symbol::Flag);
-  // Create a subprogram symbol in the current scope and push a new scope.
   void CheckExtantProc(const parser::Name &, Symbol::Flag);
+  // Create a subprogram symbol in the current scope and push a new scope.
   Symbol &PushSubprogramScope(const parser::Name &, Symbol::Flag);
   Symbol *GetSpecificFromGeneric(const parser::Name &);
   SubprogramDetails &PostSubprogramStmt(const parser::Name &);
@@ -3206,7 +3206,11 @@ bool SubprogramVisitor::HandlePreviousCalls(
 void SubprogramVisitor::CheckExtantProc(
     const parser::Name &name, Symbol::Flag subpFlag) {
   if (auto *prev{FindSymbol(name)}) {
-    if (!IsDummy(*prev) && !HandlePreviousCalls(name, *prev, subpFlag)) {
+    if (IsDummy(*prev)) {
+    } else if (inInterfaceBlock() && currScope() != prev->owner()) {
+      // Procedures in an INTERFACE block do not resolve to symbols
+      // in scopes between the global scope and the current scope.
+    } else if (!HandlePreviousCalls(name, *prev, subpFlag)) {
       SayAlreadyDeclared(name, *prev);
     }
   }


        


More information about the flang-commits mailing list