clang-tools 10.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/UnhandledSelfAssignmentCheck.h"
13 #include "../bugprone/BadSignalToKillThreadCheck.h"
14 #include "../google/UnnamedNamespaceInHeaderCheck.h"
15 #include "../misc/NewDeleteOverloadsCheck.h"
16 #include "../misc/NonCopyableObjects.h"
17 #include "../misc/StaticAssertCheck.h"
18 #include "../misc/ThrowByValueCatchByReferenceCheck.h"
19 #include "../performance/MoveConstructorInitCheck.h"
20 #include "../readability/UppercaseLiteralSuffixCheck.h"
21 #include "CommandProcessorCheck.h"
22 #include "DefaultOperatorNewAlignmentCheck.h"
23 #include "DontModifyStdNamespaceCheck.h"
24 #include "FloatLoopCounter.h"
25 #include "LimitedRandomnessCheck.h"
26 #include "MutatingCopyCheck.h"
27 #include "PostfixOperatorCheck.h"
28 #include "ProperlySeededRandomGeneratorCheck.h"
29 #include "SetLongJmpCheck.h"
30 #include "StaticObjectExceptionCheck.h"
31 #include "StrToNumCheck.h"
32 #include "ThrownExceptionTypeCheck.h"
33 #include "VariadicFunctionDefCheck.h"
34
35 namespace clang {
36 namespace tidy {
37 namespace cert {
38
39 class CERTModule : public ClangTidyModule {
40 public:
41 void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
42 // C++ checkers
43 // DCL
44 CheckFactories.registerCheck<PostfixOperatorCheck>(
45 "cert-dcl21-cpp");
46 CheckFactories.registerCheck<VariadicFunctionDefCheck>("cert-dcl50-cpp");
47 CheckFactories.registerCheck<misc::NewDeleteOverloadsCheck>(
48 "cert-dcl54-cpp");
49 CheckFactories.registerCheck<DontModifyStdNamespaceCheck>(
50 "cert-dcl58-cpp");
51 CheckFactories.registerCheck<google::build::UnnamedNamespaceInHeaderCheck>(
52 "cert-dcl59-cpp");
53 // ERR
54 CheckFactories.registerCheck<misc::ThrowByValueCatchByReferenceCheck>(
55 "cert-err09-cpp");
56 CheckFactories.registerCheck<SetLongJmpCheck>("cert-err52-cpp");
57 CheckFactories.registerCheck<StaticObjectExceptionCheck>("cert-err58-cpp");
58 CheckFactories.registerCheck<ThrownExceptionTypeCheck>("cert-err60-cpp");
59 CheckFactories.registerCheck<misc::ThrowByValueCatchByReferenceCheck>(
60 "cert-err61-cpp");
61 // MEM
62 CheckFactories.registerCheck<DefaultOperatorNewAlignmentCheck>(
63 "cert-mem57-cpp");
64 // MSC
65 CheckFactories.registerCheck<LimitedRandomnessCheck>("cert-msc50-cpp");
66 CheckFactories.registerCheck<ProperlySeededRandomGeneratorCheck>(
67 "cert-msc51-cpp");
68 // OOP
69 CheckFactories.registerCheck<performance::MoveConstructorInitCheck>(
70 "cert-oop11-cpp");
71 CheckFactories.registerCheck<bugprone::UnhandledSelfAssignmentCheck>(
72 "cert-oop54-cpp");
73 CheckFactories.registerCheck<MutatingCopyCheck>(
74 "cert-oop58-cpp");
75
76 // C checkers
77 // DCL
78 CheckFactories.registerCheck<misc::StaticAssertCheck>("cert-dcl03-c");
79 CheckFactories.registerCheck<readability::UppercaseLiteralSuffixCheck>(
80 "cert-dcl16-c");
81 // ENV
82 CheckFactories.registerCheck<CommandProcessorCheck>("cert-env33-c");
83 // FLP
84 CheckFactories.registerCheck<FloatLoopCounter>("cert-flp30-c");
85 // FIO
86 CheckFactories.registerCheck<misc::NonCopyableObjectsCheck>("cert-fio38-c");
87 // ERR
88 CheckFactories.registerCheck<StrToNumCheck>("cert-err34-c");
89 // MSC
90 CheckFactories.registerCheck<LimitedRandomnessCheck>("cert-msc30-c");
91 CheckFactories.registerCheck<ProperlySeededRandomGeneratorCheck>(
92 "cert-msc32-c");
93 // POS
94 CheckFactories.registerCheck<bugprone::BadSignalToKillThreadCheck>(
95 "cert-pos44-c");
96 }
97
98 ClangTidyOptions getModuleOptions() override {
99 ClangTidyOptions Options;
100 ClangTidyOptions::OptionMap &Opts = Options.CheckOptions;
101 Opts["cert-dcl16-c.NewSuffixes"] = "L;LL;LU;LLU";
102 Opts["cert-oop54-cpp.WarnOnlyIfThisHasSuspiciousField"] = "0";
103 return Options;
104 }
105 };
106
107 } // namespace cert
108
109 // Register the MiscTidyModule using this statically initialized variable.
110 static ClangTidyModuleRegistry::Add<cert::CERTModule>
111 X("cert-module",
112 "Adds lint checks corresponding to CERT secure coding guidelines.");
113
114 // This anchor is used to force the linker to link in the generated object file
115 // and thus register the CERTModule.
116 volatile int CERTModuleAnchorSource = 0;
117
118 } // namespace tidy
119 } // namespace clang
clang::tidy::cert::PostfixOperatorCheck
Checks if the overloaded postfix ++ and – operator return a constant object.
Definition: PostfixOperatorCheck.h:23
PostfixOperatorCheck.h
clang::tidy::cert::LimitedRandomnessCheck
Pseudorandom number generators are not genuinely random.
Definition: LimitedRandomnessCheck.h:25
clang::tidy::readability::UppercaseLiteralSuffixCheck
Detects when the integral literal or floating point literal has non-uppercase suffix, and suggests to make the suffix uppercase.
Definition: UppercaseLiteralSuffixCheck.h:25
clang::tidy::misc::ThrowByValueCatchByReferenceCheck
checks for locations that do not throw by value
Definition: ThrowByValueCatchByReferenceCheck.h:29
clang::tidy::ClangTidyCheckFactories::registerCheck
void registerCheck(StringRef CheckName)
Registers the CheckType with the name Name.
Definition: ClangTidyModule.h:58
clang::tidy::misc::StaticAssertCheck
Replaces assert() with static_assert() if the condition is evaluatable at compile time...
Definition: StaticAssertCheck.h:25
clang::tidy::bugprone::BadSignalToKillThreadCheck
Finds pthread_kill function calls when thread is terminated by SIGTERM signal.
Definition: BadSignalToKillThreadCheck.h:22
MutatingCopyCheck.h
clang::tidy::ClangTidyOptions
Contains options for clang-tidy.
Definition: ClangTidyOptions.h:50
SetLongJmpCheck.h
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::ClangTidyCheckFactories
A collection of ClangTidyCheckFactory instances.
Definition: ClangTidyModule.h:27
clang::tidy::cert::CERTModule
Definition: CERTTidyModule.cpp:39
clang::tidy::ClangTidyOptions::CheckOptions
OptionMap CheckOptions
Key-value mapping used to store check-specific options.
Definition: ClangTidyOptions.h:100
ThrownExceptionTypeCheck.h
clang::tidy::cert::StrToNumCheck
Guards against use of string conversion functions that do not have reasonable error handling for conv...
Definition: StrToNumCheck.h:23
StaticObjectExceptionCheck.h
clang::tidy::cert::StaticObjectExceptionCheck
Checks whether the constructor for a static or thread_local object will throw.
Definition: StaticObjectExceptionCheck.h:23
clang::tidy::ClangTidyModule
A clang-tidy module groups a number of ClangTidyChecks and gives them a prefixed name.
Definition: ClangTidyModule.h:80
clang::tidy::bugprone::UnhandledSelfAssignmentCheck
Finds user-defined copy assignment operators which do not protect the code against self-assignment ei...
Definition: UnhandledSelfAssignmentCheck.h:24
DefaultOperatorNewAlignmentCheck.h
ProperlySeededRandomGeneratorCheck.h
LimitedRandomnessCheck.h
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::google::build::UnnamedNamespaceInHeaderCheck
Finds anonymous namespaces in headers.
Definition: UnnamedNamespaceInHeaderCheck.h:32
VariadicFunctionDefCheck.h
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::ThrownExceptionTypeCheck
Checks whether a thrown object is nothrow copy constructible.
Definition: ThrownExceptionTypeCheck.h:22
clang::tidy::cert::SetLongJmpCheck
Guards against use of setjmp/longjmp in C++ code.
Definition: SetLongJmpCheck.h:22
clang::tidy::CERTModuleAnchorSource
volatile int CERTModuleAnchorSource
Definition: CERTTidyModule.cpp:116
clang::tidy::X
static ClangTidyModuleRegistry::Add< bugprone::BugproneModule > X("bugprone-module", "Adds checks for bugprone code constructs.")
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::ClangTidyOptions::OptionMap
std::map< std::string, std::string > OptionMap
Definition: ClangTidyOptions.h:97
CommandProcessorCheck.h
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
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition: ApplyReplacements.h:27
clang::tidy::cert::CERTModule::getModuleOptions
ClangTidyOptions getModuleOptions() override
Gets default options for checks defined in this module.
Definition: CERTTidyModule.cpp:98
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::DontModifyStdNamespaceCheck
Modification of the std or posix namespace can result in undefined behavior.
Definition: DontModifyStdNamespaceCheck.h:23
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:41
clang::tidy::cert::ProperlySeededRandomGeneratorCheck
Random number generator must be seeded properly.
Definition: ProperlySeededRandomGeneratorCheck.h:26
StrToNumCheck.h
FloatLoopCounter.h
clang::tidy::cert::VariadicFunctionDefCheck
Guards against any C-style variadic function definitions (not declarations).
Definition: VariadicFunctionDefCheck.h:22
DontModifyStdNamespaceCheck.h