[flang-commits] [flang] 811aafc - [flang] Don't resolve names in derived type definitions to generics

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Fri Sep 23 10:56:51 PDT 2022


Author: Peter Klausler
Date: 2022-09-23T10:56:24-07:00
New Revision: 811aafcbf57e2933982b978492f2a5367c3a9f99

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

LOG: [flang] Don't resolve names in derived type definitions to generics

There's code in name resolution that handles resolution of references
that appear in the definitions of derived types -- it checks for
existing components in the type being defined, as well as for
non-parent components in its ancestors.  Special case code prevents
resolution of a name to the symbol of a procedure binding.  This
code needs to be extended so that names of generic procedures
are similarly prevented from shadowing symbols in the scope around
the type.

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

Added: 
    flang/test/Semantics/symbol23.f90

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 dc1fffc25b58d..01f06a752a2d2 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -2254,6 +2254,7 @@ Symbol *ScopeHandler::FindSymbol(const Scope &scope, const parser::Name &name) {
   if (scope.IsDerivedType()) {
     if (Symbol * symbol{scope.FindComponent(name.source)}) {
       if (!symbol->has<ProcBindingDetails>() &&
+          !symbol->has<GenericDetails>() &&
           !symbol->test(Symbol::Flag::ParentComp)) {
         return Resolve(name, symbol);
       }

diff  --git a/flang/test/Semantics/symbol23.f90 b/flang/test/Semantics/symbol23.f90
new file mode 100644
index 0000000000000..82f7309820990
--- /dev/null
+++ b/flang/test/Semantics/symbol23.f90
@@ -0,0 +1,42 @@
+! RUN: %python %S/test_symbols.py %s %flang_fc1
+! Regression test of name resolution bug
+!DEF: /m Module
+module m
+ !DEF: /m/base ABSTRACT, PUBLIC DerivedType
+ type, abstract :: base
+ contains
+  !DEF: /m/base/foo Generic
+  !DEF: /m/base/spec DEFERRED ProcBinding
+  generic :: foo => spec
+  !DEF: /m/iface ABSTRACT, PUBLIC (Subroutine) Subprogram
+  !REF: /m/base/spec
+  procedure(iface), deferred :: spec
+ end type
+ abstract interface
+  !REF: /m/iface
+  !DEF: /m/iface/this ObjectEntity CLASS(base)
+  subroutine iface (this)
+   !REF: /m/base
+   import :: base
+   !REF: /m/base
+   !REF: /m/iface/this
+   class(base) :: this
+  end subroutine
+ end interface
+ !REF: /m/base
+ !DEF: /m/ext PUBLIC DerivedType
+ type, extends(base) :: ext
+ contains
+  !DEF: /m/ext/spec ProcBinding
+  !DEF: /m/foo PUBLIC (Subroutine) Subprogram
+  procedure :: spec => foo
+ end type
+contains
+ !REF: /m/foo
+ !DEF: /m/foo/this ObjectEntity CLASS(ext)
+ subroutine foo (this)
+  !REF: /m/ext
+  !REF: /m/foo/this
+  class(ext) :: this
+ end subroutine
+end module


        


More information about the flang-commits mailing list