[flang-commits] [flang] [flang][cuda] Allow call to len intrinsic on host with device argument (PR #216846)

via flang-commits flang-commits at lists.llvm.org
Mon Aug 17 14:46:10 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-flang-semantics

Author: Valentin Clement (バレンタイン クレメン) (clementval)

<details>
<summary>Changes</summary>

This is fine to call `len` intrinsic on the host with a device actual argument since the descriptor is allocated in managed memory. 

---
Full diff: https://github.com/llvm/llvm-project/pull/216846.diff


2 Files Affected:

- (modified) flang/lib/Semantics/check-call.cpp (+2-2) 
- (modified) flang/test/Semantics/CUDA/cuf23.cuf (+7) 


``````````diff
diff --git a/flang/lib/Semantics/check-call.cpp b/flang/lib/Semantics/check-call.cpp
index 6309b3617f84b..8ba83be132723 100644
--- a/flang/lib/Semantics/check-call.cpp
+++ b/flang/lib/Semantics/check-call.cpp
@@ -354,8 +354,8 @@ static bool DefersSameTypeParameters(
 // arguments.
 static const llvm::StringSet<> cudaSkippedIntrinsics = {"__builtin_c_devloc",
     "__builtin_c_f_pointer", "__builtin_c_loc", "__builtin_show_descriptor",
-    "allocated", "associated", "kind", "lbound", "loc", "present", "shape",
-    "size", "sizeof", "ubound"};
+    "allocated", "associated", "kind", "len", "lbound", "loc", "present",
+    "shape", "size", "sizeof", "ubound"};
 
 static void CheckExplicitDataArg(const characteristics::DummyDataObject &dummy,
     const std::string &dummyName, evaluate::Expr<evaluate::SomeType> &actual,
diff --git a/flang/test/Semantics/CUDA/cuf23.cuf b/flang/test/Semantics/CUDA/cuf23.cuf
index 7eb261413f3ff..6d577bb0559ea 100644
--- a/flang/test/Semantics/CUDA/cuf23.cuf
+++ b/flang/test/Semantics/CUDA/cuf23.cuf
@@ -89,6 +89,13 @@ subroutine intrinsic_error_skip_show_descriptor(n)
   call show_descriptor(d) ! ok, descriptor in managed memory
 end subroutine
 
+subroutine intrinsic_error_skip_len(cdchar)
+  character(len=*), device :: cdchar
+  integer :: ibuffsize
+  ibuffsize = len(cdchar) ! ok, descriptor is in managed memory
+end subroutine intrinsic_error_skip_len
+
+
 double complex function acc_routine_check(n, x, y)
   !$acc routine(acc_routine_check) vector
   implicit none

``````````

</details>


https://github.com/llvm/llvm-project/pull/216846


More information about the flang-commits mailing list