clang-tools  14.0.0git
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/SignalHandlerCheck.h"
15 #include "../bugprone/SignedCharMisuseCheck.h"
16 #include "../bugprone/SpuriouslyWakeUpFunctionsCheck.h"
17 #include "../bugprone/SuspiciousMemoryComparisonCheck.h"
18 #include "../bugprone/UnhandledSelfAssignmentCheck.h"
19 #include "../concurrency/ThreadCanceltypeAsynchronousCheck.h"
20 #include "../google/UnnamedNamespaceInHeaderCheck.h"
21 #include "../misc/NewDeleteOverloadsCheck.h"
22 #include "../misc/NonCopyableObjects.h"
23 #include "../misc/StaticAssertCheck.h"
24 #include "../misc/ThrowByValueCatchByReferenceCheck.h"
25 #include "../performance/MoveConstructorInitCheck.h"
26 #include "../readability/UppercaseLiteralSuffixCheck.h"
27 #include "CommandProcessorCheck.h"
30 #include "FloatLoopCounter.h"
31 #include "LimitedRandomnessCheck.h"
32 #include "MutatingCopyCheck.h"
34 #include "PostfixOperatorCheck.h"
36 #include "SetLongJmpCheck.h"
38 #include "StrToNumCheck.h"
41 
42 namespace clang {
43 namespace tidy {
44 namespace cert {
45 
46 class CERTModule : public ClangTidyModule {
47 public:
48  void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
49  // C++ checkers
50  // CON
52  "cert-con54-cpp");
53  // DCL
54  CheckFactories.registerCheck<PostfixOperatorCheck>(
55  "cert-dcl21-cpp");
56  CheckFactories.registerCheck<VariadicFunctionDefCheck>("cert-dcl50-cpp");
58  "cert-dcl51-cpp");
60  "cert-dcl54-cpp");
62  "cert-dcl58-cpp");
64  "cert-dcl59-cpp");
65  // ERR
67  "cert-err09-cpp");
68  CheckFactories.registerCheck<SetLongJmpCheck>("cert-err52-cpp");
69  CheckFactories.registerCheck<StaticObjectExceptionCheck>("cert-err58-cpp");
70  CheckFactories.registerCheck<ThrownExceptionTypeCheck>("cert-err60-cpp");
72  "cert-err61-cpp");
73  // MEM
75  "cert-mem57-cpp");
76  // MSC
77  CheckFactories.registerCheck<LimitedRandomnessCheck>("cert-msc50-cpp");
79  "cert-msc51-cpp");
80  // OOP
82  "cert-oop11-cpp");
84  "cert-oop54-cpp");
86  "cert-oop57-cpp");
87  CheckFactories.registerCheck<MutatingCopyCheck>(
88  "cert-oop58-cpp");
89 
90  // C checkers
91  // CON
93  "cert-con36-c");
94  // DCL
95  CheckFactories.registerCheck<misc::StaticAssertCheck>("cert-dcl03-c");
97  "cert-dcl16-c");
99  "cert-dcl37-c");
100  // ENV
101  CheckFactories.registerCheck<CommandProcessorCheck>("cert-env33-c");
102  // EXP
104  "cert-exp42-c");
105  // FLP
106  CheckFactories.registerCheck<FloatLoopCounter>("cert-flp30-c");
108  "cert-flp37-c");
109  // FIO
110  CheckFactories.registerCheck<misc::NonCopyableObjectsCheck>("cert-fio38-c");
111  // ERR
112  CheckFactories.registerCheck<StrToNumCheck>("cert-err34-c");
113  // MSC
114  CheckFactories.registerCheck<LimitedRandomnessCheck>("cert-msc30-c");
116  "cert-msc32-c");
117  // POS
119  "cert-pos44-c");
120  CheckFactories
122  "cert-pos47-c");
123  // SIG
124  CheckFactories.registerCheck<bugprone::SignalHandlerCheck>("cert-sig30-c");
125  // STR
127  "cert-str34-c");
128  }
129 
131  ClangTidyOptions Options;
133  Opts["cert-dcl16-c.NewSuffixes"] = "L;LL;LU;LLU";
134  Opts["cert-oop54-cpp.WarnOnlyIfThisHasSuspiciousField"] = "false";
135  Opts["cert-str34-c.DiagnoseSignedUnsignedCharComparisons"] = "false";
136  return Options;
137  }
138 };
139 
140 } // namespace cert
141 
142 // Register the MiscTidyModule using this statically initialized variable.
143 static ClangTidyModuleRegistry::Add<cert::CERTModule>
144  X("cert-module",
145  "Adds lint checks corresponding to CERT secure coding guidelines.");
146 
147 // This anchor is used to force the linker to link in the generated object file
148 // and thus register the CERTModule.
149 volatile int CERTModuleAnchorSource = 0;
150 
151 } // namespace tidy
152 } // namespace clang
clang::tidy::bugprone::SignalHandlerCheck
Checker for signal handler functions.
Definition: SignalHandlerCheck.h:23
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
clang::tidy::ClangTidyOptions::OptionMap
llvm::StringMap< ClangTidyValue > OptionMap
Definition: ClangTidyOptions.h:115
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:23
clang::tidy::bugprone::SuspiciousMemoryComparisonCheck
Finds potentially incorrect calls to memcmp() based on properties of the arguments.
Definition: SuspiciousMemoryComparisonCheck.h:23
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:118
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:28
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::google::build::UnnamedNamespaceInHeaderCheck
Finds anonymous namespaces in headers.
Definition: UnnamedNamespaceInHeaderCheck.h:36
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:46
clang::tidy::cert::CERTModule::getModuleOptions
ClangTidyOptions getModuleOptions() override
Gets default options for checks defined in this module.
Definition: CERTTidyModule.cpp:130
clang::tidy::CERTModuleAnchorSource
volatile int CERTModuleAnchorSource
Definition: CERTTidyModule.cpp:149
FloatLoopCounter.h
PostfixOperatorCheck.h
clang::tidy::concurrency::ThreadCanceltypeAsynchronousCheck
Finds pthread_setcanceltype function calls where a thread's cancellation type is set to asynchronous.
Definition: ThreadCanceltypeAsynchronousCheck.h:22
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:48
clang::tidy::misc::ThrowByValueCatchByReferenceCheck
checks for locations that do not throw by value
Definition: ThrowByValueCatchByReferenceCheck.h:29
DontModifyStdNamespaceCheck.h
clang::tidy::X
static ClangTidyModuleRegistry::Add< altera::AlteraModule > X("altera-module", "Adds Altera FPGA OpenCL lint checks.")
clang::tidy::ClangTidyModule
A clang-tidy module groups a number of ClangTidyChecks and gives them a prefixed name.
Definition: ClangTidyModule.h:81
clang::tidy::ClangTidyCheckFactories::registerCheck
void registerCheck(llvm::StringRef CheckName)
Registers the CheckType with the name Name.
Definition: ClangTidyModule.h:59
VariadicFunctionDefCheck.h