Implement C23 memset_explicit (bug 32378)
Collin Funk
collin.funk1@gmail.com
Fri Sep 26 19:56:02 GMT 2025
Joseph Myers <josmyers@redhat.com> writes:
> +void *
> +__memset_explicit_chk (void *dst, int c, size_t len, size_t dstlen)
> +{
> + /* Inline __memset_chk to avoid a PLT reference to __memset_chk. */
> + if (__glibc_unlikely (dstlen < len))
> + __chk_fail ();
> + memset (dst, c, len);
> + /* Compiler barrier. */
> + asm volatile ("" ::: "memory");
> + return dst;
> +}
Do we want the following workaround from Gnulib so Clang does not
optimize it away? Copying the snippet from there:
memset (s, c, len);
/* Compiler barrier. */
/* With asm ("" ::: "memory") LLVM analyzes uses of 's' and finds that the
whole thing is dead and eliminates it. Use 'g' to work around this
problem. See <https://bugs.llvm.org/show_bug.cgi?id=15495#c11>. */
__asm__ volatile ("" : : "g"(s) : "memory");
return s;
Collin
More information about the Libc-alpha
mailing list