[flang-commits] [flang] Skip contiguous check when ignore_tkr(c) is used (PR #138762)

Zhen Wang via flang-commits flang-commits at lists.llvm.org
Wed May 7 09:16:08 PDT 2025


https://github.com/wangzpgi updated https://github.com/llvm/llvm-project/pull/138762

>From 61c452e7384b762e33fb9636c9dfd7f4cbad026e Mon Sep 17 00:00:00 2001
From: Zhen Wang <zhenw at nvidia.com>
Date: Tue, 6 May 2025 13:58:54 -0700
Subject: [PATCH 1/2] Do not emit warnings/errors for contiguous check when
 ignore_tkr(c) is used for all attributes

---
 flang/lib/Semantics/check-call.cpp |  3 ++-
 flang/test/Semantics/cuf20.cuf     | 42 ++++++++++++++++++++++++++++++
 2 files changed, 44 insertions(+), 1 deletion(-)
 create mode 100644 flang/test/Semantics/cuf20.cuf

diff --git a/flang/lib/Semantics/check-call.cpp b/flang/lib/Semantics/check-call.cpp
index dfaa0e028d698..58271d7ca2e87 100644
--- a/flang/lib/Semantics/check-call.cpp
+++ b/flang/lib/Semantics/check-call.cpp
@@ -1016,7 +1016,8 @@ static void CheckExplicitDataArg(const characteristics::DummyDataObject &dummy,
       }
     }
     if (dummyDataAttr == common::CUDADataAttr::Device &&
-        (dummyIsAssumedShape || dummyIsAssumedRank)) {
+        (dummyIsAssumedShape || dummyIsAssumedRank)
+        !dummy.ignoreTKR.test(common::IgnoreTKR::Contiguous)) {
       if (auto contig{evaluate::IsContiguous(actual, foldingContext,
               /*namedConstantSectionsAreContiguous=*/true,
               /*firstDimensionStride1=*/true)}) {
diff --git a/flang/test/Semantics/cuf20.cuf b/flang/test/Semantics/cuf20.cuf
new file mode 100644
index 0000000000000..222ff2a1b7c6d
--- /dev/null
+++ b/flang/test/Semantics/cuf20.cuf
@@ -0,0 +1,42 @@
+! RUN: %python %S/test_errors.py %s %flang_fc1
+
+! Test case 1: Device arrays with ignore_tkr(c)
+subroutine test_device_arrays()
+  interface bar
+    subroutine bar1(a)
+!dir$ ignore_tkr(c) a
+      real :: a(..)
+!@cuf attributes(device) :: a
+    end subroutine
+  end interface
+
+  integer :: n = 10, k = 2
+  real, device :: a(10), b(10), c(10)
+  
+  call bar(a(1:n))     ! Should not warn about contiguity
+  call bar(b(1:n:k))   ! Should not warn about contiguity
+  call bar(c(1:n:2))   ! Should not warn about contiguity
+end subroutine
+
+! Test case 2: Managed arrays with ignore_tkr(c)
+subroutine test_managed_arrays()
+  interface bar
+    subroutine bar1(a)
+!dir$ ignore_tkr(c) a
+      real :: a(..)
+!@cuf attributes(device) :: a
+    end subroutine
+  end interface
+
+  integer :: n = 10, k = 2
+  real, managed :: a(10), b(10), c(10)
+  
+  call bar(a(1:n))     ! Should not warn about contiguity
+  call bar(b(1:n:k))   ! Should not warn about contiguity
+  call bar(c(1:n:2))   ! Should not warn about contiguity
+end subroutine
+
+program main
+  call test_device_arrays()
+  call test_managed_arrays()
+end program 
\ No newline at end of file

>From 33ad28f8ea46f8fc2f5dce2fc7d333be35a05291 Mon Sep 17 00:00:00 2001
From: Zhen Wang <zhenw at nvidia.com>
Date: Tue, 6 May 2025 14:10:41 -0700
Subject: [PATCH 2/2] fix missing &&

---
 flang/lib/Semantics/check-call.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/flang/lib/Semantics/check-call.cpp b/flang/lib/Semantics/check-call.cpp
index 58271d7ca2e87..11928860fea5f 100644
--- a/flang/lib/Semantics/check-call.cpp
+++ b/flang/lib/Semantics/check-call.cpp
@@ -1016,7 +1016,7 @@ static void CheckExplicitDataArg(const characteristics::DummyDataObject &dummy,
       }
     }
     if (dummyDataAttr == common::CUDADataAttr::Device &&
-        (dummyIsAssumedShape || dummyIsAssumedRank)
+        (dummyIsAssumedShape || dummyIsAssumedRank) &&
         !dummy.ignoreTKR.test(common::IgnoreTKR::Contiguous)) {
       if (auto contig{evaluate::IsContiguous(actual, foldingContext,
               /*namedConstantSectionsAreContiguous=*/true,



More information about the flang-commits mailing list