[flang-commits] [flang] e5ccfbb - [flang] Respect !DIR$ IGNORE_TKR in generic matching

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Thu May 18 11:26:27 PDT 2023


Author: Peter Klausler
Date: 2023-05-18T11:26:16-07:00
New Revision: e5ccfbbfdeccbb030423978824de648956b270c8

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

LOG: [flang] Respect !DIR$ IGNORE_TKR in generic matching

Generic matching needs to relax argument compatibility checks when
dummy arguments have !DIR$ IGNORE_TKR directives.

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

Added: 
    flang/test/Semantics/ignore_tkr02.f90

Modified: 
    flang/lib/Evaluate/characteristics.cpp
    flang/lib/Semantics/expression.cpp
    flang/lib/Semantics/symbol.cpp

Removed: 
    


################################################################################
diff  --git a/flang/lib/Evaluate/characteristics.cpp b/flang/lib/Evaluate/characteristics.cpp
index 62b1573010f95..6b961ac9fae56 100644
--- a/flang/lib/Evaluate/characteristics.cpp
+++ b/flang/lib/Evaluate/characteristics.cpp
@@ -400,6 +400,9 @@ llvm::raw_ostream &DummyDataObject::Dump(llvm::raw_ostream &o) const {
       sep = ',';
     }
   }
+  if (!ignoreTKR.empty()) {
+    ignoreTKR.Dump(o << ' ', common::EnumToString);
+  }
   return o;
 }
 

diff  --git a/flang/lib/Semantics/expression.cpp b/flang/lib/Semantics/expression.cpp
index afd92674ed293..9e95411a833e3 100644
--- a/flang/lib/Semantics/expression.cpp
+++ b/flang/lib/Semantics/expression.cpp
@@ -2307,10 +2307,11 @@ static bool CheckCompatibleArgument(bool isElemental,
               return true;
             } else if (!isElemental && actual.Rank() != x.type.Rank() &&
                 !x.type.attrs().test(
-                    characteristics::TypeAndShape::Attr::AssumedRank)) {
+                    characteristics::TypeAndShape::Attr::AssumedRank) &&
+                !x.ignoreTKR.test(common::IgnoreTKR::Rank)) {
               return false;
             } else if (auto actualType{actual.GetType()}) {
-              return x.type.type().IsTkCompatibleWith(*actualType);
+              return x.type.type().IsTkCompatibleWith(*actualType, x.ignoreTKR);
             }
             return false;
           },

diff  --git a/flang/lib/Semantics/symbol.cpp b/flang/lib/Semantics/symbol.cpp
index 83d73f2d0a7a4..d9fd0d076ef95 100644
--- a/flang/lib/Semantics/symbol.cpp
+++ b/flang/lib/Semantics/symbol.cpp
@@ -411,8 +411,7 @@ llvm::raw_ostream &operator<<(
     os << " (has unanalyzedPDTComponentInit)";
   }
   if (!x.ignoreTKR_.empty()) {
-    os << ' ';
-    x.ignoreTKR_.Dump(os, common::EnumToString);
+    x.ignoreTKR_.Dump(os << ' ', common::EnumToString);
   }
   return os;
 }

diff  --git a/flang/test/Semantics/ignore_tkr02.f90 b/flang/test/Semantics/ignore_tkr02.f90
new file mode 100644
index 0000000000000..a56b92d6613aa
--- /dev/null
+++ b/flang/test/Semantics/ignore_tkr02.f90
@@ -0,0 +1,38 @@
+! RUN: %flang_fc1 -fdebug-unparse %s 2>&1 | FileCheck %s
+program main
+  interface generic
+    subroutine sub1(j, k)
+      integer(1) j
+      integer k
+      !dir$ ignore_tkr(kr) k
+    end
+    subroutine sub2(j, k)
+      integer(2) j
+      integer k
+      !dir$ ignore_tkr(kr) k
+    end
+    subroutine sub4(j, k)
+      integer(4) j
+      integer k
+      !dir$ ignore_tkr(kr) k
+    end
+  end interface
+!CHECK: CALL sub1(1_1,int(1_1,kind=4))
+  call generic(1_1,1_1)
+!CHECK: CALL sub1(1_1,int(1_2,kind=4))
+  call generic(1_1,1_2)
+!CHECK: CALL sub1(1_1,[INTEGER(1)::1_1])
+  call generic(1_1,[1_1])
+!CHECK: CALL sub2(1_2,int(1_1,kind=4))
+  call generic(1_2,1_1)
+!CHECK: CALL sub2(1_2,int(1_2,kind=4))
+  call generic(1_2,1_2)
+!CHECK: CALL sub2(1_2,[INTEGER(1)::1_1])
+  call generic(1_2,[1_1])
+!CHECK: CALL sub4(1_4,int(1_1,kind=4))
+  call generic(1_4,1_1)
+!CHECK: CALL sub4(1_4,int(1_2,kind=4))
+  call generic(1_4,1_2)
+!CHECK: CALL sub4(1_4,[INTEGER(1)::1_1])
+  call generic(1_4,[1_1])
+end


        


More information about the flang-commits mailing list