[flang-commits] [flang] [flang][cuda] Fix ignore_tkr(m) to also cover CUDA unified attribute (PR #192131)

Zhen Wang via flang-commits flang-commits at lists.llvm.org
Tue Apr 14 13:46:28 PDT 2026


https://github.com/wangzpgi created https://github.com/llvm/llvm-project/pull/192131

The ignore_tkr(m) directive suppresses CUDA managed attribute checking on dummy arguments, but it was not covering the unified attribute. This caused a spurious error when passing a plain host array to a unified dummy with ignore_tkr(m):
```
error: dummy argument 'x=' has ATTRIBUTES(UNIFIED) but its associated actual argument has no CUDA data attribute
```
Extend the IgnoreTKR::Managed check in AreCompatibleCUDADataAttrs to accept Unified in addition to Managed and no-attribute.

>From 2d54228b5ddc18cc7bbaef4fe1393eaef7335586 Mon Sep 17 00:00:00 2001
From: Zhen Wang <zhenw at nvidia.com>
Date: Tue, 14 Apr 2026 13:44:06 -0700
Subject: [PATCH] Fix ignore_tkr(m) to also cover CUDA unified attribute

---
 flang/include/flang/Support/Fortran.h |  2 +-
 flang/lib/Support/Fortran.cpp         |  4 ++--
 flang/test/Semantics/cuf10.cuf        | 13 ++++++++++++-
 3 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/flang/include/flang/Support/Fortran.h b/flang/include/flang/Support/Fortran.h
index dc6f7ec900e74..9f8d7295f586e 100644
--- a/flang/include/flang/Support/Fortran.h
+++ b/flang/include/flang/Support/Fortran.h
@@ -88,7 +88,7 @@ ENUM_CLASS(IgnoreTKR,
     Kind, // K - don't check kind
     Rank, // R - don't check ranks
     Device, // D - don't check host/device residence
-    Managed, // M - don't check managed storage
+    Managed, // M - don't check managed/unified storage
     Contiguous, // C - don't check for storage sequence association with a
                 // potentially non-contiguous object
     Pointer) // P - ignore pointer and allocatable matching
diff --git a/flang/lib/Support/Fortran.cpp b/flang/lib/Support/Fortran.cpp
index 05d6e0e709e91..83a68b4cfa94c 100644
--- a/flang/lib/Support/Fortran.cpp
+++ b/flang/lib/Support/Fortran.cpp
@@ -132,8 +132,8 @@ bool AreCompatibleCUDADataAttrs(std::optional<CUDADataAttr> x,
       y.value_or(CUDADataAttr::Device) == CUDADataAttr::Device) {
     return true;
   } else if (ignoreTKR.test(IgnoreTKR::Managed) &&
-      x.value_or(CUDADataAttr::Managed) == CUDADataAttr::Managed &&
-      y.value_or(CUDADataAttr::Managed) == CUDADataAttr::Managed) {
+      (!x || *x == CUDADataAttr::Managed || *x == CUDADataAttr::Unified) &&
+      (!y || *y == CUDADataAttr::Managed || *y == CUDADataAttr::Unified)) {
     return true;
   } else if (allowUnifiedMatchingRule) {
     if (!x) { // Dummy argument has no attribute -> host
diff --git a/flang/test/Semantics/cuf10.cuf b/flang/test/Semantics/cuf10.cuf
index 2cb1d0d227036..86637a92b2196 100644
--- a/flang/test/Semantics/cuf10.cuf
+++ b/flang/test/Semantics/cuf10.cuf
@@ -58,6 +58,17 @@ module m
     integer :: a(10)
     call hostdev(a) ! ok because hostdev is attributes(host,device)
   end subroutine
-    
+
+  subroutine sub_ignore_tkr_m(x, n)
+!dir$ ignore_tkr (m) x
+    integer, unified :: x(n)
+    integer, value :: n
+  end subroutine
+  subroutine test_ignore_tkr_m()
+    integer :: host_arr(10)
+    integer, managed :: managed_arr(10)
+    call sub_ignore_tkr_m(host_arr, 10)
+    call sub_ignore_tkr_m(managed_arr, 10)
+  end subroutine
 
 end



More information about the flang-commits mailing list