[clang] [clang-tools-extra] [libcxx] [clang][Sema] Add -Wsuspicious-memcmp for memcmp on types without unique object representations (PR #214218)

Aditya Medhane via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 7 07:56:56 PDT 2026


flash1729 wrote:

> [!NOTE]
> Stacked on #212768 (the first commit in this PR); will rebase to a single commit once that lands.

Some context on validation and the in-tree changes that ride along:

**False positives**: The known `_Atomic` false positive in `hasUniqueObjectRepresentations` is being fixed by #212768, which this PR depends on. The predicate's remaining unhandled types (vectors, `_Complex`, some ObjC and OpenCL types) conservatively report non-unique. That's the same behavior the tidy check has shipped since 2021, and none of these types show up in memcmp'd structs anywhere in the monorepo.

**In-tree fallout**: The library code warning flags is libc++'s atomics implementation, where [atomics.wait] requires comparing value representations, so the memcmp is intentional. Those sites now cast to `const void*`, which is what the fixit suggests. Four libc++ tests that check object representations directly (`bit_cast.pass.cpp` and the atomic padding tests) suppress the warning with a `__has_warning`-guarded pragma, so configurations that test against older compilers are unaffected.

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


More information about the cfe-commits mailing list