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"
24 #include "FloatLoopCounter.h"
25 #include "LimitedRandomnessCheck.h"
26 #include "MutatingCopyCheck.h"
27 #include "PostfixOperatorCheck.h"
29 #include "SetLongJmpCheck.h"
31 #include "StrToNumCheck.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");
48  "cert-dcl54-cpp");
50  "cert-dcl58-cpp");
52  "cert-dcl59-cpp");
53  // ERR
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");
60  "cert-err61-cpp");
61  // MEM
63  "cert-mem57-cpp");
64  // MSC
65  CheckFactories.registerCheck<LimitedRandomnessCheck>("cert-msc50-cpp");
67  "cert-msc51-cpp");
68  // OOP
70  "cert-oop11-cpp");
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");
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");
92  "cert-msc32-c");
93  // POS
95  "cert-pos44-c");
96  }
97 
99  ClangTidyOptions Options;
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
Checks if the overloaded postfix ++ and – operator return a constant object.
Pseudorandom number generators are not genuinely random.
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
void registerCheck(StringRef CheckName)
Registers the CheckType with the name Name.
Replaces assert() with static_assert() if the condition is evaluatable at compile time...
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.
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...
std::map< std::string, std::string > OptionMap
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...
Guards against any C-style variadic function definitions (not declarations).