clang-tools  14.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"
17 #include "BranchCloneCheck.h"
19 #include "DanglingHandleCheck.h"
22 #include "ExceptionEscapeCheck.h"
23 #include "FoldInitTypeCheck.h"
27 #include "InaccurateEraseCheck.h"
29 #include "InfiniteLoopCheck.h"
30 #include "IntegerDivisionCheck.h"
32 #include "MacroParenthesesCheck.h"
39 #include "NoEscapeCheck.h"
41 #include "ParentVirtualCallCheck.h"
42 #include "PosixReturnCheck.h"
45 #include "SignalHandlerCheck.h"
46 #include "SignedCharMisuseCheck.h"
47 #include "SizeofContainerCheck.h"
48 #include "SizeofExpressionCheck.h"
50 #include "StringConstructorCheck.h"
54 #include "SuspiciousIncludeCheck.h"
60 #include "SwappedArgumentsCheck.h"
68 #include "UnusedRaiiCheck.h"
69 #include "UnusedReturnValueCheck.h"
70 #include "UseAfterMoveCheck.h"
71 #include "VirtualNearMissCheck.h"
72 
73 namespace clang {
74 namespace tidy {
75 namespace bugprone {
76 
78 public:
79  void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
80  CheckFactories.registerCheck<ArgumentCommentCheck>(
81  "bugprone-argument-comment");
82  CheckFactories.registerCheck<AssertSideEffectCheck>(
83  "bugprone-assert-side-effect");
85  "bugprone-bad-signal-to-kill-thread");
87  "bugprone-bool-pointer-implicit-conversion");
88  CheckFactories.registerCheck<BranchCloneCheck>(
89  "bugprone-branch-clone");
91  "bugprone-copy-constructor-init");
92  CheckFactories.registerCheck<DanglingHandleCheck>(
93  "bugprone-dangling-handle");
95  "bugprone-dynamic-static-initializers");
97  "bugprone-easily-swappable-parameters");
98  CheckFactories.registerCheck<ExceptionEscapeCheck>(
99  "bugprone-exception-escape");
100  CheckFactories.registerCheck<FoldInitTypeCheck>(
101  "bugprone-fold-init-type");
103  "bugprone-forward-declaration-namespace");
105  "bugprone-forwarding-reference-overload");
107  "bugprone-implicit-widening-of-multiplication-result");
108  CheckFactories.registerCheck<InaccurateEraseCheck>(
109  "bugprone-inaccurate-erase");
110  CheckFactories.registerCheck<IncorrectRoundingsCheck>(
111  "bugprone-incorrect-roundings");
112  CheckFactories.registerCheck<InfiniteLoopCheck>(
113  "bugprone-infinite-loop");
114  CheckFactories.registerCheck<IntegerDivisionCheck>(
115  "bugprone-integer-division");
116  CheckFactories.registerCheck<LambdaFunctionNameCheck>(
117  "bugprone-lambda-function-name");
118  CheckFactories.registerCheck<MacroParenthesesCheck>(
119  "bugprone-macro-parentheses");
121  "bugprone-macro-repeated-side-effects");
123  "bugprone-misplaced-operator-in-strlen-in-alloc");
125  "bugprone-misplaced-pointer-arithmetic-in-alloc");
127  "bugprone-misplaced-widening-cast");
129  "bugprone-move-forwarding-reference");
131  "bugprone-multiple-statement-macro");
133  "bugprone-redundant-branch-condition");
135  "bugprone-narrowing-conversions");
136  CheckFactories.registerCheck<NoEscapeCheck>("bugprone-no-escape");
138  "bugprone-not-null-terminated-result");
139  CheckFactories.registerCheck<ParentVirtualCallCheck>(
140  "bugprone-parent-virtual-call");
141  CheckFactories.registerCheck<PosixReturnCheck>(
142  "bugprone-posix-return");
143  CheckFactories.registerCheck<ReservedIdentifierCheck>(
144  "bugprone-reserved-identifier");
145  CheckFactories.registerCheck<SignalHandlerCheck>("bugprone-signal-handler");
146  CheckFactories.registerCheck<SignedCharMisuseCheck>(
147  "bugprone-signed-char-misuse");
148  CheckFactories.registerCheck<SizeofContainerCheck>(
149  "bugprone-sizeof-container");
150  CheckFactories.registerCheck<SizeofExpressionCheck>(
151  "bugprone-sizeof-expression");
153  "bugprone-spuriously-wake-up-functions");
154  CheckFactories.registerCheck<StringConstructorCheck>(
155  "bugprone-string-constructor");
157  "bugprone-string-integer-assignment");
159  "bugprone-string-literal-with-embedded-nul");
160  CheckFactories.registerCheck<SuspiciousEnumUsageCheck>(
161  "bugprone-suspicious-enum-usage");
162  CheckFactories.registerCheck<SuspiciousIncludeCheck>(
163  "bugprone-suspicious-include");
165  "bugprone-suspicious-memory-comparison");
167  "bugprone-suspicious-memset-usage");
169  "bugprone-suspicious-missing-comma");
170  CheckFactories.registerCheck<SuspiciousSemicolonCheck>(
171  "bugprone-suspicious-semicolon");
173  "bugprone-suspicious-string-compare");
174  CheckFactories.registerCheck<SwappedArgumentsCheck>(
175  "bugprone-swapped-arguments");
176  CheckFactories.registerCheck<TerminatingContinueCheck>(
177  "bugprone-terminating-continue");
178  CheckFactories.registerCheck<ThrowKeywordMissingCheck>(
179  "bugprone-throw-keyword-missing");
181  "bugprone-too-small-loop-variable");
183  "bugprone-undefined-memory-manipulation");
185  "bugprone-undelegated-constructor");
187  "bugprone-unhandled-self-assignment");
189  "bugprone-unhandled-exception-at-new");
190  CheckFactories.registerCheck<UnusedRaiiCheck>(
191  "bugprone-unused-raii");
192  CheckFactories.registerCheck<UnusedReturnValueCheck>(
193  "bugprone-unused-return-value");
194  CheckFactories.registerCheck<UseAfterMoveCheck>(
195  "bugprone-use-after-move");
196  CheckFactories.registerCheck<VirtualNearMissCheck>(
197  "bugprone-virtual-near-miss");
198  }
199 };
200 
201 } // namespace bugprone
202 
203 // Register the BugproneTidyModule using this statically initialized variable.
204 static ClangTidyModuleRegistry::Add<bugprone::BugproneModule>
205  X("bugprone-module", "Adds checks for bugprone code constructs.");
206 
207 // This anchor is used to force the linker to link in the generated object file
208 // and thus register the BugproneModule.
209 volatile int BugproneModuleAnchorSource = 0;
210 
211 } // namespace tidy
212 } // namespace clang
clang::tidy::bugprone::SignalHandlerCheck
Checker for signal handler functions.
Definition: SignalHandlerCheck.h:23
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
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:79
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::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
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
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:77
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:209
clang::tidy::bugprone::SuspiciousIncludeCheck
Warns on inclusion of files whose names suggest that they're implementation files,...
Definition: SuspiciousIncludeCheck.h:38
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.")
MacroParenthesesCheck.h
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
clang::tidy::ClangTidyModule
A clang-tidy module groups a number of ClangTidyChecks and gives them a prefixed name.
Definition: ClangTidyModule.h:81
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