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