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