[flang-commits] [flang] cd2a8df - [flang] Don't prematurely resolve subprogram names

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Tue May 24 13:35:12 PDT 2022


Author: Peter Klausler
Date: 2022-05-24T13:34:58-07:00
New Revision: cd2a8df8916505de9df68b9a6c1700f71e5ebf44

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

LOG: [flang] Don't prematurely resolve subprogram names

Name resolution for subprograms checks whether the name is already
present in the enclosing scope as a generic interface, so that the
case of a generic with the same name as one of its specifics can be
handled.  The particular means by which the enclosing scope is searched
for the name would resolve the name (bind a symbol to it) as a side
effect.  This turns out to be the wrong thing to do when the subprogram
is going to have its symbol created in another scope to cope with its
BIND(C,NAME="name") name, and its Fortran name is already present in the
enclosing scope for a subprogram of the same name but without
BIND(C,NAME="name").

A very long explanation for a one-line fix, sorry.  In short, change
the code to look up the name but not resolve it at that point.

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

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 cbb657040783..d7eef39eb09a 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -3706,7 +3706,8 @@ void SubprogramVisitor::PushBlockDataScope(const parser::Name &name) {
 
 // If name is a generic, return specific subprogram with the same name.
 Symbol *SubprogramVisitor::GetSpecificFromGeneric(const parser::Name &name) {
-  if (auto *symbol{FindSymbol(name)}) {
+  // Search for the name but don't resolve it
+  if (auto *symbol{currScope().FindSymbol(name.source)}) {
     if (auto *details{symbol->detailsIf<GenericDetails>()}) {
       // found generic, want subprogram
       auto *specific{details->specific()};


        


More information about the flang-commits mailing list