[flang-commits] [flang] [flang][cuda] Emit error when a device actual argument is used in host intrinsic (PR #172914)

Valentin Clement バレンタイン クレメン via flang-commits flang-commits at lists.llvm.org
Thu Dec 18 14:42:07 PST 2025


================
@@ -1145,6 +1145,37 @@ static void CheckExplicitDataArg(const characteristics::DummyDataObject &dummy,
           dummyName, toStr(dummyDataAttr), toStr(actualDataAttr));
     }
   }
+  // Emit an error message if an actual argument passed to a host intrinsic is
+  // on the device.
+  if (intrinsic && !FindCUDADeviceContext(scope) &&
+      !FindOpenACCConstructContaining(scope) &&
+      !FindCUFKernelDoConstructContaining(scope)) {
+    if (intrinsic->name != "__builtin_c_f_pointer" &&
+        intrinsic->name != "__builtin_c_loc") {
+      std::optional<common::CUDADataAttr> actualDataAttr;
+      if (const auto *actualObject{actualLastSymbol
+                  ? actualLastSymbol->detailsIf<ObjectEntityDetails>()
+                  : nullptr}) {
+        actualDataAttr = actualObject->cudaDataAttr();
+      }
+      if (actualDataAttr && *actualDataAttr == common::CUDADataAttr::Device) {
+        // Allocatable or pointer with device attribute have their descriptor in
+        // managed memory. It is allowed to pass them to some inquiry
+        // intrinsics.
+        if (!actualLastSymbol || !IsAllocatableOrPointer(*actualLastSymbol) ||
+            (IsAllocatableOrPointer(*actualLastSymbol) &&
+                intrinsic->name != "size" && intrinsic->name != "lbound" &&
----------------
clementval wrote:

I added stringsets for the intrinsics names but I still need two since the condition are different. 

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


More information about the flang-commits mailing list