2017-07-14 20:15:55 +08:00
|
|
|
//===--- BugproneTidyModule.cpp - clang-tidy ------------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "../ClangTidy.h"
|
|
|
|
#include "../ClangTidyModule.h"
|
|
|
|
#include "../ClangTidyModuleRegistry.h"
|
2018-05-23 15:58:41 +08:00
|
|
|
#include "../cppcoreguidelines/NarrowingConversionsCheck.h"
|
2017-11-24 01:02:48 +08:00
|
|
|
#include "ArgumentCommentCheck.h"
|
2017-11-24 22:16:29 +08:00
|
|
|
#include "AssertSideEffectCheck.h"
|
|
|
|
#include "BoolPointerImplicitConversionCheck.h"
|
2017-11-17 20:23:30 +08:00
|
|
|
#include "CopyConstructorInitCheck.h"
|
2017-11-24 17:52:05 +08:00
|
|
|
#include "DanglingHandleCheck.h"
|
2018-07-13 21:09:40 +08:00
|
|
|
#include "ExceptionEscapeCheck.h"
|
2017-11-24 22:16:29 +08:00
|
|
|
#include "FoldInitTypeCheck.h"
|
|
|
|
#include "ForwardDeclarationNamespaceCheck.h"
|
2018-02-28 22:47:20 +08:00
|
|
|
#include "ForwardingReferenceOverloadCheck.h"
|
2017-11-24 22:16:29 +08:00
|
|
|
#include "InaccurateEraseCheck.h"
|
2018-01-30 23:12:24 +08:00
|
|
|
#include "IncorrectRoundingsCheck.h"
|
2017-08-10 21:30:30 +08:00
|
|
|
#include "IntegerDivisionCheck.h"
|
2018-02-28 22:47:20 +08:00
|
|
|
#include "LambdaFunctionNameCheck.h"
|
2018-03-15 16:25:39 +08:00
|
|
|
#include "MacroParenthesesCheck.h"
|
2018-02-28 22:47:20 +08:00
|
|
|
#include "MacroRepeatedSideEffectsCheck.h"
|
2017-11-23 20:26:28 +08:00
|
|
|
#include "MisplacedOperatorInStrlenInAllocCheck.h"
|
2018-02-28 22:47:20 +08:00
|
|
|
#include "MisplacedWideningCastCheck.h"
|
2017-11-24 22:16:29 +08:00
|
|
|
#include "MoveForwardingReferenceCheck.h"
|
|
|
|
#include "MultipleStatementMacroCheck.h"
|
2018-04-07 04:02:50 +08:00
|
|
|
#include "ParentVirtualCallCheck.h"
|
2018-03-15 16:26:47 +08:00
|
|
|
#include "SizeofContainerCheck.h"
|
2018-03-15 16:26:19 +08:00
|
|
|
#include "SizeofExpressionCheck.h"
|
2017-11-23 21:49:14 +08:00
|
|
|
#include "StringConstructorCheck.h"
|
2018-03-01 07:30:29 +08:00
|
|
|
#include "StringIntegerAssignmentCheck.h"
|
|
|
|
#include "StringLiteralWithEmbeddedNulCheck.h"
|
|
|
|
#include "SuspiciousEnumUsageCheck.h"
|
2017-07-14 20:15:55 +08:00
|
|
|
#include "SuspiciousMemsetUsageCheck.h"
|
2018-03-01 07:30:29 +08:00
|
|
|
#include "SuspiciousMissingCommaCheck.h"
|
2018-03-01 07:47:15 +08:00
|
|
|
#include "SuspiciousSemicolonCheck.h"
|
|
|
|
#include "SuspiciousStringCompareCheck.h"
|
|
|
|
#include "SwappedArgumentsCheck.h"
|
2018-05-14 18:10:02 +08:00
|
|
|
#include "TerminatingContinueCheck.h"
|
2018-02-15 17:08:51 +08:00
|
|
|
#include "ThrowKeywordMissingCheck.h"
|
[clang-tidy] new check: bugprone-too-small-loop-variable
The new checker searches for those for loops which has a loop variable with a "too small" type which means this type can't represent all values which are part of the iteration range.
For example:
```
int main() {
long size = 300000;
for( short int i = 0; i < size; ++i) {}
}
```
The short type leads to infinite loop here because it can't store all values in the `[0..size]` interval. In a real use case, size means a container's size which depends on the user input. Which means for small amount of objects the algorithm works, but with a larger user input the software will freeze.
The idea of the checker comes from the LibreOffice project, where the same check was implemented as a clang compiler plugin, called `LoopVarTooSmall` (LLVM licensed).
The idea is the same behind this check, but the code is different because of the different framework.
Patch by ztamas.
Reviewers: alexfh, hokein, aaron.ballman, JonasToth, xazax.hun, whisperity
Reviewed By: JonasToth, whisperity
Differential Revision: https://reviews.llvm.org/D53974
llvm-svn: 346665
2018-11-13 00:01:39 +08:00
|
|
|
#include "TooSmallLoopVariableCheck.h"
|
2017-07-14 20:20:19 +08:00
|
|
|
#include "UndefinedMemoryManipulationCheck.h"
|
2018-03-01 07:47:15 +08:00
|
|
|
#include "UndelegatedConstructorCheck.h"
|
2018-03-15 16:27:42 +08:00
|
|
|
#include "UnusedRaiiCheck.h"
|
2018-03-19 21:02:32 +08:00
|
|
|
#include "UnusedReturnValueCheck.h"
|
2017-11-24 22:16:29 +08:00
|
|
|
#include "UseAfterMoveCheck.h"
|
|
|
|
#include "VirtualNearMissCheck.h"
|
2017-07-14 20:15:55 +08:00
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
namespace tidy {
|
|
|
|
namespace bugprone {
|
|
|
|
|
|
|
|
class BugproneModule : public ClangTidyModule {
|
|
|
|
public:
|
|
|
|
void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
|
2017-11-24 01:02:48 +08:00
|
|
|
CheckFactories.registerCheck<ArgumentCommentCheck>(
|
|
|
|
"bugprone-argument-comment");
|
2017-11-24 22:16:29 +08:00
|
|
|
CheckFactories.registerCheck<AssertSideEffectCheck>(
|
|
|
|
"bugprone-assert-side-effect");
|
|
|
|
CheckFactories.registerCheck<BoolPointerImplicitConversionCheck>(
|
|
|
|
"bugprone-bool-pointer-implicit-conversion");
|
2017-11-17 20:23:30 +08:00
|
|
|
CheckFactories.registerCheck<CopyConstructorInitCheck>(
|
2017-11-17 20:28:58 +08:00
|
|
|
"bugprone-copy-constructor-init");
|
2017-11-24 17:52:05 +08:00
|
|
|
CheckFactories.registerCheck<DanglingHandleCheck>(
|
|
|
|
"bugprone-dangling-handle");
|
2018-07-13 21:09:40 +08:00
|
|
|
CheckFactories.registerCheck<ExceptionEscapeCheck>(
|
|
|
|
"bugprone-exception-escape");
|
2017-11-24 22:16:29 +08:00
|
|
|
CheckFactories.registerCheck<FoldInitTypeCheck>(
|
|
|
|
"bugprone-fold-init-type");
|
|
|
|
CheckFactories.registerCheck<ForwardDeclarationNamespaceCheck>(
|
|
|
|
"bugprone-forward-declaration-namespace");
|
2018-02-28 22:47:20 +08:00
|
|
|
CheckFactories.registerCheck<ForwardingReferenceOverloadCheck>(
|
|
|
|
"bugprone-forwarding-reference-overload");
|
2017-11-24 22:16:29 +08:00
|
|
|
CheckFactories.registerCheck<InaccurateEraseCheck>(
|
|
|
|
"bugprone-inaccurate-erase");
|
2018-01-30 23:12:24 +08:00
|
|
|
CheckFactories.registerCheck<IncorrectRoundingsCheck>(
|
|
|
|
"bugprone-incorrect-roundings");
|
2017-08-10 21:30:30 +08:00
|
|
|
CheckFactories.registerCheck<IntegerDivisionCheck>(
|
|
|
|
"bugprone-integer-division");
|
2018-02-28 22:47:20 +08:00
|
|
|
CheckFactories.registerCheck<LambdaFunctionNameCheck>(
|
|
|
|
"bugprone-lambda-function-name");
|
2018-03-15 16:25:39 +08:00
|
|
|
CheckFactories.registerCheck<MacroParenthesesCheck>(
|
|
|
|
"bugprone-macro-parentheses");
|
2018-02-28 22:47:20 +08:00
|
|
|
CheckFactories.registerCheck<MacroRepeatedSideEffectsCheck>(
|
|
|
|
"bugprone-macro-repeated-side-effects");
|
2017-11-23 20:26:28 +08:00
|
|
|
CheckFactories.registerCheck<MisplacedOperatorInStrlenInAllocCheck>(
|
|
|
|
"bugprone-misplaced-operator-in-strlen-in-alloc");
|
2018-02-28 22:47:20 +08:00
|
|
|
CheckFactories.registerCheck<MisplacedWideningCastCheck>(
|
|
|
|
"bugprone-misplaced-widening-cast");
|
2017-11-24 22:16:29 +08:00
|
|
|
CheckFactories.registerCheck<MoveForwardingReferenceCheck>(
|
|
|
|
"bugprone-move-forwarding-reference");
|
|
|
|
CheckFactories.registerCheck<MultipleStatementMacroCheck>(
|
|
|
|
"bugprone-multiple-statement-macro");
|
[clang-tidy] new check: bugprone-too-small-loop-variable
The new checker searches for those for loops which has a loop variable with a "too small" type which means this type can't represent all values which are part of the iteration range.
For example:
```
int main() {
long size = 300000;
for( short int i = 0; i < size; ++i) {}
}
```
The short type leads to infinite loop here because it can't store all values in the `[0..size]` interval. In a real use case, size means a container's size which depends on the user input. Which means for small amount of objects the algorithm works, but with a larger user input the software will freeze.
The idea of the checker comes from the LibreOffice project, where the same check was implemented as a clang compiler plugin, called `LoopVarTooSmall` (LLVM licensed).
The idea is the same behind this check, but the code is different because of the different framework.
Patch by ztamas.
Reviewers: alexfh, hokein, aaron.ballman, JonasToth, xazax.hun, whisperity
Reviewed By: JonasToth, whisperity
Differential Revision: https://reviews.llvm.org/D53974
llvm-svn: 346665
2018-11-13 00:01:39 +08:00
|
|
|
CheckFactories.registerCheck<TooSmallLoopVariableCheck>(
|
|
|
|
"bugprone-too-small-loop-variable");
|
2018-05-23 15:58:41 +08:00
|
|
|
CheckFactories.registerCheck<cppcoreguidelines::NarrowingConversionsCheck>(
|
|
|
|
"bugprone-narrowing-conversions");
|
2018-04-07 04:02:50 +08:00
|
|
|
CheckFactories.registerCheck<ParentVirtualCallCheck>(
|
|
|
|
"bugprone-parent-virtual-call");
|
2018-03-15 16:26:47 +08:00
|
|
|
CheckFactories.registerCheck<SizeofContainerCheck>(
|
|
|
|
"bugprone-sizeof-container");
|
2018-03-15 16:26:19 +08:00
|
|
|
CheckFactories.registerCheck<SizeofExpressionCheck>(
|
|
|
|
"bugprone-sizeof-expression");
|
2017-11-23 21:49:14 +08:00
|
|
|
CheckFactories.registerCheck<StringConstructorCheck>(
|
|
|
|
"bugprone-string-constructor");
|
2018-03-01 07:30:29 +08:00
|
|
|
CheckFactories.registerCheck<StringIntegerAssignmentCheck>(
|
|
|
|
"bugprone-string-integer-assignment");
|
|
|
|
CheckFactories.registerCheck<StringLiteralWithEmbeddedNulCheck>(
|
|
|
|
"bugprone-string-literal-with-embedded-nul");
|
|
|
|
CheckFactories.registerCheck<SuspiciousEnumUsageCheck>(
|
|
|
|
"bugprone-suspicious-enum-usage");
|
2017-07-14 20:15:55 +08:00
|
|
|
CheckFactories.registerCheck<SuspiciousMemsetUsageCheck>(
|
|
|
|
"bugprone-suspicious-memset-usage");
|
2018-03-01 07:30:29 +08:00
|
|
|
CheckFactories.registerCheck<SuspiciousMissingCommaCheck>(
|
|
|
|
"bugprone-suspicious-missing-comma");
|
2018-03-01 07:47:15 +08:00
|
|
|
CheckFactories.registerCheck<SuspiciousSemicolonCheck>(
|
|
|
|
"bugprone-suspicious-semicolon");
|
|
|
|
CheckFactories.registerCheck<SuspiciousStringCompareCheck>(
|
|
|
|
"bugprone-suspicious-string-compare");
|
|
|
|
CheckFactories.registerCheck<SwappedArgumentsCheck>(
|
|
|
|
"bugprone-swapped-arguments");
|
2018-05-14 18:10:02 +08:00
|
|
|
CheckFactories.registerCheck<TerminatingContinueCheck>(
|
|
|
|
"bugprone-terminating-continue");
|
2018-02-15 17:08:51 +08:00
|
|
|
CheckFactories.registerCheck<ThrowKeywordMissingCheck>(
|
|
|
|
"bugprone-throw-keyword-missing");
|
2017-07-14 20:20:19 +08:00
|
|
|
CheckFactories.registerCheck<UndefinedMemoryManipulationCheck>(
|
|
|
|
"bugprone-undefined-memory-manipulation");
|
2018-03-01 07:47:15 +08:00
|
|
|
CheckFactories.registerCheck<UndelegatedConstructorCheck>(
|
|
|
|
"bugprone-undelegated-constructor");
|
2018-03-15 16:27:42 +08:00
|
|
|
CheckFactories.registerCheck<UnusedRaiiCheck>(
|
|
|
|
"bugprone-unused-raii");
|
2018-03-19 21:02:32 +08:00
|
|
|
CheckFactories.registerCheck<UnusedReturnValueCheck>(
|
|
|
|
"bugprone-unused-return-value");
|
2017-11-24 22:16:29 +08:00
|
|
|
CheckFactories.registerCheck<UseAfterMoveCheck>(
|
|
|
|
"bugprone-use-after-move");
|
|
|
|
CheckFactories.registerCheck<VirtualNearMissCheck>(
|
|
|
|
"bugprone-virtual-near-miss");
|
2017-07-14 20:15:55 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace bugprone
|
|
|
|
|
|
|
|
// Register the BugproneTidyModule using this statically initialized variable.
|
|
|
|
static ClangTidyModuleRegistry::Add<bugprone::BugproneModule>
|
|
|
|
X("bugprone-module", "Adds checks for bugprone code constructs.");
|
|
|
|
|
|
|
|
// This anchor is used to force the linker to link in the generated object file
|
|
|
|
// and thus register the BugproneModule.
|
|
|
|
volatile int BugproneModuleAnchorSource = 0;
|
|
|
|
|
|
|
|
} // namespace tidy
|
|
|
|
} // namespace clang
|