[flang-commits] [flang] bf8f9b3 - [flang] Fix regression from generic fix

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Fri Apr 22 12:26:57 PDT 2022


Author: Peter Klausler
Date: 2022-04-22T12:26:44-07:00
New Revision: bf8f9b35c10a2e408116bee8b9c34066b3a2bb49

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

LOG: [flang] Fix regression from generic fix

A recent change that corrected the name resolution of a generic interface
when the same name was visible in scope incorrectly prevented a local
generic from shadowing an outer name that is not a generic, subprogram,
or derived type -- e.g., a simple variable -- leading to an inappropriate
error message.

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

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 35a8c353fcb2f..0b0078fa343fd 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -6962,16 +6962,18 @@ void ResolveNamesVisitor::CreateGeneric(const parser::GenericSpec &x) {
       info.Resolve(existing);
       return;
     }
-    if (ultimate.has<SubprogramDetails>() ||
-        ultimate.has<SubprogramNameDetails>()) {
-      genericDetails.set_specific(ultimate);
-    } else if (ultimate.has<DerivedTypeDetails>()) {
-      genericDetails.set_derivedType(ultimate);
-    } else {
-      SayAlreadyDeclared(symbolName, *existing);
-      return;
+    if (&existing->owner() == &currScope()) {
+      if (ultimate.has<SubprogramDetails>() ||
+          ultimate.has<SubprogramNameDetails>()) {
+        genericDetails.set_specific(ultimate);
+      } else if (ultimate.has<DerivedTypeDetails>()) {
+        genericDetails.set_derivedType(ultimate);
+      } else {
+        SayAlreadyDeclared(symbolName, *existing);
+        return;
+      }
+      EraseSymbol(*existing);
     }
-    EraseSymbol(*existing);
   }
   info.Resolve(&MakeSymbol(symbolName, Attrs{}, std::move(genericDetails)));
 }


        


More information about the flang-commits mailing list