[clang-tidy] Add bugprone-suspicious-memory-comparison check
authorGabor Bencze <b.gabor98@gmail.com>
Wed, 25 Aug 2021 18:22:15 +0000 (20:22 +0200)
committerBalazs Benics <balazs.benics@sigmatechnology.se>
Thu, 26 Aug 2021 07:23:37 +0000 (09:23 +0200)
commit3373e845398bfb8fa0e3c81b7ca84cbfedbad3ae
tree7322a2de900ed5eb903c0da775b43bf1a37a16d3
parentad59735f9d150ebd10d4752a4468795c39f02c5d
[clang-tidy] Add bugprone-suspicious-memory-comparison check

The check warns on suspicious calls to `memcmp`.
It currently checks for comparing types that do not have
unique object representations or are non-standard-layout.
Based on
  https://wiki.sei.cmu.edu/confluence/display/c/EXP42-C.+Do+not+compare+padding+data
  https://wiki.sei.cmu.edu/confluence/display/c/FLP37-C.+Do+not+use+object+representations+to+compare+floating-point+values
and part of
  https://wiki.sei.cmu.edu/confluence/display/cplusplus/OOP57-CPP.+Prefer+special+member+functions+and+overloaded+operators+to+C+Standard+Library+functions
Add alias `cert-exp42-c` and `cert-flp37-c`.

Some tests are currently failing at head, the check depends on D89649.
Originally started in D71973

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D89651
13 files changed:
clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
clang-tools-extra/clang-tidy/bugprone/SuspiciousMemoryComparisonCheck.cpp [new file with mode: 0644]
clang-tools-extra/clang-tidy/bugprone/SuspiciousMemoryComparisonCheck.h [new file with mode: 0644]
clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/docs/clang-tidy/checks/bugprone-suspicious-memory-comparison.rst [new file with mode: 0644]
clang-tools-extra/docs/clang-tidy/checks/cert-exp42-c.rst [new file with mode: 0644]
clang-tools-extra/docs/clang-tidy/checks/cert-flp37-c.rst [new file with mode: 0644]
clang-tools-extra/docs/clang-tidy/checks/list.rst
clang-tools-extra/test/clang-tidy/checkers/bugprone-suspicious-memory-comparison-32bits.cpp [new file with mode: 0644]
clang-tools-extra/test/clang-tidy/checkers/bugprone-suspicious-memory-comparison.c [new file with mode: 0644]
clang-tools-extra/test/clang-tidy/checkers/bugprone-suspicious-memory-comparison.cpp [new file with mode: 0644]