llvm-c166/offload/tools
Jan Trusiłło f7075d0da2
[offload] add nodiscard support to offload-tblgen and mark ol_errc_t (#209727)
Offload API functions may fail with error codes that shouldn't be
ignored. Most notably, if `olInit` fails and its error return value is
ignored, it is easy to use the library in an invalid uninitialized
state, which can and has caused confusion. In those cases, it may be
useful to have the ability to mark some API function with
`[[nodiscard]]`

This PR adds an optional `nodiscard` property to offload-tblgen's
`Function`, `Enum`, and `Struct`. If set, an `OL_NODISCARD` macro is
emitted, which expands to `[[nodiscard]]` on >=C++17 and >=C23, and to
nothing otherwise.

`nodiscard` is set for `ol_errc_t`, meaning every call to a function
that returns it will emit a compiler warning if the return value is
ignored and the TU is compiled on a supported language mode.

`libsycl` and `llvm-gpu-loader` still build cleanly and are unaffected
by the change.

Worth considering: should there be an opt-out (`#define
OL_DISABLE_NODISCARD` or similar)?

Assisted-by: Claude
2026-08-03 14:40:13 +00:00
..
deviceinfo
kernelreplay
offload-tblgen [offload] add nodiscard support to offload-tblgen and mark ol_errc_t (#209727) 2026-08-03 14:40:13 +00:00
CMakeLists.txt