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

Nathan Chancellor via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 29 08:21:51 PDT 2024


nathanchance 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

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


More information about the cfe-commits mailing list