[libc-commits] [libc] [libc] Expand usage of libc null checks. (PR #116262)
via libc-commits
libc-commits at lists.llvm.org
Wed Jan 8 13:30:28 PST 2025
================
@@ -17,6 +18,8 @@ namespace LIBC_NAMESPACE_DECL {
// TODO: Look at performance benefits of comparing words.
LLVM_LIBC_FUNCTION(void *, memchr, (const void *src, int c, size_t n)) {
+ const unsigned char *src_cpy = (const unsigned char *)src;
+ LIBC_CRASH_ON_NULLPTR(src_cpy);
----------------
lntue wrote:
The volatile load of nullptr (which is implementation-defined, not undefined behavior) was needed to preserve the crashing with SIGSEGV behavior that you might get when `func(nullptr)` was called with a dynamically linked glibc. Without that, `__builtin_trap()` will crash with `SIGILL` instead.
So for the purpose of this PR, I think we should leave `LIBC_CRASH_ON_NULLPTR` macro definition as-is, and a further investigation to simplify the trapping behavior of the macro could be a follow up task / PR.
https://github.com/llvm/llvm-project/pull/116262
More information about the libc-commits
mailing list