Conversation
Signed-off-by: niranda perera <niranda.perera@gmail.com>
|
Thanks for looking into it, it seems someone with cmake ownership needs to approve as well |
This comment has been minimized.
This comment has been minimized.
| // GCC cannot prove __query_interface returns non-null for __iunknown (the invariant guarantees it) | ||
| _CCCL_DIAG_PUSH | ||
| _CCCL_DIAG_SUPPRESS_GCC("-Wnull-dereference") |
There was a problem hiding this comment.
Critical: some compilers have issues with warning suppression inside of class definitions. We should rather move the suppression outside to a single one at the top and one push at the bottom.
There was a problem hiding this comment.
@miscco what's the better practice here? Should I move the PUSH to the very top of the cpp file covering all methods? Or just cover these 2 methods?
Because, in the future, if some other warning needs to be suppressed, we should be able to see the existing warning suppressions.
There was a problem hiding this comment.
Sorry, the message got lost.
We should move the push to the top of the class and the pop after it
This comment has been minimized.
This comment has been minimized.
🥳 CI Workflow Results🟩 Finished in 1h 31m: Pass: 100%/99 | Total: 1d 10h | Max: 1h 14m | Hits: 94%/255613See results here. |
Description
Fixes #7875
Enables
-Wnull-dereference(with-Werror) in the libcudacxx test suite and suppresses the resulting GCC false-positive warnings in the__basic_anytype-erasure implementation.Why
-Wnull-dereference?-Wnull-dereferenceasks GCC to perform inter-procedural null-pointer flow analysis and warn (with-Werror, hard-fail) on any code path that can reach a dereference through a pointer that could be null. This catches a class of bugs that-Walland-Wextramiss.Why the suppressions?
GCC's analysis cannot see through
__basic_any's type-erasure invariants. When__query_interfaceis inlined, GCC observes itsreturn nullptrbranch and concludes the result might be null at every call site, even those that are guarded by the design (e.g.,__iunknownis always registered, virtual dispatch is only reached through a live object). This leads to false-positive errors in three locations:virtcall.h__virtcall—__vptr->__fn_(...)__query_interfaceinlined; GCC sees potentialnullptrbasic_any_value.hreset()/type()—__query_interface(__iunknown())->...__iunknownlookup inlined, nullable path visiblertti.h__try_vptr_cast—rtti->__query_interface(...)__query_interface(__iunknown())inlined into slow-path castEach suppression is scoped as tightly as possible — a
_CCCL_DIAG_PUSH/_CCCL_DIAG_SUPPRESS_GCC("-Wnull-dereference")/_CCCL_DIAG_POPbracket around only the offending statement(s)._CCCL_DIAG_SUPPRESS_GCCexpands to a no-op on all non-GCC compilers.Changes
libcudacxx/test/CMakeLists.txt— adds-Wnull-dereferencetoheadertest_warning_levels_device(NVIDIA/NVCC, Clang-as-device, and generic paths) andheadertest_warning_levels_host(non-MSVC). MSVC paths are unchanged.libcudacxx/include/cuda/__utility/__basic_any/virtcall.h— suppresses false positive in__virtcallat the virtual dispatch call site.libcudacxx/include/cuda/__utility/__basic_any/basic_any_value.h— suppresses false positives inreset()andtype()around the__query_interface(__iunknown())dereference chains.libcudacxx/include/cuda/__utility/__basic_any/rtti.h— suppresses false positive in__try_vptr_castslow-path (down-cast / cross-cast) whererttiis known non-null by the__iunknownregistration invariant.Checklist