[flang-commits] [flang] fa5e448 - [flang] Don't use-associate intrinsics

Tim Keith via flang-commits flang-commits at lists.llvm.org
Wed Jul 15 15:08:25 PDT 2020


Author: Tim Keith
Date: 2020-07-15T15:08:08-07:00
New Revision: fa5e4482e01f7eceae52529edb75e754b601e8d0

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

LOG: [flang] Don't use-associate intrinsics

When an intrinsic is referenced in a module scope, a symbol for it is
added. When that module is USEd, the intrinsic should not be included.
Otherwise we can get ambiguous reference errors with the same intrinsic
coming from two difference modules.

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

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp
index f0556ce7e930..73d111ca3c09 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -2310,6 +2310,7 @@ void ModuleVisitor::Post(const parser::UseStmt &x) {
     }
     for (const auto &[name, symbol] : *useModuleScope_) {
       if (symbol->attrs().test(Attr::PUBLIC) &&
+          !symbol->attrs().test(Attr::INTRINSIC) &&
           !symbol->detailsIf<MiscDetails>()) {
         if (useNames.count(name) == 0) {
           auto *localSymbol{FindInScope(currScope(), name)};

diff  --git a/flang/test/Semantics/modfile30.f90 b/flang/test/Semantics/modfile30.f90
index 01c60d5a3990..dba950c2737a 100644
--- a/flang/test/Semantics/modfile30.f90
+++ b/flang/test/Semantics/modfile30.f90
@@ -42,7 +42,6 @@ module m2
 ! type(t),parameter::a=t()
 !end
 
-! Don't write out intrinsics
 module m3a
   integer, parameter :: i4 = selected_int_kind(9)
 end
@@ -60,7 +59,6 @@ module m3b
 !Expect: m3b.mod
 !module m3b
 ! use m3a,only:i4
-! use m3a,only:selected_int_kind
 ! integer(4)::j
 !end
 
@@ -82,7 +80,6 @@ module m4b
 !Expect: m4b.mod
 !module m4b
 ! use m4a,only:a
-! use m4a,only:achar
 ! character(1_4,1),parameter::b="\001"
 !end
 

diff  --git a/flang/test/Semantics/resolve14.f90 b/flang/test/Semantics/resolve14.f90
index 826e0da1c758..44ece0b18644 100644
--- a/flang/test/Semantics/resolve14.f90
+++ b/flang/test/Semantics/resolve14.f90
@@ -3,20 +3,30 @@ module m1
   integer :: x
   integer :: y
   integer :: z
+  integer, parameter :: k1 = selected_int_kind(9)
 end
 module m2
   real :: y
   real :: z
   real :: w
+  integer, parameter :: k2 = selected_int_kind(9)
 end
 
-use m1, xx => x, y => z
-use m2
-volatile w
-!ERROR: Cannot change CONTIGUOUS attribute on use-associated 'w'
-contiguous w
-!ERROR: 'z' is use-associated from module 'm2' and cannot be re-declared
-integer z
-!ERROR: Reference to 'y' is ambiguous
-y = 1
+program p1
+  use m1
+  use m2
+  ! check that selected_int_kind is not use-associated
+  integer, parameter :: k = selected_int_kind(9)
+end
+
+program p2
+  use m1, xx => x, y => z
+  use m2
+  volatile w
+  !ERROR: Cannot change CONTIGUOUS attribute on use-associated 'w'
+  contiguous w
+  !ERROR: 'z' is use-associated from module 'm2' and cannot be re-declared
+  integer z
+  !ERROR: Reference to 'y' is ambiguous
+  y = 1
 end


        


More information about the flang-commits mailing list