[flang-commits] [flang] aee7056 - [flang] Silence bogus error on use after IMPORT

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Wed Feb 2 11:16:08 PST 2022


Author: Peter Klausler
Date: 2022-02-02T11:15:58-08:00
New Revision: aee705661fe8c2ecbf0e1766ee93dbad286a6b8c

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

LOG: [flang] Silence bogus error on use after IMPORT

When a scope uses an explicit IMPORT statement to import a
symbol from the scope's host, it should not emit a bogus error
message later if that symbol is used in a specification construct.
The code that checks for imports being hidden by local declarations
was not allowing for the presence of host association (or USE)
indirection symbols in the local scope.  Fix by using GetUltimate()
before checking for the hidden symbol.

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

Added: 
    

Modified: 
    flang/lib/Semantics/resolve-names.cpp
    flang/test/Semantics/resolve29.f90

Removed: 
    


################################################################################
diff  --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp
index b2613453e353d..a77d3c83cb2c7 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -6769,9 +6769,12 @@ void ResolveNamesVisitor::CheckImports() {
 void ResolveNamesVisitor::CheckImport(
     const SourceName &location, const SourceName &name) {
   if (auto *symbol{FindInScope(name)}) {
-    Say(location, "'%s' from host is not accessible"_err_en_US, name)
-        .Attach(symbol->name(), "'%s' is hidden by this entity"_en_US,
-            symbol->name());
+    const Symbol &ultimate{symbol->GetUltimate()};
+    if (&ultimate.owner() == &currScope()) {
+      Say(location, "'%s' from host is not accessible"_err_en_US, name)
+          .Attach(symbol->name(), "'%s' is hidden by this entity"_en_US,
+              symbol->name());
+    }
   }
 }
 

diff  --git a/flang/test/Semantics/resolve29.f90 b/flang/test/Semantics/resolve29.f90
index 9e97569117ef8..ea4642c1b3ddc 100644
--- a/flang/test/Semantics/resolve29.f90
+++ b/flang/test/Semantics/resolve29.f90
@@ -1,5 +1,5 @@
 ! RUN: %python %S/test_errors.py %s %flang_fc1
-module m
+module m1
   type t1
   end type
   type t3
@@ -42,3 +42,15 @@ subroutine s7()
     call s5()
   end
 end module
+module m2
+  integer, parameter :: ck = kind('a')
+end module
+program main
+  use m2
+  interface
+    subroutine s0(x)
+      import :: ck
+      character(kind=ck) :: x ! no error
+    end subroutine
+  end interface
+end program


        


More information about the flang-commits mailing list