Skip to content

Commit 6b147b4

Browse files
authored
[clang-tidy] Rename and move 'cert-oop57-cpp' to 'bugprone-raw-memory-call-on-non-trivial-type' (#162039)
closes #157294
1 parent eb4360b commit 6b147b4

File tree

11 files changed

+74
-57
lines changed

11 files changed

+74
-57
lines changed

clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
#include "ParentVirtualCallCheck.h"
6262
#include "PointerArithmeticOnPolymorphicObjectCheck.h"
6363
#include "PosixReturnCheck.h"
64+
#include "RawMemoryCallOnNonTrivialTypeCheck.h"
6465
#include "RedundantBranchConditionCheck.h"
6566
#include "ReservedIdentifierCheck.h"
6667
#include "ReturnConstRefFromParameterCheck.h"
@@ -216,6 +217,8 @@ class BugproneModule : public ClangTidyModule {
216217
CheckFactories.registerCheck<ParentVirtualCallCheck>(
217218
"bugprone-parent-virtual-call");
218219
CheckFactories.registerCheck<PosixReturnCheck>("bugprone-posix-return");
220+
CheckFactories.registerCheck<RawMemoryCallOnNonTrivialTypeCheck>(
221+
"bugprone-raw-memory-call-on-non-trivial-type");
219222
CheckFactories.registerCheck<ReservedIdentifierCheck>(
220223
"bugprone-reserved-identifier");
221224
CheckFactories.registerCheck<SharedPtrArrayMismatchCheck>(

clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ add_clang_library(clangTidyBugproneModule STATIC
6262
ParentVirtualCallCheck.cpp
6363
PointerArithmeticOnPolymorphicObjectCheck.cpp
6464
PosixReturnCheck.cpp
65+
RawMemoryCallOnNonTrivialTypeCheck.cpp
6566
RedundantBranchConditionCheck.cpp
6667
ReservedIdentifierCheck.cpp
6768
ReturnConstRefFromParameterCheck.cpp

clang-tools-extra/clang-tidy/cert/NonTrivialTypesLibcMemoryCallsCheck.cpp renamed to clang-tools-extra/clang-tidy/bugprone/RawMemoryCallOnNonTrivialTypeCheck.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#include "NonTrivialTypesLibcMemoryCallsCheck.h"
9+
#include "RawMemoryCallOnNonTrivialTypeCheck.h"
1010
#include "../utils/OptionsUtils.h"
1111
#include "clang/AST/Decl.h"
1212
#include "clang/ASTMatchers/ASTMatchFinder.h"
@@ -17,7 +17,7 @@
1717

1818
using namespace clang::ast_matchers;
1919

20-
namespace clang::tidy::cert {
20+
namespace clang::tidy::bugprone {
2121

2222
namespace {
2323
AST_MATCHER(CXXRecordDecl, isTriviallyDefaultConstructible) {
@@ -48,22 +48,21 @@ static constexpr llvm::StringRef ComparisonOperators[] = {
4848
"operator==", "operator!=", "operator<",
4949
"operator>", "operator<=", "operator>="};
5050

51-
NonTrivialTypesLibcMemoryCallsCheck::NonTrivialTypesLibcMemoryCallsCheck(
51+
RawMemoryCallOnNonTrivialTypeCheck::RawMemoryCallOnNonTrivialTypeCheck(
5252
StringRef Name, ClangTidyContext *Context)
5353
: ClangTidyCheck(Name, Context),
5454
MemSetNames(Options.get("MemSetNames", "")),
5555
MemCpyNames(Options.get("MemCpyNames", "")),
5656
MemCmpNames(Options.get("MemCmpNames", "")) {}
5757

58-
void NonTrivialTypesLibcMemoryCallsCheck::storeOptions(
58+
void RawMemoryCallOnNonTrivialTypeCheck::storeOptions(
5959
ClangTidyOptions::OptionMap &Opts) {
6060
Options.store(Opts, "MemSetNames", MemSetNames);
6161
Options.store(Opts, "MemCpyNames", MemCpyNames);
6262
Options.store(Opts, "MemCmpNames", MemCmpNames);
6363
}
6464

65-
void NonTrivialTypesLibcMemoryCallsCheck::registerMatchers(
66-
MatchFinder *Finder) {
65+
void RawMemoryCallOnNonTrivialTypeCheck::registerMatchers(MatchFinder *Finder) {
6766
using namespace ast_matchers::internal;
6867
auto IsStructPointer = [](Matcher<CXXRecordDecl> Constraint = anything(),
6968
bool Bind = false) {
@@ -103,7 +102,7 @@ void NonTrivialTypesLibcMemoryCallsCheck::registerMatchers(
103102
this);
104103
}
105104

106-
void NonTrivialTypesLibcMemoryCallsCheck::check(
105+
void RawMemoryCallOnNonTrivialTypeCheck::check(
107106
const MatchFinder::MatchResult &Result) {
108107
if (const auto *Caller = Result.Nodes.getNodeAs<CallExpr>("lazyConstruct")) {
109108
diag(Caller->getBeginLoc(), "calling %0 on a non-trivially default "
@@ -122,4 +121,4 @@ void NonTrivialTypesLibcMemoryCallsCheck::check(
122121
}
123122
}
124123

125-
} // namespace clang::tidy::cert
124+
} // namespace clang::tidy::bugprone

clang-tools-extra/clang-tidy/cert/NonTrivialTypesLibcMemoryCallsCheck.h renamed to clang-tools-extra/clang-tidy/bugprone/RawMemoryCallOnNonTrivialTypeCheck.h

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,21 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CERT_NONTRIVIALTYPESLIBCMEMORYCALLSCHECK_H
10-
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CERT_NONTRIVIALTYPESLIBCMEMORYCALLSCHECK_H
9+
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_RAWMEMORYCALLONNONTRIVIALTYPECHECK_H
10+
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_RAWMEMORYCALLONNONTRIVIALTYPECHECK_H
1111

1212
#include "../ClangTidyCheck.h"
1313

14-
namespace clang::tidy::cert {
14+
namespace clang::tidy::bugprone {
1515

16-
/// Flags use of the `C` standard library functions 'memset', 'memcpy' and
16+
/// Flags use of the C standard library functions 'memset', 'memcpy' and
1717
/// 'memcmp' and similar derivatives on non-trivial types.
1818
///
1919
/// For the user-facing documentation see:
20-
/// https://clang.llvm.org/extra/clang-tidy/checks/cert/oop57-cpp.html
21-
class NonTrivialTypesLibcMemoryCallsCheck : public ClangTidyCheck {
20+
/// https://clang.llvm.org/extra/clang-tidy/checks/bugprone/raw-memory-call-on-non-trivial-type.html
21+
class RawMemoryCallOnNonTrivialTypeCheck : public ClangTidyCheck {
2222
public:
23-
NonTrivialTypesLibcMemoryCallsCheck(StringRef Name,
24-
ClangTidyContext *Context);
23+
RawMemoryCallOnNonTrivialTypeCheck(StringRef Name, ClangTidyContext *Context);
2524
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
2625
return LangOpts.CPlusPlus && !LangOpts.ObjC;
2726
}
@@ -35,6 +34,6 @@ class NonTrivialTypesLibcMemoryCallsCheck : public ClangTidyCheck {
3534
const StringRef MemCmpNames;
3635
};
3736

38-
} // namespace clang::tidy::cert
37+
} // namespace clang::tidy::bugprone
3938

40-
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CERT_NONTRIVIALTYPESLIBCMEMORYCALLSCHECK_H
39+
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_RAWMEMORYCALLONNONTRIVIALTYPECHECK_H

clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "../bugprone/BadSignalToKillThreadCheck.h"
1313
#include "../bugprone/CommandProcessorCheck.h"
1414
#include "../bugprone/PointerArithmeticOnPolymorphicObjectCheck.h"
15+
#include "../bugprone/RawMemoryCallOnNonTrivialTypeCheck.h"
1516
#include "../bugprone/ReservedIdentifierCheck.h"
1617
#include "../bugprone/SignalHandlerCheck.h"
1718
#include "../bugprone/SignedCharMisuseCheck.h"
@@ -39,7 +40,6 @@
3940
#include "FloatLoopCounter.h"
4041
#include "LimitedRandomnessCheck.h"
4142
#include "MutatingCopyCheck.h"
42-
#include "NonTrivialTypesLibcMemoryCallsCheck.h"
4343
#include "ProperlySeededRandomGeneratorCheck.h"
4444
#include "ThrownExceptionTypeCheck.h"
4545

@@ -278,7 +278,7 @@ class CERTModule : public ClangTidyModule {
278278
"cert-oop11-cpp");
279279
CheckFactories.registerCheck<bugprone::UnhandledSelfAssignmentCheck>(
280280
"cert-oop54-cpp");
281-
CheckFactories.registerCheck<NonTrivialTypesLibcMemoryCallsCheck>(
281+
CheckFactories.registerCheck<bugprone::RawMemoryCallOnNonTrivialTypeCheck>(
282282
"cert-oop57-cpp");
283283
CheckFactories.registerCheck<MutatingCopyCheck>("cert-oop58-cpp");
284284

clang-tools-extra/clang-tidy/cert/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ add_clang_library(clangTidyCERTModule STATIC
1010
FloatLoopCounter.cpp
1111
LimitedRandomnessCheck.cpp
1212
MutatingCopyCheck.cpp
13-
NonTrivialTypesLibcMemoryCallsCheck.cpp
1413
ProperlySeededRandomGeneratorCheck.cpp
1514
ThrownExceptionTypeCheck.cpp
1615

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,11 @@ New check aliases
264264
<clang-tidy/checks/bugprone/throwing-static-initialization>`
265265
keeping initial check as an alias to the new one.
266266

267+
- Renamed :doc:`cert-oop57-cpp <clang-tidy/checks/cert/oop57-cpp>` to
268+
:doc:`bugprone-raw-memory-call-on-non-trivial-type
269+
<clang-tidy/checks/bugprone/raw-memory-call-on-non-trivial-type>`
270+
keeping initial check as an alias to the new one.
271+
267272
Changes in existing checks
268273
^^^^^^^^^^^^^^^^^^^^^^^^^^
269274

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
.. title:: clang-tidy - bugprone-raw-memory-call-on-non-trivial-type
2+
3+
bugprone-raw-memory-call-on-non-trivial-type
4+
============================================
5+
6+
Flags use of the C standard library functions ``memset``, ``memcpy`` and
7+
``memcmp`` and similar derivatives on non-trivial types.
8+
9+
The check will detect the following functions: ``memset``, ``std::memset``,
10+
``std::memcpy``, ``memcpy``, ``std::memmove``, ``memmove``, ``std::strcpy``,
11+
``strcpy``, ``memccpy``, ``stpncpy``, ``strncpy``, ``std::memcmp``, ``memcmp``,
12+
``std::strcmp``, ``strcmp``, ``strncmp``.
13+
14+
Options
15+
-------
16+
17+
.. option:: MemSetNames
18+
19+
Specify extra functions to flag that act similarly to ``memset``. Specify
20+
names in a semicolon-delimited list. Default is an empty string.
21+
22+
.. option:: MemCpyNames
23+
24+
Specify extra functions to flag that act similarly to ``memcpy``. Specify
25+
names in a semicolon-delimited list. Default is an empty string.
26+
27+
.. option:: MemCmpNames
28+
29+
Specify extra functions to flag that act similarly to ``memcmp``. Specify
30+
names in a semicolon-delimited list. Default is an empty string.
31+
32+
This check corresponds to the CERT C++ Coding Standard rule
33+
`OOP57-CPP. Prefer special member functions and overloaded operators to C
34+
Standard Library functions
35+
<https://wiki.sei.cmu.edu/confluence/display/cplusplus/OOP57-CPP.+Prefer+special+member+functions+and+overloaded+operators+to+C+Standard+Library+functions>`_.

clang-tools-extra/docs/clang-tidy/checks/cert/oop57-cpp.rst

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,13 @@
11
.. title:: clang-tidy - cert-oop57-cpp
2+
.. meta::
3+
:http-equiv=refresh: 5;URL=../bugprone/raw-memory-call-on-non-trivial-type.html
24

35
cert-oop57-cpp
46
==============
57

6-
Flags use of the `C` standard library functions ``memset``, ``memcpy`` and
7-
``memcmp`` and similar derivatives on non-trivial types.
8-
9-
Options
10-
-------
11-
12-
.. option:: MemSetNames
13-
14-
Specify extra functions to flag that act similarly to ``memset``.
15-
Specify names in a semicolon delimited list.
16-
Default is an empty string.
17-
The check will detect the following functions:
18-
`memset`, `std::memset`.
19-
20-
.. option:: MemCpyNames
21-
22-
Specify extra functions to flag that act similarly to ``memcpy``.
23-
Specify names in a semicolon delimited list.
24-
Default is an empty string.
25-
The check will detect the following functions:
26-
`std::memcpy`, `memcpy`, `std::memmove`, `memmove`, `std::strcpy`,
27-
`strcpy`, `memccpy`, `stpncpy`, `strncpy`.
28-
29-
.. option:: MemCmpNames
30-
31-
Specify extra functions to flag that act similarly to ``memcmp``.
32-
Specify names in a semicolon delimited list.
33-
Default is an empty string.
34-
The check will detect the following functions:
35-
`std::memcmp`, `memcmp`, `std::strcmp`, `strcmp`, `strncmp`.
8+
The `cert-oop57-cpp` check is an alias, please see
9+
`bugprone-raw-memory-call-on-non-trivial-type <../bugprone/raw-memory-call-on-non-trivial-type.html>`_
10+
for more information.
3611

3712
This check corresponds to the CERT C++ Coding Standard rule
3813
`OOP57-CPP. Prefer special member functions and overloaded operators to C

clang-tools-extra/docs/clang-tidy/checks/list.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ Clang-Tidy Checks
129129
:doc:`bugprone-parent-virtual-call <bugprone/parent-virtual-call>`, "Yes"
130130
:doc:`bugprone-pointer-arithmetic-on-polymorphic-object <bugprone/pointer-arithmetic-on-polymorphic-object>`,
131131
:doc:`bugprone-posix-return <bugprone/posix-return>`, "Yes"
132+
:doc:`bugprone-raw-memory-call-on-non-trivial-type <bugprone/raw-memory-call-on-non-trivial-type>`,
132133
:doc:`bugprone-redundant-branch-condition <bugprone/redundant-branch-condition>`, "Yes"
133134
:doc:`bugprone-reserved-identifier <bugprone/reserved-identifier>`, "Yes"
134135
:doc:`bugprone-return-const-ref-from-parameter <bugprone/return-const-ref-from-parameter>`,
@@ -180,7 +181,6 @@ Clang-Tidy Checks
180181
:doc:`cert-mem57-cpp <cert/mem57-cpp>`,
181182
:doc:`cert-msc50-cpp <cert/msc50-cpp>`,
182183
:doc:`cert-msc51-cpp <cert/msc51-cpp>`,
183-
:doc:`cert-oop57-cpp <cert/oop57-cpp>`,
184184
:doc:`cert-oop58-cpp <cert/oop58-cpp>`,
185185
:doc:`concurrency-mt-unsafe <concurrency/mt-unsafe>`,
186186
:doc:`concurrency-thread-canceltype-asynchronous <concurrency/thread-canceltype-asynchronous>`,
@@ -442,8 +442,8 @@ Check aliases
442442
:doc:`cert-dcl51-cpp <cert/dcl51-cpp>`, :doc:`bugprone-reserved-identifier <bugprone/reserved-identifier>`, "Yes"
443443
:doc:`cert-dcl54-cpp <cert/dcl54-cpp>`, :doc:`misc-new-delete-overloads <misc/new-delete-overloads>`,
444444
:doc:`cert-dcl59-cpp <cert/dcl59-cpp>`, :doc:`google-build-namespaces <google/build-namespaces>`,
445-
:doc:`cert-err09-cpp <cert/err09-cpp>`, :doc:`misc-throw-by-value-catch-by-reference <misc/throw-by-value-catch-by-reference>`,
446445
:doc:`cert-env33-c <cert/env33-c>`, :doc:`bugprone-command-processor <bugprone/command-processor>`,
446+
:doc:`cert-err09-cpp <cert/err09-cpp>`, :doc:`misc-throw-by-value-catch-by-reference <misc/throw-by-value-catch-by-reference>`,
447447
:doc:`cert-err34-c <cert/err34-c>`, :doc:`bugprone-unchecked-string-to-number-conversion <bugprone/unchecked-string-to-number-conversion>`,
448448
:doc:`cert-err52-cpp <cert/err52-cpp>`, :doc:`modernize-avoid-setjmp-longjmp <modernize/avoid-setjmp-longjmp>`,
449449
:doc:`cert-err58-cpp <cert/err58-cpp>`, :doc:`bugprone-throwing-static-initialization <bugprone/throwing-static-initialization>`,
@@ -459,6 +459,7 @@ Check aliases
459459
:doc:`cert-msc54-cpp <cert/msc54-cpp>`, :doc:`bugprone-signal-handler <bugprone/signal-handler>`,
460460
:doc:`cert-oop11-cpp <cert/oop11-cpp>`, :doc:`performance-move-constructor-init <performance/move-constructor-init>`,
461461
:doc:`cert-oop54-cpp <cert/oop54-cpp>`, :doc:`bugprone-unhandled-self-assignment <bugprone/unhandled-self-assignment>`,
462+
:doc:`cert-oop57-cpp <cert/oop57-cpp>`, :doc:`bugprone-raw-memory-call-on-non-trivial-type <bugprone/raw-memory-call-on-non-trivial-type>`,
462463
:doc:`cert-pos44-c <cert/pos44-c>`, :doc:`bugprone-bad-signal-to-kill-thread <bugprone/bad-signal-to-kill-thread>`,
463464
:doc:`cert-pos47-c <cert/pos47-c>`, :doc:`concurrency-thread-canceltype-asynchronous <concurrency/thread-canceltype-asynchronous>`,
464465
:doc:`cert-sig30-c <cert/sig30-c>`, :doc:`bugprone-signal-handler <bugprone/signal-handler>`,

0 commit comments

Comments
 (0)