clang-tools 8.0.0

CERTTidyModule.cpp
Go to the documentation of this file.
1 //===--- CERTTidyModule.cpp - clang-tidy ----------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #include "../ClangTidy.h"
11 #include "../ClangTidyModule.h"
12 #include "../ClangTidyModuleRegistry.h"
13 #include "../google/UnnamedNamespaceInHeaderCheck.h"
14 #include "../misc/NewDeleteOverloadsCheck.h"
15 #include "../misc/NonCopyableObjects.h"
16 #include "../misc/StaticAssertCheck.h"
17 #include "../misc/ThrowByValueCatchByReferenceCheck.h"
18 #include "../performance/MoveConstructorInitCheck.h"
19 #include "../readability/UppercaseLiteralSuffixCheck.h"
20 #include "CommandProcessorCheck.h"
21 #include "DontModifyStdNamespaceCheck.h"
22 #include "FloatLoopCounter.h"
23 #include "LimitedRandomnessCheck.h"
24 #include "PostfixOperatorCheck.h"
25 #include "ProperlySeededRandomGeneratorCheck.h"
26 #include "SetLongJmpCheck.h"
27 #include "StaticObjectExceptionCheck.h"
28 #include "StrToNumCheck.h"
29 #include "ThrownExceptionTypeCheck.h"
30 #include "VariadicFunctionDefCheck.h"
31
32 namespace clang {
33 namespace tidy {
34 namespace cert {
35
36 class CERTModule : public ClangTidyModule {
37 public:
38 void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
39 // C++ checkers
40 // DCL
41 CheckFactories.registerCheck<PostfixOperatorCheck>(
42 "cert-dcl21-cpp");
43 CheckFactories.registerCheck<VariadicFunctionDefCheck>("cert-dcl50-cpp");
44 CheckFactories.registerCheck<misc::NewDeleteOverloadsCheck>(
45 "cert-dcl54-cpp");
46 CheckFactories.registerCheck<DontModifyStdNamespaceCheck>(
47 "cert-dcl58-cpp");
48 CheckFactories.registerCheck<google::build::UnnamedNamespaceInHeaderCheck>(
49 "cert-dcl59-cpp");
50 // OOP
51 CheckFactories.registerCheck<performance::MoveConstructorInitCheck>(
52 "cert-oop11-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 // MSC
62 CheckFactories.registerCheck<LimitedRandomnessCheck>("cert-msc50-cpp");
63 CheckFactories.registerCheck<ProperlySeededRandomGeneratorCheck>(
64 "cert-msc51-cpp");
65
66 // C checkers
67 // DCL
68 CheckFactories.registerCheck<misc::StaticAssertCheck>("cert-dcl03-c");
69 CheckFactories.registerCheck<readability::UppercaseLiteralSuffixCheck>(
70 "cert-dcl16-c");
71 // ENV
72 CheckFactories.registerCheck<CommandProcessorCheck>("cert-env33-c");
73 // FLP
74 CheckFactories.registerCheck<FloatLoopCounter>("cert-flp30-c");
75 // FIO
76 CheckFactories.registerCheck<misc::NonCopyableObjectsCheck>("cert-fio38-c");
77 // ERR
78 CheckFactories.registerCheck<StrToNumCheck>("cert-err34-c");
79 // MSC
80 CheckFactories.registerCheck<LimitedRandomnessCheck>("cert-msc30-c");
81 CheckFactories.registerCheck<ProperlySeededRandomGeneratorCheck>(
82 "cert-msc32-c");
83 }
84
85 ClangTidyOptions getModuleOptions() override {
86 ClangTidyOptions Options;
87 ClangTidyOptions::OptionMap &Opts = Options.CheckOptions;
88 Opts["cert-dcl16-c.NewSuffixes"] = "L;LL;LU;LLU";
89 return Options;
90 }
91 };
92
93 } // namespace cert
94
95 // Register the MiscTidyModule using this statically initialized variable.
96 static ClangTidyModuleRegistry::Add<cert::CERTModule>
97 X("cert-module",
98 "Adds lint checks corresponding to CERT secure coding guidelines.");
99
100 // This anchor is used to force the linker to link in the generated object file
101 // and thus register the CERTModule.
102 volatile int CERTModuleAnchorSource = 0;
103
104 } // namespace tidy
105 } // namespace clang
clang::tidy::cert::PostfixOperatorCheck
Checks if the overloaded postfix ++ and – operator return a constant object.
Definition: PostfixOperatorCheck.h:24
PostfixOperatorCheck.h
clang::tidy::cert::LimitedRandomnessCheck
Pseudorandom number generators are not genuinely random.
Definition: LimitedRandomnessCheck.h:26
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:26
clang::tidy::misc::ThrowByValueCatchByReferenceCheck
checks for locations that do not throw by value
Definition: ThrowByValueCatchByReferenceCheck.h:30
clang::tidy::ClangTidyCheckFactories::registerCheck
void registerCheck(StringRef CheckName)
Registers the CheckType with the name Name.
Definition: ClangTidyModule.h:59
clang::tidy::misc::StaticAssertCheck
Replaces assert() with static_assert() if the condition is evaluatable at compile time...
Definition: StaticAssertCheck.h:26
clang::tidy::ClangTidyOptions
Contains options for clang-tidy.
Definition: ClangTidyOptions.h:51
SetLongJmpCheck.h
clang::tidy::cert::CommandProcessorCheck
Execution of a command processor can lead to security vulnerabilities, and is generally not required...
Definition: CommandProcessorCheck.h:26
clang::tidy::ClangTidyCheckFactories
A collection of ClangTidyCheckFactory instances.
Definition: ClangTidyModule.h:27
clang::tidy::cert::CERTModule
Definition: CERTTidyModule.cpp:36
clang::tidy::ClangTidyOptions::CheckOptions
OptionMap CheckOptions
Key-value mapping used to store check-specific options.
Definition: ClangTidyOptions.h:101
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:24
StaticObjectExceptionCheck.h
clang::tidy::cert::StaticObjectExceptionCheck
Checks whether the constructor for a static or thread_local object will throw.
Definition: StaticObjectExceptionCheck.h:24
clang::tidy::ClangTidyModule
A clang-tidy module groups a number of ClangTidyChecks and gives them a prefixed name.
Definition: ClangTidyModule.h:84
ProperlySeededRandomGeneratorCheck.h
LimitedRandomnessCheck.h
clang::tidy::misc::NewDeleteOverloadsCheck
Definition: NewDeleteOverloadsCheck.h:21
clang::tidy::misc::NonCopyableObjectsCheck
The check flags dereferences and non-pointer declarations of objects that are not meant to be passed ...
Definition: NonCopyableObjects.h:21
clang::tidy::google::build::UnnamedNamespaceInHeaderCheck
Finds anonymous namespaces in headers.
Definition: UnnamedNamespaceInHeaderCheck.h:33
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:27
clang::tidy::cert::ThrownExceptionTypeCheck
Checks whether a thrown object is nothrow copy constructible.
Definition: ThrownExceptionTypeCheck.h:23
clang::tidy::cert::SetLongJmpCheck
Guards against use of setjmp/longjmp in C++ code.
Definition: SetLongJmpCheck.h:23
clang::tidy::CERTModuleAnchorSource
volatile int CERTModuleAnchorSource
Definition: CERTTidyModule.cpp:102
clang::tidy::X
static ClangTidyModuleRegistry::Add< bugprone::BugproneModule > X("bugprone-module", "Adds checks for bugprone code constructs.")
clang::tidy::ClangTidyOptions::OptionMap
std::map< std::string, std::string > OptionMap
Definition: ClangTidyOptions.h:98
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:25
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition: ChangeNamespace.cpp:18
clang::tidy::cert::CERTModule::getModuleOptions
ClangTidyOptions getModuleOptions() override
Gets default options for checks defined in this module.
Definition: CERTTidyModule.cpp:85
clang::tidy::cert::DontModifyStdNamespaceCheck
Modification of the std or posix namespace can result in undefined behavior.
Definition: DontModifyStdNamespaceCheck.h:24
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:38
clang::tidy::cert::ProperlySeededRandomGeneratorCheck
Random number generator must be seeded properly.
Definition: ProperlySeededRandomGeneratorCheck.h:27
StrToNumCheck.h
FloatLoopCounter.h
clang::tidy::cert::VariadicFunctionDefCheck
Guards against any C-style variadic function definitions (not declarations).
Definition: VariadicFunctionDefCheck.h:23
DontModifyStdNamespaceCheck.h