[clang] [llvm] [CUDA/HIP][SYCL] Deduplicate deferred diagnostics across multiple callers (PR #185926)
Artem Belevich via cfe-commits
cfe-commits at lists.llvm.org
Wed Mar 11 18:05:30 PDT 2026
================
@@ -484,6 +484,88 @@ non-constexpr function, which is by default a host function.
Users can override the inferred host and device attributes of default
destructors by adding explicit host and device attributes to them.
+Deferred Diagnostics
+====================
+
+In HIP (and CUDA), a ``__host__ __device__`` function can be called from both
+host and device code. Certain operations are not allowed on the device (e.g.,
+calling a host-only function, using variable-length arrays, or throwing
+exceptions). However, a ``__host__ __device__`` function containing such
+operations is only ill-formed if it is actually called from device code.
+
+Clang handles this through *deferred diagnostics*: errors and warnings in
+``__host__ __device__`` functions are recorded during parsing but not emitted
+immediately. They are only emitted if the function turns out to be reachable
+from code that must run on the device.
----------------
Artem-B wrote:
It's not clear which reachable function triggers the diag. Is it the HD function associated with the diag itself, or the callee which can't be called in this compilation? E.g for `if constexpr (is_host_compilation()) device_func()` we probably should not emit the diagnostic on the host (but we apparently do: https://godbolt.org/z/nhWfEzhEq)
https://github.com/llvm/llvm-project/pull/185926
More information about the cfe-commits
mailing list