clang-tools 22.0.0git
BugproneTidyModule.cpp
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
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"
17#include "BranchCloneCheck.h"
26#include "DanglingHandleCheck.h"
31#include "EmptyCatchCheck.h"
35#include "FoldInitTypeCheck.h"
44#include "InfiniteLoopCheck.h"
59#include "NoEscapeCheck.h"
66#include "PosixReturnCheck.h"
73#include "SignalHandlerCheck.h"
108#include "UnsafeFunctionsCheck.h"
110#include "UnusedRaiiCheck.h"
112#include "UseAfterMoveCheck.h"
113#include "VirtualNearMissCheck.h"
114
115namespace clang::tidy {
116namespace bugprone {
117namespace {
118
119class BugproneModule : public ClangTidyModule {
120public:
121 void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
122 CheckFactories.registerCheck<ArgumentCommentCheck>(
123 "bugprone-argument-comment");
124 CheckFactories.registerCheck<AssertSideEffectCheck>(
125 "bugprone-assert-side-effect");
126 CheckFactories.registerCheck<AssignmentInIfConditionCheck>(
127 "bugprone-assignment-in-if-condition");
128 CheckFactories.registerCheck<BadSignalToKillThreadCheck>(
129 "bugprone-bad-signal-to-kill-thread");
130 CheckFactories.registerCheck<BitwisePointerCastCheck>(
131 "bugprone-bitwise-pointer-cast");
132 CheckFactories.registerCheck<BoolPointerImplicitConversionCheck>(
133 "bugprone-bool-pointer-implicit-conversion");
134 CheckFactories.registerCheck<BranchCloneCheck>("bugprone-branch-clone");
135 CheckFactories.registerCheck<CapturingThisInMemberVariableCheck>(
136 "bugprone-capturing-this-in-member-variable");
137 CheckFactories.registerCheck<CastingThroughVoidCheck>(
138 "bugprone-casting-through-void");
139 CheckFactories.registerCheck<ChainedComparisonCheck>(
140 "bugprone-chained-comparison");
141 CheckFactories.registerCheck<CommandProcessorCheck>(
142 "bugprone-command-processor");
143 CheckFactories.registerCheck<ComparePointerToMemberVirtualFunctionCheck>(
144 "bugprone-compare-pointer-to-member-virtual-function");
145 CheckFactories.registerCheck<CopyConstructorInitCheck>(
146 "bugprone-copy-constructor-init");
147 CheckFactories.registerCheck<CopyConstructorMutatesArgumentCheck>(
148 "bugprone-copy-constructor-mutates-argument");
149 CheckFactories.registerCheck<DanglingHandleCheck>(
150 "bugprone-dangling-handle");
151 CheckFactories.registerCheck<DefaultOperatorNewOnOveralignedTypeCheck>(
152 "bugprone-default-operator-new-on-overaligned-type");
153 CheckFactories.registerCheck<DerivedMethodShadowingBaseMethodCheck>(
154 "bugprone-derived-method-shadowing-base-method");
155 CheckFactories.registerCheck<DynamicStaticInitializersCheck>(
156 "bugprone-dynamic-static-initializers");
157 CheckFactories.registerCheck<EasilySwappableParametersCheck>(
158 "bugprone-easily-swappable-parameters");
159 CheckFactories.registerCheck<EmptyCatchCheck>("bugprone-empty-catch");
160 CheckFactories.registerCheck<ExceptionCopyConstructorThrowsCheck>(
161 "bugprone-exception-copy-constructor-throws");
162 CheckFactories.registerCheck<ExceptionEscapeCheck>(
163 "bugprone-exception-escape");
164 CheckFactories.registerCheck<FloatLoopCounterCheck>(
165 "bugprone-float-loop-counter");
166 CheckFactories.registerCheck<FoldInitTypeCheck>("bugprone-fold-init-type");
167 CheckFactories.registerCheck<ForwardDeclarationNamespaceCheck>(
168 "bugprone-forward-declaration-namespace");
169 CheckFactories.registerCheck<ForwardingReferenceOverloadCheck>(
170 "bugprone-forwarding-reference-overload");
171 CheckFactories.registerCheck<ImplicitWideningOfMultiplicationResultCheck>(
172 "bugprone-implicit-widening-of-multiplication-result");
173 CheckFactories.registerCheck<InaccurateEraseCheck>(
174 "bugprone-inaccurate-erase");
175 CheckFactories.registerCheck<IncorrectEnableIfCheck>(
176 "bugprone-incorrect-enable-if");
177 CheckFactories.registerCheck<IncorrectEnableSharedFromThisCheck>(
178 "bugprone-incorrect-enable-shared-from-this");
179 CheckFactories.registerCheck<UnintendedCharOstreamOutputCheck>(
180 "bugprone-unintended-char-ostream-output");
181 CheckFactories.registerCheck<ReturnConstRefFromParameterCheck>(
182 "bugprone-return-const-ref-from-parameter");
183 CheckFactories.registerCheck<SwitchMissingDefaultCaseCheck>(
184 "bugprone-switch-missing-default-case");
185 CheckFactories.registerCheck<IncDecInConditionsCheck>(
186 "bugprone-inc-dec-in-conditions");
187 CheckFactories.registerCheck<IncorrectRoundingsCheck>(
188 "bugprone-incorrect-roundings");
189 CheckFactories.registerCheck<InfiniteLoopCheck>("bugprone-infinite-loop");
190 CheckFactories.registerCheck<IntegerDivisionCheck>(
191 "bugprone-integer-division");
192 CheckFactories.registerCheck<InvalidEnumDefaultInitializationCheck>(
193 "bugprone-invalid-enum-default-initialization");
194 CheckFactories.registerCheck<LambdaFunctionNameCheck>(
195 "bugprone-lambda-function-name");
196 CheckFactories.registerCheck<MacroParenthesesCheck>(
197 "bugprone-macro-parentheses");
198 CheckFactories.registerCheck<MacroRepeatedSideEffectsCheck>(
199 "bugprone-macro-repeated-side-effects");
200 CheckFactories.registerCheck<MisleadingSetterOfReferenceCheck>(
201 "bugprone-misleading-setter-of-reference");
202 CheckFactories.registerCheck<MisplacedOperatorInStrlenInAllocCheck>(
203 "bugprone-misplaced-operator-in-strlen-in-alloc");
204 CheckFactories.registerCheck<MisplacedPointerArithmeticInAllocCheck>(
205 "bugprone-misplaced-pointer-arithmetic-in-alloc");
206 CheckFactories.registerCheck<MisplacedWideningCastCheck>(
207 "bugprone-misplaced-widening-cast");
208 CheckFactories.registerCheck<MoveForwardingReferenceCheck>(
209 "bugprone-move-forwarding-reference");
210 CheckFactories.registerCheck<MultiLevelImplicitPointerConversionCheck>(
211 "bugprone-multi-level-implicit-pointer-conversion");
212 CheckFactories.registerCheck<MultipleNewInOneExpressionCheck>(
213 "bugprone-multiple-new-in-one-expression");
214 CheckFactories.registerCheck<MultipleStatementMacroCheck>(
215 "bugprone-multiple-statement-macro");
216 CheckFactories.registerCheck<NondeterministicPointerIterationOrderCheck>(
217 "bugprone-nondeterministic-pointer-iteration-order");
218 CheckFactories.registerCheck<OptionalValueConversionCheck>(
219 "bugprone-optional-value-conversion");
220 CheckFactories.registerCheck<PointerArithmeticOnPolymorphicObjectCheck>(
221 "bugprone-pointer-arithmetic-on-polymorphic-object");
222 CheckFactories.registerCheck<RedundantBranchConditionCheck>(
223 "bugprone-redundant-branch-condition");
224 CheckFactories.registerCheck<NarrowingConversionsCheck>(
225 "bugprone-narrowing-conversions");
226 CheckFactories.registerCheck<NoEscapeCheck>("bugprone-no-escape");
227 CheckFactories.registerCheck<NonZeroEnumToBoolConversionCheck>(
228 "bugprone-non-zero-enum-to-bool-conversion");
229 CheckFactories.registerCheck<NotNullTerminatedResultCheck>(
230 "bugprone-not-null-terminated-result");
231 CheckFactories.registerCheck<ParentVirtualCallCheck>(
232 "bugprone-parent-virtual-call");
233 CheckFactories.registerCheck<PosixReturnCheck>("bugprone-posix-return");
234 CheckFactories.registerCheck<RandomGeneratorSeedCheck>(
235 "bugprone-random-generator-seed");
236 CheckFactories.registerCheck<RawMemoryCallOnNonTrivialTypeCheck>(
237 "bugprone-raw-memory-call-on-non-trivial-type");
238 CheckFactories.registerCheck<ReservedIdentifierCheck>(
239 "bugprone-reserved-identifier");
240 CheckFactories.registerCheck<SharedPtrArrayMismatchCheck>(
241 "bugprone-shared-ptr-array-mismatch");
242 CheckFactories.registerCheck<SignalHandlerCheck>("bugprone-signal-handler");
243 CheckFactories.registerCheck<SignedCharMisuseCheck>(
244 "bugprone-signed-char-misuse");
245 CheckFactories.registerCheck<SizeofContainerCheck>(
246 "bugprone-sizeof-container");
247 CheckFactories.registerCheck<SizeofExpressionCheck>(
248 "bugprone-sizeof-expression");
249 CheckFactories.registerCheck<SpuriouslyWakeUpFunctionsCheck>(
250 "bugprone-spuriously-wake-up-functions");
251 CheckFactories.registerCheck<StandaloneEmptyCheck>(
252 "bugprone-standalone-empty");
253 CheckFactories.registerCheck<StdNamespaceModificationCheck>(
254 "bugprone-std-namespace-modification");
255 CheckFactories.registerCheck<StringConstructorCheck>(
256 "bugprone-string-constructor");
257 CheckFactories.registerCheck<StringIntegerAssignmentCheck>(
258 "bugprone-string-integer-assignment");
259 CheckFactories.registerCheck<StringLiteralWithEmbeddedNulCheck>(
260 "bugprone-string-literal-with-embedded-nul");
261 CheckFactories.registerCheck<StringviewNullptrCheck>(
262 "bugprone-stringview-nullptr");
263 CheckFactories.registerCheck<SuspiciousEnumUsageCheck>(
264 "bugprone-suspicious-enum-usage");
265 CheckFactories.registerCheck<SuspiciousIncludeCheck>(
266 "bugprone-suspicious-include");
267 CheckFactories.registerCheck<SuspiciousMemoryComparisonCheck>(
268 "bugprone-suspicious-memory-comparison");
269 CheckFactories.registerCheck<SuspiciousMemsetUsageCheck>(
270 "bugprone-suspicious-memset-usage");
271 CheckFactories.registerCheck<SuspiciousMissingCommaCheck>(
272 "bugprone-suspicious-missing-comma");
273 CheckFactories.registerCheck<SuspiciousReallocUsageCheck>(
274 "bugprone-suspicious-realloc-usage");
275 CheckFactories.registerCheck<SuspiciousSemicolonCheck>(
276 "bugprone-suspicious-semicolon");
277 CheckFactories.registerCheck<SuspiciousStringCompareCheck>(
278 "bugprone-suspicious-string-compare");
279 CheckFactories.registerCheck<SuspiciousStringviewDataUsageCheck>(
280 "bugprone-suspicious-stringview-data-usage");
281 CheckFactories.registerCheck<SwappedArgumentsCheck>(
282 "bugprone-swapped-arguments");
283 CheckFactories.registerCheck<TaggedUnionMemberCountCheck>(
284 "bugprone-tagged-union-member-count");
285 CheckFactories.registerCheck<TerminatingContinueCheck>(
286 "bugprone-terminating-continue");
287 CheckFactories.registerCheck<ThrowKeywordMissingCheck>(
288 "bugprone-throw-keyword-missing");
289 CheckFactories.registerCheck<ThrowingStaticInitializationCheck>(
290 "bugprone-throwing-static-initialization");
291 CheckFactories.registerCheck<TooSmallLoopVariableCheck>(
292 "bugprone-too-small-loop-variable");
293 CheckFactories.registerCheck<UncheckedOptionalAccessCheck>(
294 "bugprone-unchecked-optional-access");
295 CheckFactories.registerCheck<UncheckedStringToNumberConversionCheck>(
296 "bugprone-unchecked-string-to-number-conversion");
297 CheckFactories.registerCheck<UndefinedMemoryManipulationCheck>(
298 "bugprone-undefined-memory-manipulation");
299 CheckFactories.registerCheck<UndelegatedConstructorCheck>(
300 "bugprone-undelegated-constructor");
301 CheckFactories.registerCheck<UnhandledSelfAssignmentCheck>(
302 "bugprone-unhandled-self-assignment");
303 CheckFactories.registerCheck<UnhandledExceptionAtNewCheck>(
304 "bugprone-unhandled-exception-at-new");
305 CheckFactories.registerCheck<UniquePtrArrayMismatchCheck>(
306 "bugprone-unique-ptr-array-mismatch");
307 CheckFactories.registerCheck<CrtpConstructorAccessibilityCheck>(
308 "bugprone-crtp-constructor-accessibility");
309 CheckFactories.registerCheck<UnsafeFunctionsCheck>(
310 "bugprone-unsafe-functions");
311 CheckFactories.registerCheck<UnusedLocalNonTrivialVariableCheck>(
312 "bugprone-unused-local-non-trivial-variable");
313 CheckFactories.registerCheck<UnusedRaiiCheck>("bugprone-unused-raii");
314 CheckFactories.registerCheck<UnusedReturnValueCheck>(
315 "bugprone-unused-return-value");
316 CheckFactories.registerCheck<UseAfterMoveCheck>("bugprone-use-after-move");
317 CheckFactories.registerCheck<VirtualNearMissCheck>(
318 "bugprone-virtual-near-miss");
319 }
320};
321
322} // namespace
323} // namespace bugprone
324
325// Register the BugproneTidyModule using this statically initialized variable.
326static ClangTidyModuleRegistry::Add<bugprone::BugproneModule>
327 X("bugprone-module", "Adds checks for bugprone code constructs.");
328
329// This anchor is used to force the linker to link in the generated object file
330// and thus register the BugproneModule.
331// NOLINTNEXTLINE(misc-use-internal-linkage)
333
334} // namespace clang::tidy
static ClangTidyModuleRegistry::Add< altera::AlteraModule > X("altera-module", "Adds Altera FPGA OpenCL lint checks.")
volatile int BugproneModuleAnchorSource