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

source code of clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp