================
@@ -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.
----------------
yxsamliu wrote:

Good point, I'll clarify the wording. The deferred diagnostic is emitted when a 
function with guaranteed device-side emission (e.g. a kernel or an 
externally-visible `__device__` function) directly or indirectly calls an HD 
function that contains an invalid operation like referencing a host-only 
function.

Regarding `if constexpr` — you're right, deferred diagnostics are still emitted 
for the discarded branch. This is a pre-existing limitation: deferred 
diagnostics are recorded at parse time before `if constexpr` is resolved, and 
the reachability check works at the call graph level, not at the statement 
level. We could address it by conditionally traversing the AST when collecting 
deferred diagnostics, but that would be future work and is outside the scope of 
this PR.

https://github.com/llvm/llvm-project/pull/185926
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to