clang-tools  12.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/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
Finds cnd_wait, cnd_timedwait, wait, wait_for, or wait_until function calls when the function is not ...
Checks if the overloaded postfix ++ and – operator return a constant object.
Pseudorandom number generators are not genuinely random.
void registerCheck(llvm::StringRef CheckName)
Registers the CheckType with the name Name.
Detects when the integral literal or floating point literal has non-uppercase suffix, and suggests to make the suffix uppercase.
checks for locations that do not throw by value
Finds those signed char -> integer conversions which might indicate a programming error...
Replaces assert() with static_assert() if the condition is evaluatable at compile time...
Checks for usages of identifiers reserved for use by the implementation.
Finds pthread_kill function calls when thread is terminated by SIGTERM signal.
Contains options for clang-tidy.
Execution of a command processor can lead to security vulnerabilities, and is generally not required...
A collection of ClangTidyCheckFactory instances.
OptionMap CheckOptions
Key-value mapping used to store check-specific options.
Guards against use of string conversion functions that do not have reasonable error handling for conv...
Definition: StrToNumCheck.h:23
Checks whether the constructor for a static or thread_local object will throw.
A clang-tidy module groups a number of ClangTidyChecks and gives them a prefixed name.
Flags use of the C standard library functions &#39;memset&#39;, &#39;memcpy&#39; and &#39;memcmp&#39; and similar derivatives...
Finds user-defined copy assignment operators which do not protect the code against self-assignment ei...
The check flags dereferences and non-pointer declarations of objects that are not meant to be passed ...
The check flags user-defined move constructors that have a ctor-initializer initializing a member or ...
Checks whether a thrown object is nothrow copy constructible.
Guards against use of setjmp/longjmp in C++ code.
volatile int CERTModuleAnchorSource
static ClangTidyModuleRegistry::Add< bugprone::BugproneModule > X("bugprone-module", "Adds checks for bugprone code constructs.")
Finds assignments to the copied object and its direct or indirect members in copy constructors and co...
This check diagnoses when the loop induction expression of a for loop has floating-point type...
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
ClangTidyOptions getModuleOptions() override
Gets default options for checks defined in this module.
Checks if an object of type with extended alignment is allocated by using the default operator new...
Modification of the std or posix namespace can result in undefined behavior.
void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override
Implement this function in order to register all CheckFactories belonging to this module...
std::map< std::string, ClangTidyValue > OptionMap
Guards against any C-style variadic function definitions (not declarations).