clang-tools  15.0.0git
BugproneTidyModule.cpp
Go to the documentation of this file.
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"
18 #include "BranchCloneCheck.h"
20 #include "DanglingHandleCheck.h"
23 #include "ExceptionEscapeCheck.h"
24 #include "FoldInitTypeCheck.h"
28 #include "InaccurateEraseCheck.h"
30 #include "InfiniteLoopCheck.h"
31 #include "IntegerDivisionCheck.h"
33 #include "MacroParenthesesCheck.h"
40 #include "NoEscapeCheck.h"
42 #include "ParentVirtualCallCheck.h"
43 #include "PosixReturnCheck.h"
47 #include "SignalHandlerCheck.h"
48 #include "SignedCharMisuseCheck.h"
49 #include "SizeofContainerCheck.h"
50 #include "SizeofExpressionCheck.h"
52 #include "StringConstructorCheck.h"
55 #include "StringviewNullptrCheck.h"
57 #include "SuspiciousIncludeCheck.h"
63 #include "SwappedArgumentsCheck.h"
72 #include "UnusedRaiiCheck.h"
73 #include "UnusedReturnValueCheck.h"
74 #include "UseAfterMoveCheck.h"
75 #include "VirtualNearMissCheck.h"
76 
77 namespace clang {
78 namespace tidy {
79 namespace bugprone {
80 
82 public:
83  void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
84  CheckFactories.registerCheck<ArgumentCommentCheck>(
85  "bugprone-argument-comment");
86  CheckFactories.registerCheck<AssertSideEffectCheck>(
87  "bugprone-assert-side-effect");
89  "bugprone-assignment-in-if-condition");
91  "bugprone-bad-signal-to-kill-thread");
93  "bugprone-bool-pointer-implicit-conversion");
94  CheckFactories.registerCheck<BranchCloneCheck>("bugprone-branch-clone");
96  "bugprone-copy-constructor-init");
97  CheckFactories.registerCheck<DanglingHandleCheck>(
98  "bugprone-dangling-handle");
100  "bugprone-dynamic-static-initializers");
102  "bugprone-easily-swappable-parameters");
103  CheckFactories.registerCheck<ExceptionEscapeCheck>(
104  "bugprone-exception-escape");
105  CheckFactories.registerCheck<FoldInitTypeCheck>("bugprone-fold-init-type");
107  "bugprone-forward-declaration-namespace");
109  "bugprone-forwarding-reference-overload");
111  "bugprone-implicit-widening-of-multiplication-result");
112  CheckFactories.registerCheck<InaccurateEraseCheck>(
113  "bugprone-inaccurate-erase");
114  CheckFactories.registerCheck<IncorrectRoundingsCheck>(
115  "bugprone-incorrect-roundings");
116  CheckFactories.registerCheck<InfiniteLoopCheck>("bugprone-infinite-loop");
117  CheckFactories.registerCheck<IntegerDivisionCheck>(
118  "bugprone-integer-division");
119  CheckFactories.registerCheck<LambdaFunctionNameCheck>(
120  "bugprone-lambda-function-name");
121  CheckFactories.registerCheck<MacroParenthesesCheck>(
122  "bugprone-macro-parentheses");
124  "bugprone-macro-repeated-side-effects");
126  "bugprone-misplaced-operator-in-strlen-in-alloc");
128  "bugprone-misplaced-pointer-arithmetic-in-alloc");
130  "bugprone-misplaced-widening-cast");
132  "bugprone-move-forwarding-reference");
134  "bugprone-multiple-statement-macro");
136  "bugprone-redundant-branch-condition");
138  "bugprone-narrowing-conversions");
139  CheckFactories.registerCheck<NoEscapeCheck>("bugprone-no-escape");
141  "bugprone-not-null-terminated-result");
142  CheckFactories.registerCheck<ParentVirtualCallCheck>(
143  "bugprone-parent-virtual-call");
144  CheckFactories.registerCheck<PosixReturnCheck>("bugprone-posix-return");
145  CheckFactories.registerCheck<ReservedIdentifierCheck>(
146  "bugprone-reserved-identifier");
148  "bugprone-shared-ptr-array-mismatch");
149  CheckFactories.registerCheck<SignalHandlerCheck>("bugprone-signal-handler");
150  CheckFactories.registerCheck<SignedCharMisuseCheck>(
151  "bugprone-signed-char-misuse");
152  CheckFactories.registerCheck<SizeofContainerCheck>(
153  "bugprone-sizeof-container");
154  CheckFactories.registerCheck<SizeofExpressionCheck>(
155  "bugprone-sizeof-expression");
157  "bugprone-spuriously-wake-up-functions");
158  CheckFactories.registerCheck<StringConstructorCheck>(
159  "bugprone-string-constructor");
161  "bugprone-string-integer-assignment");
163  "bugprone-string-literal-with-embedded-nul");
164  CheckFactories.registerCheck<StringviewNullptrCheck>(
165  "bugprone-stringview-nullptr");
166  CheckFactories.registerCheck<SuspiciousEnumUsageCheck>(
167  "bugprone-suspicious-enum-usage");
168  CheckFactories.registerCheck<SuspiciousIncludeCheck>(
169  "bugprone-suspicious-include");
171  "bugprone-suspicious-memory-comparison");
173  "bugprone-suspicious-memset-usage");
175  "bugprone-suspicious-missing-comma");
176  CheckFactories.registerCheck<SuspiciousSemicolonCheck>(
177  "bugprone-suspicious-semicolon");
179  "bugprone-suspicious-string-compare");
180  CheckFactories.registerCheck<SwappedArgumentsCheck>(
181  "bugprone-swapped-arguments");
182  CheckFactories.registerCheck<TerminatingContinueCheck>(
183  "bugprone-terminating-continue");
184  CheckFactories.registerCheck<ThrowKeywordMissingCheck>(
185  "bugprone-throw-keyword-missing");
187  "bugprone-too-small-loop-variable");
189  "bugprone-unchecked-optional-access");
191  "bugprone-undefined-memory-manipulation");
193  "bugprone-undelegated-constructor");
195  "bugprone-unhandled-self-assignment");
197  "bugprone-unhandled-exception-at-new");
198  CheckFactories.registerCheck<UnusedRaiiCheck>("bugprone-unused-raii");
199  CheckFactories.registerCheck<UnusedReturnValueCheck>(
200  "bugprone-unused-return-value");
201  CheckFactories.registerCheck<UseAfterMoveCheck>("bugprone-use-after-move");
202  CheckFactories.registerCheck<VirtualNearMissCheck>(
203  "bugprone-virtual-near-miss");
204  }
205 };
206 
207 } // namespace bugprone
208 
209 // Register the BugproneTidyModule using this statically initialized variable.
210 static ClangTidyModuleRegistry::Add<bugprone::BugproneModule>
211  X("bugprone-module", "Adds checks for bugprone code constructs.");
212 
213 // This anchor is used to force the linker to link in the generated object file
214 // and thus register the BugproneModule.
215 volatile int BugproneModuleAnchorSource = 0;
216 
217 } // namespace tidy
218 } // namespace clang
clang::tidy::bugprone::SignalHandlerCheck
Checker for signal handler functions.
Definition: SignalHandlerCheck.h:25
clang::tidy::bugprone::TooSmallLoopVariableCheck
This check gives a warning if a loop variable has a too small type which might not be able to represe...
Definition: TooSmallLoopVariableCheck.h:30
clang::tidy::bugprone::NoEscapeCheck
Block arguments in dispatch_async() and dispatch_after() are guaranteed to escape.
Definition: NoEscapeCheck.h:24
clang::tidy::bugprone::CopyConstructorInitCheck
Finds copy constructors where the ctor don't call the copy constructor of the base class.
Definition: CopyConstructorInitCheck.h:23
AssignmentInIfConditionCheck.h
StringLiteralWithEmbeddedNulCheck.h
clang::tidy::bugprone::PosixReturnCheck
Definition: PosixReturnCheck.h:18
clang::tidy::bugprone::SuspiciousMissingCommaCheck
This check finds string literals which are probably concatenated accidentally.
Definition: SuspiciousMissingCommaCheck.h:23
clang::tidy::bugprone::IntegerDivisionCheck
Finds cases where integer division in a floating point context is likely to cause unintended loss of ...
Definition: IntegerDivisionCheck.h:23
clang::tidy::bugprone::StringIntegerAssignmentCheck
Finds instances where an integer is assigned to a string.
Definition: StringIntegerAssignmentCheck.h:22
DanglingHandleCheck.h
StringConstructorCheck.h
clang::tidy::bugprone::AssertSideEffectCheck
Finds assert() with side effect.
Definition: AssertSideEffectCheck.h:34
clang::tidy::bugprone::MacroRepeatedSideEffectsCheck
Checks for repeated argument with side effects in macros.
Definition: MacroRepeatedSideEffectsCheck.h:19
clang::tidy::bugprone::FoldInitTypeCheck
Find and flag invalid initializer values in folds, e.g.
Definition: FoldInitTypeCheck.h:27
ForwardDeclarationNamespaceCheck.h
clang::tidy::bugprone::InaccurateEraseCheck
Checks for inaccurate use of the erase() method.
Definition: InaccurateEraseCheck.h:25
clang::tidy::bugprone::MoveForwardingReferenceCheck
The check warns if std::move is applied to a forwarding reference (i.e.
Definition: MoveForwardingReferenceCheck.h:36
SignalHandlerCheck.h
clang::tidy::bugprone::SuspiciousMemoryComparisonCheck
Finds potentially incorrect calls to memcmp() based on properties of the arguments.
Definition: SuspiciousMemoryComparisonCheck.h:23
BoolPointerImplicitConversionCheck.h
UnhandledSelfAssignmentCheck.h
MisplacedOperatorInStrlenInAllocCheck.h
clang::tidy::bugprone::BadSignalToKillThreadCheck
Finds pthread_kill function calls when thread is terminated by SIGTERM signal.
Definition: BadSignalToKillThreadCheck.h:22
clang::tidy::bugprone::SuspiciousStringCompareCheck
Find suspicious calls to string compare functions.
Definition: SuspiciousStringCompareCheck.h:22
UnhandledExceptionAtNewCheck.h
UndelegatedConstructorCheck.h
UndefinedMemoryManipulationCheck.h
SizeofExpressionCheck.h
clang::tidy::bugprone::UnhandledExceptionAtNewCheck
Finds calls to 'new' that may throw unhandled exception at allocation failure.
Definition: UnhandledExceptionAtNewCheck.h:23
PosixReturnCheck.h
MisplacedWideningCastCheck.h
clang::tidy::bugprone::VirtualNearMissCheck
Checks for near miss of virtual methods.
Definition: VirtualNearMissCheck.h:26
TerminatingContinueCheck.h
IncorrectRoundingsCheck.h
clang::tidy::bugprone::SignedCharMisuseCheck
Finds those signed char -> integer conversions which might indicate a programming error.
Definition: SignedCharMisuseCheck.h:26
clang::tidy::bugprone::ForwardingReferenceOverloadCheck
The checker looks for constructors that can act as copy or move constructors through their forwarding...
Definition: ForwardingReferenceOverloadCheck.h:29
SuspiciousIncludeCheck.h
clang::tidy::bugprone::LambdaFunctionNameCheck
Detect when func or FUNCTION is being used from within a lambda.
Definition: LambdaFunctionNameCheck.h:24
clang::tidy::bugprone::UnhandledSelfAssignmentCheck
Finds user-defined copy assignment operators which do not protect the code against self-assignment ei...
Definition: UnhandledSelfAssignmentCheck.h:24
clang::tidy::ClangTidyCheckFactories
A collection of ClangTidyCheckFactory instances.
Definition: ClangTidyModule.h:28
clang::tidy::bugprone::BoolPointerImplicitConversionCheck
Checks for conditions based on implicit conversion from a bool pointer to bool.
Definition: BoolPointerImplicitConversionCheck.h:29
clang::tidy::bugprone::SpuriouslyWakeUpFunctionsCheck
Finds cnd_wait, cnd_timedwait, wait, wait_for, or wait_until function calls when the function is not ...
Definition: SpuriouslyWakeUpFunctionsCheck.h:25
AssertSideEffectCheck.h
ParentVirtualCallCheck.h
clang::tidy::bugprone::NotNullTerminatedResultCheck
Finds function calls where it is possible to cause a not null-terminated result.
Definition: NotNullTerminatedResultCheck.h:26
VirtualNearMissCheck.h
SuspiciousMemsetUsageCheck.h
clang::tidy::bugprone::BugproneModule::addCheckFactories
void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override
Implement this function in order to register all CheckFactories belonging to this module.
Definition: BugproneTidyModule.cpp:83
clang::tidy::bugprone::SizeofExpressionCheck
Find suspicious usages of sizeof expression.
Definition: SizeofExpressionCheck.h:22
clang::tidy::bugprone::MisplacedOperatorInStrlenInAllocCheck
Finds cases where 1 is added to the string in the argument to a function in the strlen() family inste...
Definition: MisplacedOperatorInStrlenInAllocCheck.h:24
clang::tidy::bugprone::SharedPtrArrayMismatchCheck
Find std::shared_ptr<T>(new T[...]), replace it (if applicable) with std::shared_ptr<T[]>(new T[....
Definition: SharedPtrArrayMismatchCheck.h:26
clang::tidy::bugprone::ImplicitWideningOfMultiplicationResultCheck
Diagnoses instances of an implicit widening of multiplication result.
Definition: ImplicitWideningOfMultiplicationResultCheck.h:23
clang::tidy::bugprone::MisplacedPointerArithmeticInAllocCheck
Finds cases where an integer is added to or subracted from the result of a memory allocation function...
Definition: MisplacedPointerArithmeticInAllocCheck.h:23
clang::tidy::bugprone::MacroParenthesesCheck
Finds macros that can have unexpected behaviour due to missing parentheses.
Definition: MacroParenthesesCheck.h:31
StringviewNullptrCheck.h
clang::tidy::cppcoreguidelines::NarrowingConversionsCheck
Checks for narrowing conversions, e.g: int i = 0; i += 0.1;.
Definition: NarrowingConversionsCheck.h:24
clang::tidy::bugprone::UndelegatedConstructorCheck
Finds creation of temporary objects in constructors that look like a function call to another constru...
Definition: UndelegatedConstructorCheck.h:23
clang::tidy::bugprone::TerminatingContinueCheck
Checks if a 'continue' statement terminates the loop (i.e.
Definition: TerminatingContinueCheck.h:23
SizeofContainerCheck.h
clang::tidy::bugprone::SizeofContainerCheck
Find usages of sizeof on expressions of STL container types.
Definition: SizeofContainerCheck.h:23
clang::tidy::bugprone::UncheckedOptionalAccessCheck
Warns when the code is unwrapping a std::optional<T>, absl::optional<T>, or base::Optional<T> object ...
Definition: UncheckedOptionalAccessCheck.h:24
CopyConstructorInitCheck.h
FoldInitTypeCheck.h
clang::tidy::bugprone::DynamicStaticInitializersCheck
Finds dynamically initialized static variables in header files.
Definition: DynamicStaticInitializersCheck.h:28
SuspiciousMissingCommaCheck.h
DynamicStaticInitializersCheck.h
SwappedArgumentsCheck.h
NoEscapeCheck.h
ArgumentCommentCheck.h
clang::tidy::bugprone::DanglingHandleCheck
Detect dangling references in value handlers like std::experimental::string_view.
Definition: DanglingHandleCheck.h:23
IntegerDivisionCheck.h
TooSmallLoopVariableCheck.h
SignedCharMisuseCheck.h
BadSignalToKillThreadCheck.h
LambdaFunctionNameCheck.h
UnusedReturnValueCheck.h
clang::tidy::bugprone::SuspiciousEnumUsageCheck
The checker detects various cases when an enum is probably misused (as a bitmask).
Definition: SuspiciousEnumUsageCheck.h:22
ThrowKeywordMissingCheck.h
clang::tidy::bugprone::SuspiciousMemsetUsageCheck
Finds memset calls with potential mistakes in their arguments.
Definition: SuspiciousMemsetUsageCheck.h:22
clang::tidy::bugprone::ReservedIdentifierCheck
Checks for usages of identifiers reserved for use by the implementation.
Definition: ReservedIdentifierCheck.h:33
ExceptionEscapeCheck.h
clang::tidy::bugprone::StringConstructorCheck
Finds suspicious string constructor and check their parameters.
Definition: StringConstructorCheck.h:22
clang::tidy::bugprone::UseAfterMoveCheck
The check warns if an object is used after it has been moved, without an intervening reinitialization...
Definition: UseAfterMoveCheck.h:23
clang::tidy::bugprone::ParentVirtualCallCheck
Finds calls to grand..-parent virtual methods instead of parent's.
Definition: ParentVirtualCallCheck.h:22
SuspiciousSemicolonCheck.h
clang::tidy::bugprone::MultipleStatementMacroCheck
Detect multiple statement macros that are used in unbraced conditionals.
Definition: MultipleStatementMacroCheck.h:24
clang::tidy::bugprone::BugproneModule
Definition: BugproneTidyModule.cpp:81
ReservedIdentifierCheck.h
ImplicitWideningOfMultiplicationResultCheck.h
clang::tidy::bugprone::IncorrectRoundingsCheck
Checks the usage of patterns known to produce incorrect rounding.
Definition: IncorrectRoundingsCheck.h:26
UseAfterMoveCheck.h
clang::tidy::bugprone::ExceptionEscapeCheck
Finds functions which should not throw exceptions: Destructors, move constructors,...
Definition: bugprone/ExceptionEscapeCheck.h:27
clang::tidy::bugprone::UnusedRaiiCheck
Finds temporaries that look like RAII objects.
Definition: UnusedRaiiCheck.h:22
StringIntegerAssignmentCheck.h
InfiniteLoopCheck.h
MoveForwardingReferenceCheck.h
MultipleStatementMacroCheck.h
clang::tidy::bugprone::ForwardDeclarationNamespaceCheck
Checks if an unused forward declaration is in a wrong namespace.
Definition: ForwardDeclarationNamespaceCheck.h:40
MisplacedPointerArithmeticInAllocCheck.h
SuspiciousMemoryComparisonCheck.h
clang::tidy::bugprone::UnusedReturnValueCheck
Detects function calls where the return value is unused.
Definition: UnusedReturnValueCheck.h:23
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition: ApplyReplacements.h:27
clang::tidy::bugprone::SuspiciousSemicolonCheck
This check finds semicolon that modifies the meaning of the program unintendedly.
Definition: SuspiciousSemicolonCheck.h:23
UnusedRaiiCheck.h
clang::tidy::bugprone::EasilySwappableParametersCheck
Finds function definitions where parameters of convertible types follow each other directly,...
Definition: EasilySwappableParametersCheck.h:24
clang::tidy::bugprone::MisplacedWideningCastCheck
Find casts of calculation results to bigger type.
Definition: MisplacedWideningCastCheck.h:30
EasilySwappableParametersCheck.h
clang::tidy::bugprone::RedundantBranchConditionCheck
Finds condition variables in nested if statements that were also checked in the outer if statement an...
Definition: RedundantBranchConditionCheck.h:23
clang::tidy::bugprone::BranchCloneCheck
A check for detecting if/else if/else chains where two or more branches are Type I clones of each oth...
Definition: BranchCloneCheck.h:26
clang::tidy::BugproneModuleAnchorSource
volatile int BugproneModuleAnchorSource
Definition: BugproneTidyModule.cpp:215
clang::tidy::bugprone::SuspiciousIncludeCheck
Warns on inclusion of files whose names suggest that they're implementation files,...
Definition: SuspiciousIncludeCheck.h:38
clang::tidy::bugprone::AssignmentInIfConditionCheck
Catches assignments within the condition clause of an if statement.
Definition: AssignmentInIfConditionCheck.h:22
SpuriouslyWakeUpFunctionsCheck.h
SuspiciousEnumUsageCheck.h
clang::tidy::bugprone::StringLiteralWithEmbeddedNulCheck
Find suspicious string literals with embedded NUL characters.
Definition: StringLiteralWithEmbeddedNulCheck.h:22
clang::tidy::bugprone::SwappedArgumentsCheck
Finds potentially swapped arguments by looking at implicit conversions.
Definition: SwappedArgumentsCheck.h:19
clang::tidy::X
static ClangTidyModuleRegistry::Add< altera::AlteraModule > X("altera-module", "Adds Altera FPGA OpenCL lint checks.")
UncheckedOptionalAccessCheck.h
MacroParenthesesCheck.h
clang::tidy::bugprone::StringviewNullptrCheck
Checks for various ways that the const CharT* constructor of std::basic_string_view can be passed a n...
Definition: StringviewNullptrCheck.h:36
SuspiciousStringCompareCheck.h
ForwardingReferenceOverloadCheck.h
clang::tidy::bugprone::ThrowKeywordMissingCheck
Emits a warning about temporary objects whose type is (or is derived from) a class that has 'EXCEPTIO...
Definition: ThrowKeywordMissingCheck.h:23
clang::tidy::bugprone::InfiniteLoopCheck
Finds obvious infinite loops (loops where the condition variable is not changed at all).
Definition: InfiniteLoopCheck.h:23
NotNullTerminatedResultCheck.h
SharedPtrArrayMismatchCheck.h
clang::tidy::ClangTidyModule
A clang-tidy module groups a number of ClangTidyChecks and gives them a prefixed name.
Definition: ClangTidyModule.h:85
InaccurateEraseCheck.h
RedundantBranchConditionCheck.h
clang::tidy::bugprone::UndefinedMemoryManipulationCheck
Finds calls of memory manipulation functions memset(), memcpy() and memmove() on not TriviallyCopyabl...
Definition: UndefinedMemoryManipulationCheck.h:24
BranchCloneCheck.h
MacroRepeatedSideEffectsCheck.h
clang::tidy::ClangTidyCheckFactories::registerCheck
void registerCheck(llvm::StringRef CheckName)
Registers the CheckType with the name Name.
Definition: ClangTidyModule.h:59
clang::tidy::bugprone::ArgumentCommentCheck
Checks that argument comments match parameter names.
Definition: ArgumentCommentCheck.h:34