clang-tools  10.0.0svn
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 "../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"
22 #include "FloatLoopCounter.h"
23 #include "LimitedRandomnessCheck.h"
24 #include "PostfixOperatorCheck.h"
26 #include "SetLongJmpCheck.h"
28 #include "StrToNumCheck.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");
45  "cert-dcl54-cpp");
47  "cert-dcl58-cpp");
49  "cert-dcl59-cpp");
50  // OOP
52  "cert-oop11-cpp");
54  "cert-oop54-cpp");
55  // ERR
57  "cert-err09-cpp");
58  CheckFactories.registerCheck<SetLongJmpCheck>("cert-err52-cpp");
59  CheckFactories.registerCheck<StaticObjectExceptionCheck>("cert-err58-cpp");
60  CheckFactories.registerCheck<ThrownExceptionTypeCheck>("cert-err60-cpp");
62  "cert-err61-cpp");
63  // MSC
64  CheckFactories.registerCheck<LimitedRandomnessCheck>("cert-msc50-cpp");
66  "cert-msc51-cpp");
67 
68  // C checkers
69  // DCL
70  CheckFactories.registerCheck<misc::StaticAssertCheck>("cert-dcl03-c");
72  "cert-dcl16-c");
73  // ENV
74  CheckFactories.registerCheck<CommandProcessorCheck>("cert-env33-c");
75  // FLP
76  CheckFactories.registerCheck<FloatLoopCounter>("cert-flp30-c");
77  // FIO
78  CheckFactories.registerCheck<misc::NonCopyableObjectsCheck>("cert-fio38-c");
79  // ERR
80  CheckFactories.registerCheck<StrToNumCheck>("cert-err34-c");
81  // MSC
82  CheckFactories.registerCheck<LimitedRandomnessCheck>("cert-msc30-c");
84  "cert-msc32-c");
85  }
86 
88  ClangTidyOptions Options;
90  Opts["cert-dcl16-c.NewSuffixes"] = "L;LL;LU;LLU";
91  Opts["cert-oop54-cpp.WarnOnlyIfThisHasSuspiciousField"] = "0";
92  return Options;
93  }
94 };
95 
96 } // namespace cert
97 
98 // Register the MiscTidyModule using this statically initialized variable.
99 static ClangTidyModuleRegistry::Add<cert::CERTModule>
100  X("cert-module",
101  "Adds lint checks corresponding to CERT secure coding guidelines.");
102 
103 // This anchor is used to force the linker to link in the generated object file
104 // and thus register the CERTModule.
105 volatile int CERTModuleAnchorSource = 0;
106 
107 } // namespace tidy
108 } // 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...
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.")
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.
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).