334 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9#include "../ClangTidy.h"10#include "../ClangTidyModule.h"11#include "../ClangTidyModuleRegistry.h"12#include "ArgumentCommentCheck.h"13#include "AssertSideEffectCheck.h"14#include "AssignmentInIfConditionCheck.h"15#include "BadSignalToKillThreadCheck.h"16#include "BitwisePointerCastCheck.h"17#include "BoolPointerImplicitConversionCheck.h"18#include "BranchCloneCheck.h"19#include "CapturingThisInMemberVariableCheck.h"20#include "CastingThroughVoidCheck.h"21#include "ChainedComparisonCheck.h"22#include "CommandProcessorCheck.h"23#include "ComparePointerToMemberVirtualFunctionCheck.h"24#include "CopyConstructorInitCheck.h"25#include "CopyConstructorMutatesArgumentCheck.h"26#include "CrtpConstructorAccessibilityCheck.h"27#include "DanglingHandleCheck.h"28#include "DefaultOperatorNewOnOveralignedTypeCheck.h"29#include "DerivedMethodShadowingBaseMethodCheck.h"30#include "DynamicStaticInitializersCheck.h"31#include "EasilySwappableParametersCheck.h"32#include "EmptyCatchCheck.h"33#include "ExceptionCopyConstructorThrowsCheck.h"34#include "ExceptionEscapeCheck.h"35#include "FloatLoopCounterCheck.h"36#include "FoldInitTypeCheck.h"37#include "ForwardDeclarationNamespaceCheck.h"38#include "ForwardingReferenceOverloadCheck.h"39#include "ImplicitWideningOfMultiplicationResultCheck.h"40#include "InaccurateEraseCheck.h"41#include "IncDecInConditionsCheck.h"42#include "IncorrectEnableIfCheck.h"43#include "IncorrectEnableSharedFromThisCheck.h"44#include "IncorrectRoundingsCheck.h"45#include "InfiniteLoopCheck.h"46#include "IntegerDivisionCheck.h"47#include "InvalidEnumDefaultInitializationCheck.h"48#include "LambdaFunctionNameCheck.h"49#include "MacroParenthesesCheck.h"50#include "MacroRepeatedSideEffectsCheck.h"51#include "MisleadingSetterOfReferenceCheck.h"52#include "MisplacedOperatorInStrlenInAllocCheck.h"53#include "MisplacedPointerArithmeticInAllocCheck.h"54#include "MisplacedWideningCastCheck.h"55#include "MoveForwardingReferenceCheck.h"56#include "MultiLevelImplicitPointerConversionCheck.h"57#include "MultipleNewInOneExpressionCheck.h"58#include "MultipleStatementMacroCheck.h"59#include "NarrowingConversionsCheck.h"60#include "NoEscapeCheck.h"61#include "NonZeroEnumToBoolConversionCheck.h"62#include "NondeterministicPointerIterationOrderCheck.h"63#include "NotNullTerminatedResultCheck.h"64#include "OptionalValueConversionCheck.h"65#include "ParentVirtualCallCheck.h"66#include "PointerArithmeticOnPolymorphicObjectCheck.h"67#include "PosixReturnCheck.h"68#include "RandomGeneratorSeedCheck.h"69#include "RawMemoryCallOnNonTrivialTypeCheck.h"70#include "RedundantBranchConditionCheck.h"71#include "ReservedIdentifierCheck.h"72#include "ReturnConstRefFromParameterCheck.h"73#include "SharedPtrArrayMismatchCheck.h"74#include "SignalHandlerCheck.h"75#include "SignedCharMisuseCheck.h"76#include "SizeofContainerCheck.h"77#include "SizeofExpressionCheck.h"78#include "SpuriouslyWakeUpFunctionsCheck.h"79#include "StandaloneEmptyCheck.h"80#include "StdNamespaceModificationCheck.h"81#include "StringConstructorCheck.h"82#include "StringIntegerAssignmentCheck.h"83#include "StringLiteralWithEmbeddedNulCheck.h"84#include "StringviewNullptrCheck.h"85#include "SuspiciousEnumUsageCheck.h"86#include "SuspiciousIncludeCheck.h"87#include "SuspiciousMemoryComparisonCheck.h"88#include "SuspiciousMemsetUsageCheck.h"89#include "SuspiciousMissingCommaCheck.h"90#include "SuspiciousReallocUsageCheck.h"91#include "SuspiciousSemicolonCheck.h"92#include "SuspiciousStringCompareCheck.h"93#include "SuspiciousStringviewDataUsageCheck.h"94#include "SwappedArgumentsCheck.h"95#include "SwitchMissingDefaultCaseCheck.h"96#include "TaggedUnionMemberCountCheck.h"97#include "TerminatingContinueCheck.h"98#include "ThrowKeywordMissingCheck.h"99#include "ThrowingStaticInitializationCheck.h"100#include "TooSmallLoopVariableCheck.h"101#include "UncheckedOptionalAccessCheck.h"102#include "UncheckedStringToNumberConversionCheck.h"103#include "UndefinedMemoryManipulationCheck.h"104#include "UndelegatedConstructorCheck.h"105#include "UnhandledExceptionAtNewCheck.h"106#include "UnhandledSelfAssignmentCheck.h"107#include "UnintendedCharOstreamOutputCheck.h"108#include "UniquePtrArrayMismatchCheck.h"109#include "UnsafeFunctionsCheck.h"110#include "UnusedLocalNonTrivialVariableCheck.h"111#include "UnusedRaiiCheck.h"112#include "UnusedReturnValueCheck.h"113#include "UseAfterMoveCheck.h"114#include "VirtualNearMissCheck.h"115 116namespace clang::tidy {117namespace bugprone {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 bugprone323 324// Register the BugproneTidyModule using this statically initialized variable.325static ClangTidyModuleRegistry::Add<bugprone::BugproneModule>326 X("bugprone-module", "Adds checks for bugprone code constructs.");327 328// This anchor is used to force the linker to link in the generated object file329// and thus register the BugproneModule.330// NOLINTNEXTLINE(misc-use-internal-linkage)331volatile int BugproneModuleAnchorSource = 0;332 333} // namespace clang::tidy334