[clang] [clang] warn_{cstruct, cxxstruct}_memaccess are too agressive about initializers (PR #170577)
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Wed Apr 29 04:56:09 PDT 2026
================
@@ -10356,15 +10356,24 @@ void Sema::CheckMemaccessArguments(const CallExpr *Call,
bool NonTriviallyCopyableCXXRecord =
getLangOpts().CPlusPlus && RD->isCompleteDefinition() &&
!PointeeTy.isTriviallyCopyableType(Context);
+ // We don't warn about bzero or zero memsetting as these are an idiomatic
+ // mechanism for ensuring objects do not have stale data.
+ bool IsNonZeroInitMemcall = false;
----------------
AaronBallman wrote:
Ooof yeah, this only working for `memset` is not going to catch all the idioms. `bzero` certainly is used as is `explicit_bzero`. `ZeroMemory` from Win32 ends up expanding to a `memset`, as does `FillMemory`, so those are fine, but `SecureZeroMemory` expands to a function `RtlSecureZeroMemory` (and there's `SecureZeroMemory2` which expands to `RtlSecureZeroMemory2` of course, lol). `memset_s` is used pretty often on Windows as well. I doubt this is a complete list, but on top of it, there's variants where the user wraps these calls in their own helper function, etc.
https://github.com/llvm/llvm-project/pull/170577
More information about the cfe-commits
mailing list