1 //===--- BugproneTidyModule.cpp - clang-tidy ------------------------------===//
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
7 //===----------------------------------------------------------------------===//
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 "AssignmentInIfConditionCheck.h"
16 #include "BadSignalToKillThreadCheck.h"
17 #include "BoolPointerImplicitConversionCheck.h"
18 #include "BranchCloneCheck.h"
19 #include "CastingThroughVoidCheck.h"
20 #include "ComparePointerToMemberVirtualFunctionCheck.h"
21 #include "CopyConstructorInitCheck.h"
22 #include "DanglingHandleCheck.h"
23 #include "DynamicStaticInitializersCheck.h"
24 #include "EasilySwappableParametersCheck.h"
25 #include "EmptyCatchCheck.h"
26 #include "ExceptionEscapeCheck.h"
27 #include "FoldInitTypeCheck.h"
28 #include "ForwardDeclarationNamespaceCheck.h"
29 #include "ForwardingReferenceOverloadCheck.h"
30 #include "ImplicitWideningOfMultiplicationResultCheck.h"
31 #include "InaccurateEraseCheck.h"
32 #include "IncDecInConditionsCheck.h"
33 #include "IncorrectEnableIfCheck.h"
34 #include "IncorrectRoundingsCheck.h"
35 #include "InfiniteLoopCheck.h"
36 #include "IntegerDivisionCheck.h"
37 #include "LambdaFunctionNameCheck.h"
38 #include "MacroParenthesesCheck.h"
39 #include "MacroRepeatedSideEffectsCheck.h"
40 #include "MisplacedOperatorInStrlenInAllocCheck.h"
41 #include "MisplacedPointerArithmeticInAllocCheck.h"
42 #include "MisplacedWideningCastCheck.h"
43 #include "MoveForwardingReferenceCheck.h"
44 #include "MultiLevelImplicitPointerConversionCheck.h"
45 #include "MultipleNewInOneExpressionCheck.h"
46 #include "MultipleStatementMacroCheck.h"
47 #include "NoEscapeCheck.h"
48 #include "NonZeroEnumToBoolConversionCheck.h"
49 #include "NotNullTerminatedResultCheck.h"
50 #include "OptionalValueConversionCheck.h"
51 #include "ParentVirtualCallCheck.h"
52 #include "PosixReturnCheck.h"
53 #include "RedundantBranchConditionCheck.h"
54 #include "ReservedIdentifierCheck.h"
55 #include "SharedPtrArrayMismatchCheck.h"
56 #include "SignalHandlerCheck.h"
57 #include "SignedCharMisuseCheck.h"
58 #include "SizeofContainerCheck.h"
59 #include "SizeofExpressionCheck.h"
60 #include "SpuriouslyWakeUpFunctionsCheck.h"
61 #include "StandaloneEmptyCheck.h"
62 #include "StringConstructorCheck.h"
63 #include "StringIntegerAssignmentCheck.h"
64 #include "StringLiteralWithEmbeddedNulCheck.h"
65 #include "StringviewNullptrCheck.h"
66 #include "SuspiciousEnumUsageCheck.h"
67 #include "SuspiciousIncludeCheck.h"
68 #include "SuspiciousMemoryComparisonCheck.h"
69 #include "SuspiciousMemsetUsageCheck.h"
70 #include "SuspiciousMissingCommaCheck.h"
71 #include "SuspiciousReallocUsageCheck.h"
72 #include "SuspiciousSemicolonCheck.h"
73 #include "SuspiciousStringCompareCheck.h"
74 #include "SwappedArgumentsCheck.h"
75 #include "SwitchMissingDefaultCaseCheck.h"
76 #include "TerminatingContinueCheck.h"
77 #include "ThrowKeywordMissingCheck.h"
78 #include "TooSmallLoopVariableCheck.h"
79 #include "UncheckedOptionalAccessCheck.h"
80 #include "UndefinedMemoryManipulationCheck.h"
81 #include "UndelegatedConstructorCheck.h"
82 #include "UnhandledExceptionAtNewCheck.h"
83 #include "UnhandledSelfAssignmentCheck.h"
84 #include "UniquePtrArrayMismatchCheck.h"
85 #include "UnsafeFunctionsCheck.h"
86 #include "UnusedRaiiCheck.h"
87 #include "UnusedReturnValueCheck.h"
88 #include "UseAfterMoveCheck.h"
89 #include "VirtualNearMissCheck.h"
91 namespace clang::tidy
{
94 class BugproneModule
: public ClangTidyModule
{
96 void addCheckFactories(ClangTidyCheckFactories
&CheckFactories
) override
{
97 CheckFactories
.registerCheck
<ArgumentCommentCheck
>(
98 "bugprone-argument-comment");
99 CheckFactories
.registerCheck
<AssertSideEffectCheck
>(
100 "bugprone-assert-side-effect");
101 CheckFactories
.registerCheck
<AssignmentInIfConditionCheck
>(
102 "bugprone-assignment-in-if-condition");
103 CheckFactories
.registerCheck
<BadSignalToKillThreadCheck
>(
104 "bugprone-bad-signal-to-kill-thread");
105 CheckFactories
.registerCheck
<BoolPointerImplicitConversionCheck
>(
106 "bugprone-bool-pointer-implicit-conversion");
107 CheckFactories
.registerCheck
<BranchCloneCheck
>("bugprone-branch-clone");
108 CheckFactories
.registerCheck
<CastingThroughVoidCheck
>(
109 "bugprone-casting-through-void");
110 CheckFactories
.registerCheck
<ComparePointerToMemberVirtualFunctionCheck
>(
111 "bugprone-compare-pointer-to-member-virtual-function");
112 CheckFactories
.registerCheck
<CopyConstructorInitCheck
>(
113 "bugprone-copy-constructor-init");
114 CheckFactories
.registerCheck
<DanglingHandleCheck
>(
115 "bugprone-dangling-handle");
116 CheckFactories
.registerCheck
<DynamicStaticInitializersCheck
>(
117 "bugprone-dynamic-static-initializers");
118 CheckFactories
.registerCheck
<EasilySwappableParametersCheck
>(
119 "bugprone-easily-swappable-parameters");
120 CheckFactories
.registerCheck
<EmptyCatchCheck
>("bugprone-empty-catch");
121 CheckFactories
.registerCheck
<ExceptionEscapeCheck
>(
122 "bugprone-exception-escape");
123 CheckFactories
.registerCheck
<FoldInitTypeCheck
>("bugprone-fold-init-type");
124 CheckFactories
.registerCheck
<ForwardDeclarationNamespaceCheck
>(
125 "bugprone-forward-declaration-namespace");
126 CheckFactories
.registerCheck
<ForwardingReferenceOverloadCheck
>(
127 "bugprone-forwarding-reference-overload");
128 CheckFactories
.registerCheck
<ImplicitWideningOfMultiplicationResultCheck
>(
129 "bugprone-implicit-widening-of-multiplication-result");
130 CheckFactories
.registerCheck
<InaccurateEraseCheck
>(
131 "bugprone-inaccurate-erase");
132 CheckFactories
.registerCheck
<IncorrectEnableIfCheck
>(
133 "bugprone-incorrect-enable-if");
134 CheckFactories
.registerCheck
<SwitchMissingDefaultCaseCheck
>(
135 "bugprone-switch-missing-default-case");
136 CheckFactories
.registerCheck
<IncDecInConditionsCheck
>(
137 "bugprone-inc-dec-in-conditions");
138 CheckFactories
.registerCheck
<IncorrectRoundingsCheck
>(
139 "bugprone-incorrect-roundings");
140 CheckFactories
.registerCheck
<InfiniteLoopCheck
>("bugprone-infinite-loop");
141 CheckFactories
.registerCheck
<IntegerDivisionCheck
>(
142 "bugprone-integer-division");
143 CheckFactories
.registerCheck
<LambdaFunctionNameCheck
>(
144 "bugprone-lambda-function-name");
145 CheckFactories
.registerCheck
<MacroParenthesesCheck
>(
146 "bugprone-macro-parentheses");
147 CheckFactories
.registerCheck
<MacroRepeatedSideEffectsCheck
>(
148 "bugprone-macro-repeated-side-effects");
149 CheckFactories
.registerCheck
<MisplacedOperatorInStrlenInAllocCheck
>(
150 "bugprone-misplaced-operator-in-strlen-in-alloc");
151 CheckFactories
.registerCheck
<MisplacedPointerArithmeticInAllocCheck
>(
152 "bugprone-misplaced-pointer-arithmetic-in-alloc");
153 CheckFactories
.registerCheck
<MisplacedWideningCastCheck
>(
154 "bugprone-misplaced-widening-cast");
155 CheckFactories
.registerCheck
<MoveForwardingReferenceCheck
>(
156 "bugprone-move-forwarding-reference");
157 CheckFactories
.registerCheck
<MultiLevelImplicitPointerConversionCheck
>(
158 "bugprone-multi-level-implicit-pointer-conversion");
159 CheckFactories
.registerCheck
<MultipleNewInOneExpressionCheck
>(
160 "bugprone-multiple-new-in-one-expression");
161 CheckFactories
.registerCheck
<MultipleStatementMacroCheck
>(
162 "bugprone-multiple-statement-macro");
163 CheckFactories
.registerCheck
<OptionalValueConversionCheck
>(
164 "bugprone-optional-value-conversion");
165 CheckFactories
.registerCheck
<RedundantBranchConditionCheck
>(
166 "bugprone-redundant-branch-condition");
167 CheckFactories
.registerCheck
<cppcoreguidelines::NarrowingConversionsCheck
>(
168 "bugprone-narrowing-conversions");
169 CheckFactories
.registerCheck
<NoEscapeCheck
>("bugprone-no-escape");
170 CheckFactories
.registerCheck
<NonZeroEnumToBoolConversionCheck
>(
171 "bugprone-non-zero-enum-to-bool-conversion");
172 CheckFactories
.registerCheck
<NotNullTerminatedResultCheck
>(
173 "bugprone-not-null-terminated-result");
174 CheckFactories
.registerCheck
<ParentVirtualCallCheck
>(
175 "bugprone-parent-virtual-call");
176 CheckFactories
.registerCheck
<PosixReturnCheck
>("bugprone-posix-return");
177 CheckFactories
.registerCheck
<ReservedIdentifierCheck
>(
178 "bugprone-reserved-identifier");
179 CheckFactories
.registerCheck
<SharedPtrArrayMismatchCheck
>(
180 "bugprone-shared-ptr-array-mismatch");
181 CheckFactories
.registerCheck
<SignalHandlerCheck
>("bugprone-signal-handler");
182 CheckFactories
.registerCheck
<SignedCharMisuseCheck
>(
183 "bugprone-signed-char-misuse");
184 CheckFactories
.registerCheck
<SizeofContainerCheck
>(
185 "bugprone-sizeof-container");
186 CheckFactories
.registerCheck
<SizeofExpressionCheck
>(
187 "bugprone-sizeof-expression");
188 CheckFactories
.registerCheck
<SpuriouslyWakeUpFunctionsCheck
>(
189 "bugprone-spuriously-wake-up-functions");
190 CheckFactories
.registerCheck
<StandaloneEmptyCheck
>(
191 "bugprone-standalone-empty");
192 CheckFactories
.registerCheck
<StringConstructorCheck
>(
193 "bugprone-string-constructor");
194 CheckFactories
.registerCheck
<StringIntegerAssignmentCheck
>(
195 "bugprone-string-integer-assignment");
196 CheckFactories
.registerCheck
<StringLiteralWithEmbeddedNulCheck
>(
197 "bugprone-string-literal-with-embedded-nul");
198 CheckFactories
.registerCheck
<StringviewNullptrCheck
>(
199 "bugprone-stringview-nullptr");
200 CheckFactories
.registerCheck
<SuspiciousEnumUsageCheck
>(
201 "bugprone-suspicious-enum-usage");
202 CheckFactories
.registerCheck
<SuspiciousIncludeCheck
>(
203 "bugprone-suspicious-include");
204 CheckFactories
.registerCheck
<SuspiciousMemoryComparisonCheck
>(
205 "bugprone-suspicious-memory-comparison");
206 CheckFactories
.registerCheck
<SuspiciousMemsetUsageCheck
>(
207 "bugprone-suspicious-memset-usage");
208 CheckFactories
.registerCheck
<SuspiciousMissingCommaCheck
>(
209 "bugprone-suspicious-missing-comma");
210 CheckFactories
.registerCheck
<SuspiciousReallocUsageCheck
>(
211 "bugprone-suspicious-realloc-usage");
212 CheckFactories
.registerCheck
<SuspiciousSemicolonCheck
>(
213 "bugprone-suspicious-semicolon");
214 CheckFactories
.registerCheck
<SuspiciousStringCompareCheck
>(
215 "bugprone-suspicious-string-compare");
216 CheckFactories
.registerCheck
<SwappedArgumentsCheck
>(
217 "bugprone-swapped-arguments");
218 CheckFactories
.registerCheck
<TerminatingContinueCheck
>(
219 "bugprone-terminating-continue");
220 CheckFactories
.registerCheck
<ThrowKeywordMissingCheck
>(
221 "bugprone-throw-keyword-missing");
222 CheckFactories
.registerCheck
<TooSmallLoopVariableCheck
>(
223 "bugprone-too-small-loop-variable");
224 CheckFactories
.registerCheck
<UncheckedOptionalAccessCheck
>(
225 "bugprone-unchecked-optional-access");
226 CheckFactories
.registerCheck
<UndefinedMemoryManipulationCheck
>(
227 "bugprone-undefined-memory-manipulation");
228 CheckFactories
.registerCheck
<UndelegatedConstructorCheck
>(
229 "bugprone-undelegated-constructor");
230 CheckFactories
.registerCheck
<UnhandledSelfAssignmentCheck
>(
231 "bugprone-unhandled-self-assignment");
232 CheckFactories
.registerCheck
<UnhandledExceptionAtNewCheck
>(
233 "bugprone-unhandled-exception-at-new");
234 CheckFactories
.registerCheck
<UniquePtrArrayMismatchCheck
>(
235 "bugprone-unique-ptr-array-mismatch");
236 CheckFactories
.registerCheck
<UnsafeFunctionsCheck
>(
237 "bugprone-unsafe-functions");
238 CheckFactories
.registerCheck
<UnusedRaiiCheck
>("bugprone-unused-raii");
239 CheckFactories
.registerCheck
<UnusedReturnValueCheck
>(
240 "bugprone-unused-return-value");
241 CheckFactories
.registerCheck
<UseAfterMoveCheck
>("bugprone-use-after-move");
242 CheckFactories
.registerCheck
<VirtualNearMissCheck
>(
243 "bugprone-virtual-near-miss");
247 } // namespace bugprone
249 // Register the BugproneTidyModule using this statically initialized variable.
250 static ClangTidyModuleRegistry::Add
<bugprone::BugproneModule
>
251 X("bugprone-module", "Adds checks for bugprone code constructs.");
253 // This anchor is used to force the linker to link in the generated object file
254 // and thus register the BugproneModule.
255 volatile int BugproneModuleAnchorSource
= 0;
257 } // namespace clang::tidy