[clang] [libcxx] [clang] Warn about memset/memcpy to NonTriviallyCopyable types (PR #111434)

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 29 08:29:35 PDT 2024


AaronBallman wrote:

> Is it expected that this warns for C code? I only see `cxx` in this change but I see a new instance of this warning in my Linux kernel builds:
> 
> ```
> drivers/net/ethernet/netronome/nfp/nfdk/rings.c:60:18: warning: first argument in call to '__builtin_memset' is a pointer to non-trivially copyable type 'struct nfp_nfd3_tx_desc' [-Wnontrivial-memaccess]
>    60 |         memset(tx_ring->txds, 0, tx_ring->size);
>       |                         ^
> drivers/net/ethernet/netronome/nfp/nfdk/rings.c:60:18: note: explicitly cast the pointer to silence this warning
>    60 |         memset(tx_ring->txds, 0, tx_ring->size);
>       |                         ^
>       |                (void*)
> include/linux/fortify-string.h:512:46: note: expanded from macro 'memset'
>   512 | #define memset(p, c, s) __fortify_memset_chk(p, c, s,                   \
>       |                                              ^
> include/linux/fortify-string.h:504:22: note: expanded from macro '__fortify_memset_chk'
>   504 |         __underlying_memset(p, c, __fortify_size);                      \
>       |                             ^
> 1 warning generated.
> ```
> 
> https://elixir.bootlin.com/linux/v6.11.5/source/drivers/net/ethernet/netronome/nfp/nfdk/rings.c#L60

I would not expect this diagnostic in C code, that seems like a bug to me. @serge-sans-paille can you take care of that?

https://github.com/llvm/llvm-project/pull/111434


More information about the cfe-commits mailing list