1 //===--- BugproneTidyModule.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 "../cppcoreguidelines/NarrowingConversionsCheck.h"
13 #include "ArgumentCommentCheck.h"
14 #include "AssertSideEffectCheck.h"
15 #include "BoolPointerImplicitConversionCheck.h"
16 #include "BranchCloneCheck.h"
17 #include "CopyConstructorInitCheck.h"
18 #include "DanglingHandleCheck.h"
19 #include "DynamicStaticInitializersCheck.h"
20 #include "ExceptionEscapeCheck.h"
21 #include "FoldInitTypeCheck.h"
22 #include "ForwardDeclarationNamespaceCheck.h"
23 #include "ForwardingReferenceOverloadCheck.h"
24 #include "InaccurateEraseCheck.h"
25 #include "IncorrectRoundingsCheck.h"
26 #include "InfiniteLoopCheck.h"
27 #include "IntegerDivisionCheck.h"
28 #include "LambdaFunctionNameCheck.h"
29 #include "MacroParenthesesCheck.h"
30 #include "MacroRepeatedSideEffectsCheck.h"
31 #include "MisplacedOperatorInStrlenInAllocCheck.h"
32 #include "MisplacedWideningCastCheck.h"
33 #include "MoveForwardingReferenceCheck.h"
34 #include "MultipleStatementMacroCheck.h"
35 #include "ParentVirtualCallCheck.h"
36 #include "PosixReturnCheck.h"
37 #include "SizeofContainerCheck.h"
38 #include "SizeofExpressionCheck.h"
39 #include "StringConstructorCheck.h"
40 #include "StringIntegerAssignmentCheck.h"
41 #include "StringLiteralWithEmbeddedNulCheck.h"
42 #include "SuspiciousEnumUsageCheck.h"
43 #include "SuspiciousMemsetUsageCheck.h"
44 #include "SuspiciousMissingCommaCheck.h"
45 #include "SuspiciousSemicolonCheck.h"
46 #include "SuspiciousStringCompareCheck.h"
47 #include "SwappedArgumentsCheck.h"
48 #include "TerminatingContinueCheck.h"
49 #include "ThrowKeywordMissingCheck.h"
50 #include "TooSmallLoopVariableCheck.h"
51 #include "UndefinedMemoryManipulationCheck.h"
52 #include "UndelegatedConstructorCheck.h"
53 #include "UnhandledSelfAssignmentCheck.h"
54 #include "UnusedRaiiCheck.h"
55 #include "UnusedReturnValueCheck.h"
56 #include "UseAfterMoveCheck.h"
57 #include "VirtualNearMissCheck.h"
58 
59 namespace clang {
60 namespace tidy {
61 namespace bugprone {
62 
63 class BugproneModule : public ClangTidyModule {
64 public:
65   void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
66     CheckFactories.registerCheck<ArgumentCommentCheck>(
67         "bugprone-argument-comment");
68     CheckFactories.registerCheck<AssertSideEffectCheck>(
69         "bugprone-assert-side-effect");
70     CheckFactories.registerCheck<BoolPointerImplicitConversionCheck>(
71         "bugprone-bool-pointer-implicit-conversion");
72     CheckFactories.registerCheck<BranchCloneCheck>(
73         "bugprone-branch-clone");
74     CheckFactories.registerCheck<CopyConstructorInitCheck>(
75         "bugprone-copy-constructor-init");
76     CheckFactories.registerCheck<DanglingHandleCheck>(
77         "bugprone-dangling-handle");
78     CheckFactories.registerCheck<DynamicStaticInitializersCheck>(
79         "bugprone-dynamic-static-initializers");
80     CheckFactories.registerCheck<ExceptionEscapeCheck>(
81         "bugprone-exception-escape");
82     CheckFactories.registerCheck<FoldInitTypeCheck>(
83         "bugprone-fold-init-type");
84     CheckFactories.registerCheck<ForwardDeclarationNamespaceCheck>(
85         "bugprone-forward-declaration-namespace");
86     CheckFactories.registerCheck<ForwardingReferenceOverloadCheck>(
87         "bugprone-forwarding-reference-overload");
88     CheckFactories.registerCheck<InaccurateEraseCheck>(
89         "bugprone-inaccurate-erase");
90     CheckFactories.registerCheck<IncorrectRoundingsCheck>(
91         "bugprone-incorrect-roundings");
92     CheckFactories.registerCheck<InfiniteLoopCheck>(
93         "bugprone-infinite-loop");
94     CheckFactories.registerCheck<IntegerDivisionCheck>(
95         "bugprone-integer-division");
96     CheckFactories.registerCheck<LambdaFunctionNameCheck>(
97         "bugprone-lambda-function-name");
98     CheckFactories.registerCheck<MacroParenthesesCheck>(
99         "bugprone-macro-parentheses");
100     CheckFactories.registerCheck<MacroRepeatedSideEffectsCheck>(
101         "bugprone-macro-repeated-side-effects");
102     CheckFactories.registerCheck<MisplacedOperatorInStrlenInAllocCheck>(
103         "bugprone-misplaced-operator-in-strlen-in-alloc");
104     CheckFactories.registerCheck<MisplacedWideningCastCheck>(
105         "bugprone-misplaced-widening-cast");
106     CheckFactories.registerCheck<MoveForwardingReferenceCheck>(
107         "bugprone-move-forwarding-reference");
108     CheckFactories.registerCheck<MultipleStatementMacroCheck>(
109         "bugprone-multiple-statement-macro");
110     CheckFactories.registerCheck<cppcoreguidelines::NarrowingConversionsCheck>(
111         "bugprone-narrowing-conversions");
112     CheckFactories.registerCheck<ParentVirtualCallCheck>(
113         "bugprone-parent-virtual-call");
114     CheckFactories.registerCheck<PosixReturnCheck>(
115         "bugprone-posix-return");
116     CheckFactories.registerCheck<SizeofContainerCheck>(
117         "bugprone-sizeof-container");
118     CheckFactories.registerCheck<SizeofExpressionCheck>(
119         "bugprone-sizeof-expression");
120     CheckFactories.registerCheck<StringConstructorCheck>(
121         "bugprone-string-constructor");
122     CheckFactories.registerCheck<StringIntegerAssignmentCheck>(
123         "bugprone-string-integer-assignment");
124     CheckFactories.registerCheck<StringLiteralWithEmbeddedNulCheck>(
125         "bugprone-string-literal-with-embedded-nul");
126     CheckFactories.registerCheck<SuspiciousEnumUsageCheck>(
127         "bugprone-suspicious-enum-usage");
128     CheckFactories.registerCheck<SuspiciousMemsetUsageCheck>(
129         "bugprone-suspicious-memset-usage");
130     CheckFactories.registerCheck<SuspiciousMissingCommaCheck>(
131         "bugprone-suspicious-missing-comma");
132     CheckFactories.registerCheck<SuspiciousSemicolonCheck>(
133         "bugprone-suspicious-semicolon");
134     CheckFactories.registerCheck<SuspiciousStringCompareCheck>(
135         "bugprone-suspicious-string-compare");
136     CheckFactories.registerCheck<SwappedArgumentsCheck>(
137         "bugprone-swapped-arguments");
138     CheckFactories.registerCheck<TerminatingContinueCheck>(
139         "bugprone-terminating-continue");
140     CheckFactories.registerCheck<ThrowKeywordMissingCheck>(
141         "bugprone-throw-keyword-missing");
142     CheckFactories.registerCheck<TooSmallLoopVariableCheck>(
143         "bugprone-too-small-loop-variable");
144     CheckFactories.registerCheck<UndefinedMemoryManipulationCheck>(
145         "bugprone-undefined-memory-manipulation");
146     CheckFactories.registerCheck<UndelegatedConstructorCheck>(
147         "bugprone-undelegated-constructor");
148     CheckFactories.registerCheck<UnhandledSelfAssignmentCheck>(
149         "bugprone-unhandled-self-assignment");
150     CheckFactories.registerCheck<UnusedRaiiCheck>(
151         "bugprone-unused-raii");
152     CheckFactories.registerCheck<UnusedReturnValueCheck>(
153         "bugprone-unused-return-value");
154     CheckFactories.registerCheck<UseAfterMoveCheck>(
155         "bugprone-use-after-move");
156     CheckFactories.registerCheck<VirtualNearMissCheck>(
157         "bugprone-virtual-near-miss");
158   }
159 };
160 
161 } // namespace bugprone
162 
163 // Register the BugproneTidyModule using this statically initialized variable.
164 static ClangTidyModuleRegistry::Add<bugprone::BugproneModule>
165     X("bugprone-module", "Adds checks for bugprone code constructs.");
166 
167 // This anchor is used to force the linker to link in the generated object file
168 // and thus register the BugproneModule.
169 volatile int BugproneModuleAnchorSource = 0;
170 
171 } // namespace tidy
172 } // namespace clang
173