clang-tools  11.0.0
CERTTidyModule.cpp
Go to the documentation of this file.
1 //===--- CERTTidyModule.cpp - clang-tidy ----------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "../ClangTidy.h"
10 #include "../ClangTidyModule.h"
11 #include "../ClangTidyModuleRegistry.h"
12 #include "../bugprone/BadSignalToKillThreadCheck.h"
13 #include "../bugprone/ReservedIdentifierCheck.h"
14 #include "../bugprone/SignedCharMisuseCheck.h"
15 #include "../bugprone/SpuriouslyWakeUpFunctionsCheck.h"
16 #include "../bugprone/UnhandledSelfAssignmentCheck.h"
17 #include "../google/UnnamedNamespaceInHeaderCheck.h"
18 #include "../misc/NewDeleteOverloadsCheck.h"
19 #include "../misc/NonCopyableObjects.h"
20 #include "../misc/StaticAssertCheck.h"
21 #include "../misc/ThrowByValueCatchByReferenceCheck.h"
22 #include "../performance/MoveConstructorInitCheck.h"
23 #include "../readability/UppercaseLiteralSuffixCheck.h"
24 #include "CommandProcessorCheck.h"
27 #include "FloatLoopCounter.h"
28 #include "LimitedRandomnessCheck.h"
29 #include "MutatingCopyCheck.h"
31 #include "PostfixOperatorCheck.h"
33 #include "SetLongJmpCheck.h"
35 #include "StrToNumCheck.h"
38 
39 namespace clang {
40 namespace tidy {
41 namespace cert {
42 
43 class CERTModule : public ClangTidyModule {
44 public:
45  void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
46  // C++ checkers
47  // CON
49  "cert-con54-cpp");
50  // DCL
51  CheckFactories.registerCheck<PostfixOperatorCheck>(
52  "cert-dcl21-cpp");
53  CheckFactories.registerCheck<VariadicFunctionDefCheck>("cert-dcl50-cpp");
55  "cert-dcl51-cpp");
57  "cert-dcl54-cpp");
59  "cert-dcl58-cpp");
61  "cert-dcl59-cpp");
62  // ERR
64  "cert-err09-cpp");
65  CheckFactories.registerCheck<SetLongJmpCheck>("cert-err52-cpp");
66  CheckFactories.registerCheck<StaticObjectExceptionCheck>("cert-err58-cpp");
67  CheckFactories.registerCheck<ThrownExceptionTypeCheck>("cert-err60-cpp");
69  "cert-err61-cpp");
70  // MEM
72  "cert-mem57-cpp");
73  // MSC
74  CheckFactories.registerCheck<LimitedRandomnessCheck>("cert-msc50-cpp");
76  "cert-msc51-cpp");
77  // OOP
79  "cert-oop11-cpp");
81  "cert-oop54-cpp");
83  "cert-oop57-cpp");
84  CheckFactories.registerCheck<MutatingCopyCheck>(
85  "cert-oop58-cpp");
86 
87  // C checkers
88  // CON
90  "cert-con36-c");
91  // DCL
92  CheckFactories.registerCheck<misc::StaticAssertCheck>("cert-dcl03-c");
94  "cert-dcl16-c");
96  "cert-dcl37-c");
97  // ENV
98  CheckFactories.registerCheck<CommandProcessorCheck>("cert-env33-c");
99  // FLP
100  CheckFactories.registerCheck<FloatLoopCounter>("cert-flp30-c");
101  // FIO
102  CheckFactories.registerCheck<misc::NonCopyableObjectsCheck>("cert-fio38-c");
103  // ERR
104  CheckFactories.registerCheck<StrToNumCheck>("cert-err34-c");
105  // MSC
106  CheckFactories.registerCheck<LimitedRandomnessCheck>("cert-msc30-c");
108  "cert-msc32-c");
109  // POS
111  "cert-pos44-c");
112  // STR
114  "cert-str34-c");
115  }
116 
118  ClangTidyOptions Options;
120  Opts["cert-dcl16-c.NewSuffixes"] = "L;LL;LU;LLU";
121  Opts["cert-oop54-cpp.WarnOnlyIfThisHasSuspiciousField"] = "0";
122  Opts["cert-str34-c.DiagnoseSignedUnsignedCharComparisons"] = "0";
123  return Options;
124  }
125 };
126 
127 } // namespace cert
128 
129 // Register the MiscTidyModule using this statically initialized variable.
130 static ClangTidyModuleRegistry::Add<cert::CERTModule>
131  X("cert-module",
132  "Adds lint checks corresponding to CERT secure coding guidelines.");
133 
134 // This anchor is used to force the linker to link in the generated object file
135 // and thus register the CERTModule.
136 volatile int CERTModuleAnchorSource = 0;
137 
138 } // namespace tidy
139 } // namespace clang
clang::tidy::misc::NewDeleteOverloadsCheck
Definition: NewDeleteOverloadsCheck.h:20
clang::tidy::misc::NonCopyableObjectsCheck
The check flags dereferences and non-pointer declarations of objects that are not meant to be passed ...
Definition: NonCopyableObjects.h:20
clang::tidy::cert::DefaultOperatorNewAlignmentCheck
Checks if an object of type with extended alignment is allocated by using the default operator new.
Definition: DefaultOperatorNewAlignmentCheck.h:23
clang::tidy::cert::CommandProcessorCheck
Execution of a command processor can lead to security vulnerabilities, and is generally not required.
Definition: CommandProcessorCheck.h:25
LimitedRandomnessCheck.h
CommandProcessorCheck.h
clang::tidy::cert::LimitedRandomnessCheck
Pseudorandom number generators are not genuinely random.
Definition: LimitedRandomnessCheck.h:25
clang::tidy::performance::MoveConstructorInitCheck
The check flags user-defined move constructors that have a ctor-initializer initializing a member or ...
Definition: MoveConstructorInitCheck.h:26
clang::tidy::cert::PostfixOperatorCheck
Checks if the overloaded postfix ++ and – operator return a constant object.
Definition: PostfixOperatorCheck.h:23
clang::tidy::cert::VariadicFunctionDefCheck
Guards against any C-style variadic function definitions (not declarations).
Definition: VariadicFunctionDefCheck.h:22
clang::tidy::bugprone::BadSignalToKillThreadCheck
Finds pthread_kill function calls when thread is terminated by SIGTERM signal.
Definition: BadSignalToKillThreadCheck.h:22
clang::tidy::ClangTidyOptions::CheckOptions
OptionMap CheckOptions
Key-value mapping used to store check-specific options.
Definition: ClangTidyOptions.h:114
clang::tidy::cert::DontModifyStdNamespaceCheck
Modification of the std or posix namespace can result in undefined behavior.
Definition: DontModifyStdNamespaceCheck.h:23
ProperlySeededRandomGeneratorCheck.h
MutatingCopyCheck.h
clang::tidy::bugprone::SignedCharMisuseCheck
Finds those signed char -> integer conversions which might indicate a programming error.
Definition: SignedCharMisuseCheck.h:26
clang::tidy::ClangTidyOptions
Contains options for clang-tidy.
Definition: ClangTidyOptions.h:50
clang::tidy::bugprone::UnhandledSelfAssignmentCheck
Finds user-defined copy assignment operators which do not protect the code against self-assignment ei...
Definition: UnhandledSelfAssignmentCheck.h:24
clang::tidy::ClangTidyCheckFactories
A collection of ClangTidyCheckFactory instances.
Definition: ClangTidyModule.h:30
clang::tidy::readability::UppercaseLiteralSuffixCheck
Detects when the integral literal or floating point literal has non-uppercase suffix,...
Definition: UppercaseLiteralSuffixCheck.h:25
clang::tidy::bugprone::SpuriouslyWakeUpFunctionsCheck
Finds cnd_wait, cnd_timedwait, wait, wait_for, or wait_until function calls when the function is not ...
Definition: SpuriouslyWakeUpFunctionsCheck.h:25
clang::tidy::cert::StaticObjectExceptionCheck
Checks whether the constructor for a static or thread_local object will throw.
Definition: StaticObjectExceptionCheck.h:23
StrToNumCheck.h
clang::tidy::cert::ThrownExceptionTypeCheck
Checks whether a thrown object is nothrow copy constructible.
Definition: ThrownExceptionTypeCheck.h:22
clang::tidy::cert::FloatLoopCounter
This check diagnoses when the loop induction expression of a for loop has floating-point type.
Definition: FloatLoopCounter.h:24
clang::tidy::cert::ProperlySeededRandomGeneratorCheck
Random number generator must be seeded properly.
Definition: ProperlySeededRandomGeneratorCheck.h:26
clang::tidy::cert::MutatingCopyCheck
Finds assignments to the copied object and its direct or indirect members in copy constructors and co...
Definition: MutatingCopyCheck.h:23
clang::tidy::misc::StaticAssertCheck
Replaces assert() with static_assert() if the condition is evaluatable at compile time.
Definition: StaticAssertCheck.h:25
clang::tidy::cert::StrToNumCheck
Guards against use of string conversion functions that do not have reasonable error handling for conv...
Definition: StrToNumCheck.h:23
ThrownExceptionTypeCheck.h
clang::tidy::X
static ClangTidyModuleRegistry::Add< bugprone::BugproneModule > X("bugprone-module", "Adds checks for bugprone code constructs.")
clang::tidy::google::build::UnnamedNamespaceInHeaderCheck
Finds anonymous namespaces in headers.
Definition: UnnamedNamespaceInHeaderCheck.h:33
DefaultOperatorNewAlignmentCheck.h
NonTrivialTypesLibcMemoryCallsCheck.h
StaticObjectExceptionCheck.h
SetLongJmpCheck.h
clang::tidy::bugprone::ReservedIdentifierCheck
Checks for usages of identifiers reserved for use by the implementation.
Definition: ReservedIdentifierCheck.h:33
clang::tidy::cert::NonTrivialTypesLibcMemoryCallsCheck
Flags use of the C standard library functions 'memset', 'memcpy' and 'memcmp' and similar derivatives...
Definition: NonTrivialTypesLibcMemoryCallsCheck.h:23
clang::tidy::cert::CERTModule
Definition: CERTTidyModule.cpp:43
clang::tidy::cert::CERTModule::getModuleOptions
ClangTidyOptions getModuleOptions() override
Gets default options for checks defined in this module.
Definition: CERTTidyModule.cpp:117
clang::tidy::CERTModuleAnchorSource
volatile int CERTModuleAnchorSource
Definition: CERTTidyModule.cpp:136
FloatLoopCounter.h
PostfixOperatorCheck.h
clang::tidy::cert::SetLongJmpCheck
Guards against use of setjmp/longjmp in C++ code.
Definition: SetLongJmpCheck.h:22
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition: ApplyReplacements.h:27
clang::tidy::cert::CERTModule::addCheckFactories
void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override
Implement this function in order to register all CheckFactories belonging to this module.
Definition: CERTTidyModule.cpp:45
clang::tidy::misc::ThrowByValueCatchByReferenceCheck
checks for locations that do not throw by value
Definition: ThrowByValueCatchByReferenceCheck.h:29
DontModifyStdNamespaceCheck.h
clang::tidy::ClangTidyModule
A clang-tidy module groups a number of ClangTidyChecks and gives them a prefixed name.
Definition: ClangTidyModule.h:83
clang::tidy::ClangTidyOptions::OptionMap
std::map< std::string, ClangTidyValue > OptionMap
Definition: ClangTidyOptions.h:111
clang::tidy::ClangTidyCheckFactories::registerCheck
void registerCheck(llvm::StringRef CheckName)
Registers the CheckType with the name Name.
Definition: ClangTidyModule.h:61
VariadicFunctionDefCheck.h