[flang-commits] [flang] [llvm] [flang][cuda][semantics] Reject unguarded host-only and device-only calls in CUDA HOST, DEVICE procedures (PR #228176)

Eugene Epshteyn via flang-commits flang-commits at lists.llvm.org
Mon Oct 5 17:51:32 PDT 2026


================
@@ -67,20 +68,64 @@ static const llvm::StringSet<> warpFunctions_ = {"match_all_syncjj",
     "match_any_syncjj", "match_any_syncjx", "match_any_syncjf",
     "match_any_syncjd"};
 
+// These builtin procedures lower to inline pointer operations on either target.
+static const llvm::StringSet<> inlinePointerFunctions_ = {"c_associated_c_ptr",
+    "c_associated_c_funptr", "__builtin_c_ptr_eq", "__builtin_c_ptr_ne",
+    "__builtin_c_devptr_eq", "__builtin_c_devptr_ne"};
----------------
eugeneepshteyn wrote:

(This comment was generated with the help of AI)

`c_funloc` is lowered inline too, but it's not in this list, so it's now rejected in `host,device` code:

```fortran
module funloc_host_device
  use iso_c_binding
contains
  subroutine callback() bind(c)
  end subroutine
  attributes(host,device) subroutine take_address(fp)
    type(c_funptr) :: fp
    fp = c_funloc(callback)
  end subroutine
end module
```

```console
$ flang -fsyntax-only -x cuda funloc_host_device.cuf
error: Semantic errors in funloc_host_device.cuf
funloc_host_device.cuf:8:5: error: 'c_funloc' may not be called in device code
      fp = c_funloc(callback)
      ^^^^^^^^^^^^^^^^^^^^^^^
```

Adding `__builtin_c_funloc` (or exempting everything owned by `__fortran_builtins`) would fix it, plus a case in `cuf-hostdevice-c-pointers.cuf`.


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


More information about the flang-commits mailing list