2014-03-05 21:14:32 +08:00
|
|
|
//===--- MiscTidyModule.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"
|
2014-03-18 12:46:45 +08:00
|
|
|
#include "ArgumentCommentCheck.h"
|
2015-03-02 18:46:43 +08:00
|
|
|
#include "AssertSideEffectCheck.h"
|
2015-03-09 19:48:54 +08:00
|
|
|
#include "BoolPointerImplicitConversionCheck.h"
|
2016-03-30 02:02:26 +08:00
|
|
|
#include "DanglingHandleCheck.h"
|
2016-01-09 00:37:11 +08:00
|
|
|
#include "DefinitionsInHeadersCheck.h"
|
2016-04-26 18:05:45 +08:00
|
|
|
#include "FoldInitTypeCheck.h"
|
2016-02-24 21:35:32 +08:00
|
|
|
#include "ForwardDeclarationNamespaceCheck.h"
|
2017-04-06 17:56:42 +08:00
|
|
|
#include "ForwardingReferenceOverloadCheck.h"
|
2015-02-10 17:14:26 +08:00
|
|
|
#include "InaccurateEraseCheck.h"
|
2016-02-08 18:16:13 +08:00
|
|
|
#include "IncorrectRoundings.h"
|
2015-02-08 03:54:19 +08:00
|
|
|
#include "InefficientAlgorithmCheck.h"
|
2015-06-16 22:27:31 +08:00
|
|
|
#include "MacroParenthesesCheck.h"
|
2015-06-17 22:19:35 +08:00
|
|
|
#include "MacroRepeatedSideEffectsCheck.h"
|
2016-11-08 15:50:19 +08:00
|
|
|
#include "MisplacedConstCheck.h"
|
2016-02-09 22:08:49 +08:00
|
|
|
#include "MisplacedWideningCastCheck.h"
|
2015-11-25 23:56:11 +08:00
|
|
|
#include "MoveConstantArgumentCheck.h"
|
2015-08-20 23:52:52 +08:00
|
|
|
#include "MoveConstructorInitCheck.h"
|
[clang-tidy] Add check 'misc-move-forwarding-reference'
Summary:
The check emits a warning if std::move() is applied to a forwarding reference, i.e. an rvalue reference of a function template argument type.
If a developer is unaware of the special rules for template argument deduction on forwarding references, it will seem reasonable to apply std::move() to the forwarding reference, in the same way that this would be done for a "normal" rvalue reference.
This has a consequence that is usually unwanted and possibly surprising: If the function that takes the forwarding reference as its parameter is called with an lvalue, that lvalue will be moved from (and hence placed into an indeterminate state) even though no std::move() was applied to the lvalue at the callsite.
As a fix, the check will suggest replacing the std::move() with a std::forward().
This patch requires D23004 to be submitted before it.
Reviewers: sbenza, aaron.ballman
Subscribers: klimek, etienneb, alexfh, aaron.ballman, Prazek, Eugene.Zelenko, mgehre, cfe-commits
Projects: #clang-tools-extra
Differential Revision: https://reviews.llvm.org/D22220
llvm-svn: 280077
2016-08-30 20:11:12 +08:00
|
|
|
#include "MoveForwardingReferenceCheck.h"
|
2016-04-15 05:15:57 +08:00
|
|
|
#include "MultipleStatementMacroCheck.h"
|
2015-09-29 21:12:21 +08:00
|
|
|
#include "NewDeleteOverloadsCheck.h"
|
2015-05-27 22:24:11 +08:00
|
|
|
#include "NoexceptMoveConstructorCheck.h"
|
2015-09-30 22:09:38 +08:00
|
|
|
#include "NonCopyableObjects.h"
|
2016-04-27 01:30:30 +08:00
|
|
|
#include "RedundantExpressionCheck.h"
|
2015-09-11 00:37:46 +08:00
|
|
|
#include "SizeofContainerCheck.h"
|
[clang-tidy] Add new checker for suspicious sizeof expressions
Summary:
This check is finding suspicious cases of sizeof expression.
Sizeof expression is returning the size (in bytes) of a type or an
expression. Programmers often abuse or misuse this expression.
This checker is adding common set of patterns to detect some
of these bad constructs.
Some examples found by this checker:
R/packages/ifultools/ifultools/src/fra_neig.c
```
/* free buffer memory */
(void) mutil_free( dist_buff, sizeof( ctr * sizeof( double ) ) );
(void) mutil_free( nidx_buff, sizeof( ctr * sizeof( sint32 ) ) );
```
graphviz/v2_20_2/lib/common/utils.c
```
static Dtdisc_t mapDisc = {
offsetof(item, p),
sizeof(2 * sizeof(void *)),
offsetof(item, link),
(Dtmake_f) newItem,
(Dtfree_f) freeItem,
(Dtcompar_f) cmpItem,
NIL(Dthash_f),
NIL(Dtmemory_f),
NIL(Dtevent_f)
};
```
mDNSResponder/mDNSShared/dnsextd.c
```
context = ( TCPContext* ) malloc( sizeof( TCPContext ) );
require_action( context, exit, err = mStatus_NoMemoryErr; LogErr( "AcceptTCPConnection", "malloc" ) );
mDNSPlatformMemZero( context, sizeof( sizeof( TCPContext ) ) );
context->d = self;
```
Reviewers: alexfh
Subscribers: malcolm.parsons, Eugene.Zelenko, cfe-commits
Differential Revision: http://reviews.llvm.org/D19014
llvm-svn: 266451
2016-04-16 00:36:00 +08:00
|
|
|
#include "SizeofExpressionCheck.h"
|
2015-03-02 18:46:43 +08:00
|
|
|
#include "StaticAssertCheck.h"
|
[clang-tidy] Add check 'misc-string-compare'.
I have a created a new check for clang tidy: misc-string-compare. This will check for incorrect usage of std::string::compare when used to check equality or inequality of string instead of the string equality or inequality operators.
Example:
```
std::string str1, str2;
if (str1.compare(str2)) {
}
```
Reviewers: hokein, aaron.ballman, alexfh, malcolm.parsons
Subscribers: xazax.hun, Eugene.Zelenko, cfe-commits, malcolm.parsons, Prazek, mgorny, JDevlieghere
Differential Revision: https://reviews.llvm.org/D27210
llvm-svn: 290747
2016-12-30 18:09:46 +08:00
|
|
|
#include "StringCompareCheck.h"
|
2016-04-22 01:28:08 +08:00
|
|
|
#include "StringConstructorCheck.h"
|
2015-12-15 16:47:20 +08:00
|
|
|
#include "StringIntegerAssignmentCheck.h"
|
2016-04-08 00:16:36 +08:00
|
|
|
#include "StringLiteralWithEmbeddedNulCheck.h"
|
2016-12-27 18:07:39 +08:00
|
|
|
#include "SuspiciousEnumUsageCheck.h"
|
2016-04-01 02:12:23 +08:00
|
|
|
#include "SuspiciousMissingCommaCheck.h"
|
2016-02-11 17:23:33 +08:00
|
|
|
#include "SuspiciousSemicolonCheck.h"
|
2016-04-22 01:19:36 +08:00
|
|
|
#include "SuspiciousStringCompareCheck.h"
|
2014-07-14 22:24:30 +08:00
|
|
|
#include "SwappedArgumentsCheck.h"
|
2015-10-10 04:42:44 +08:00
|
|
|
#include "ThrowByValueCatchByReferenceCheck.h"
|
2016-11-08 15:50:19 +08:00
|
|
|
#include "UnconventionalAssignOperatorCheck.h"
|
2014-07-31 17:58:52 +08:00
|
|
|
#include "UndelegatedConstructor.h"
|
2015-03-09 19:48:54 +08:00
|
|
|
#include "UniqueptrResetReleaseCheck.h"
|
2015-08-01 00:08:10 +08:00
|
|
|
#include "UnusedAliasDeclsCheck.h"
|
2015-07-20 09:06:44 +08:00
|
|
|
#include "UnusedParametersCheck.h"
|
2015-03-09 19:48:54 +08:00
|
|
|
#include "UnusedRAIICheck.h"
|
2016-04-19 21:48:39 +08:00
|
|
|
#include "UnusedUsingDeclsCheck.h"
|
[clang-tidy] Add check 'misc-use-after-move'
Summary:
The check warns if an object is used after it has been moved, without an
intervening reinitialization.
See user-facing documentation for details.
Reviewers: sbenza, Prazek, alexfh
Subscribers: beanz, mgorny, shadeware, omtcyfz, Eugene.Zelenko, Prazek, fowles, ioeric, cfe-commits
Differential Revision: https://reviews.llvm.org/D23353
llvm-svn: 281453
2016-09-14 18:29:32 +08:00
|
|
|
#include "UseAfterMoveCheck.h"
|
2016-01-13 22:16:35 +08:00
|
|
|
#include "VirtualNearMissCheck.h"
|
2014-03-05 21:14:32 +08:00
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
namespace tidy {
|
2015-03-02 20:25:03 +08:00
|
|
|
namespace misc {
|
2014-03-05 21:14:32 +08:00
|
|
|
|
|
|
|
class MiscModule : public ClangTidyModule {
|
|
|
|
public:
|
|
|
|
void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
|
2014-09-10 19:06:43 +08:00
|
|
|
CheckFactories.registerCheck<ArgumentCommentCheck>("misc-argument-comment");
|
2015-03-02 18:46:43 +08:00
|
|
|
CheckFactories.registerCheck<AssertSideEffectCheck>(
|
|
|
|
"misc-assert-side-effect");
|
2017-04-06 17:56:42 +08:00
|
|
|
CheckFactories.registerCheck<ForwardingReferenceOverloadCheck>(
|
|
|
|
"misc-forwarding-reference-overload");
|
2016-11-08 15:50:19 +08:00
|
|
|
CheckFactories.registerCheck<MisplacedConstCheck>("misc-misplaced-const");
|
2016-05-04 20:02:22 +08:00
|
|
|
CheckFactories.registerCheck<UnconventionalAssignOperatorCheck>(
|
|
|
|
"misc-unconventional-assign-operator");
|
2015-03-09 19:48:54 +08:00
|
|
|
CheckFactories.registerCheck<BoolPointerImplicitConversionCheck>(
|
2014-09-10 19:06:43 +08:00
|
|
|
"misc-bool-pointer-implicit-conversion");
|
2016-11-08 15:50:19 +08:00
|
|
|
CheckFactories.registerCheck<DanglingHandleCheck>("misc-dangling-handle");
|
2016-01-09 00:37:11 +08:00
|
|
|
CheckFactories.registerCheck<DefinitionsInHeadersCheck>(
|
|
|
|
"misc-definitions-in-headers");
|
2016-11-08 15:50:19 +08:00
|
|
|
CheckFactories.registerCheck<FoldInitTypeCheck>("misc-fold-init-type");
|
2016-02-24 21:35:32 +08:00
|
|
|
CheckFactories.registerCheck<ForwardDeclarationNamespaceCheck>(
|
|
|
|
"misc-forward-declaration-namespace");
|
2016-11-08 15:50:19 +08:00
|
|
|
CheckFactories.registerCheck<InaccurateEraseCheck>("misc-inaccurate-erase");
|
2016-02-08 18:16:13 +08:00
|
|
|
CheckFactories.registerCheck<IncorrectRoundings>(
|
|
|
|
"misc-incorrect-roundings");
|
2015-02-08 03:54:19 +08:00
|
|
|
CheckFactories.registerCheck<InefficientAlgorithmCheck>(
|
|
|
|
"misc-inefficient-algorithm");
|
2015-06-16 22:27:31 +08:00
|
|
|
CheckFactories.registerCheck<MacroParenthesesCheck>(
|
|
|
|
"misc-macro-parentheses");
|
2015-06-17 22:19:35 +08:00
|
|
|
CheckFactories.registerCheck<MacroRepeatedSideEffectsCheck>(
|
|
|
|
"misc-macro-repeated-side-effects");
|
2016-02-09 22:08:49 +08:00
|
|
|
CheckFactories.registerCheck<MisplacedWideningCastCheck>(
|
|
|
|
"misc-misplaced-widening-cast");
|
2015-11-25 23:56:11 +08:00
|
|
|
CheckFactories.registerCheck<MoveConstantArgumentCheck>(
|
|
|
|
"misc-move-const-arg");
|
2015-08-20 23:52:52 +08:00
|
|
|
CheckFactories.registerCheck<MoveConstructorInitCheck>(
|
|
|
|
"misc-move-constructor-init");
|
[clang-tidy] Add check 'misc-move-forwarding-reference'
Summary:
The check emits a warning if std::move() is applied to a forwarding reference, i.e. an rvalue reference of a function template argument type.
If a developer is unaware of the special rules for template argument deduction on forwarding references, it will seem reasonable to apply std::move() to the forwarding reference, in the same way that this would be done for a "normal" rvalue reference.
This has a consequence that is usually unwanted and possibly surprising: If the function that takes the forwarding reference as its parameter is called with an lvalue, that lvalue will be moved from (and hence placed into an indeterminate state) even though no std::move() was applied to the lvalue at the callsite.
As a fix, the check will suggest replacing the std::move() with a std::forward().
This patch requires D23004 to be submitted before it.
Reviewers: sbenza, aaron.ballman
Subscribers: klimek, etienneb, alexfh, aaron.ballman, Prazek, Eugene.Zelenko, mgehre, cfe-commits
Projects: #clang-tools-extra
Differential Revision: https://reviews.llvm.org/D22220
llvm-svn: 280077
2016-08-30 20:11:12 +08:00
|
|
|
CheckFactories.registerCheck<MoveForwardingReferenceCheck>(
|
|
|
|
"misc-move-forwarding-reference");
|
2016-04-15 05:15:57 +08:00
|
|
|
CheckFactories.registerCheck<MultipleStatementMacroCheck>(
|
|
|
|
"misc-multiple-statement-macro");
|
2015-09-29 21:12:21 +08:00
|
|
|
CheckFactories.registerCheck<NewDeleteOverloadsCheck>(
|
|
|
|
"misc-new-delete-overloads");
|
2015-05-27 22:24:11 +08:00
|
|
|
CheckFactories.registerCheck<NoexceptMoveConstructorCheck>(
|
|
|
|
"misc-noexcept-move-constructor");
|
2015-09-30 22:09:38 +08:00
|
|
|
CheckFactories.registerCheck<NonCopyableObjectsCheck>(
|
|
|
|
"misc-non-copyable-objects");
|
2016-04-27 01:30:30 +08:00
|
|
|
CheckFactories.registerCheck<RedundantExpressionCheck>(
|
|
|
|
"misc-redundant-expression");
|
2015-09-30 22:09:38 +08:00
|
|
|
CheckFactories.registerCheck<SizeofContainerCheck>("misc-sizeof-container");
|
[clang-tidy] Add new checker for suspicious sizeof expressions
Summary:
This check is finding suspicious cases of sizeof expression.
Sizeof expression is returning the size (in bytes) of a type or an
expression. Programmers often abuse or misuse this expression.
This checker is adding common set of patterns to detect some
of these bad constructs.
Some examples found by this checker:
R/packages/ifultools/ifultools/src/fra_neig.c
```
/* free buffer memory */
(void) mutil_free( dist_buff, sizeof( ctr * sizeof( double ) ) );
(void) mutil_free( nidx_buff, sizeof( ctr * sizeof( sint32 ) ) );
```
graphviz/v2_20_2/lib/common/utils.c
```
static Dtdisc_t mapDisc = {
offsetof(item, p),
sizeof(2 * sizeof(void *)),
offsetof(item, link),
(Dtmake_f) newItem,
(Dtfree_f) freeItem,
(Dtcompar_f) cmpItem,
NIL(Dthash_f),
NIL(Dtmemory_f),
NIL(Dtevent_f)
};
```
mDNSResponder/mDNSShared/dnsextd.c
```
context = ( TCPContext* ) malloc( sizeof( TCPContext ) );
require_action( context, exit, err = mStatus_NoMemoryErr; LogErr( "AcceptTCPConnection", "malloc" ) );
mDNSPlatformMemZero( context, sizeof( sizeof( TCPContext ) ) );
context->d = self;
```
Reviewers: alexfh
Subscribers: malcolm.parsons, Eugene.Zelenko, cfe-commits
Differential Revision: http://reviews.llvm.org/D19014
llvm-svn: 266451
2016-04-16 00:36:00 +08:00
|
|
|
CheckFactories.registerCheck<SizeofExpressionCheck>(
|
|
|
|
"misc-sizeof-expression");
|
2016-11-08 15:50:19 +08:00
|
|
|
CheckFactories.registerCheck<StaticAssertCheck>("misc-static-assert");
|
[clang-tidy] Add check 'misc-string-compare'.
I have a created a new check for clang tidy: misc-string-compare. This will check for incorrect usage of std::string::compare when used to check equality or inequality of string instead of the string equality or inequality operators.
Example:
```
std::string str1, str2;
if (str1.compare(str2)) {
}
```
Reviewers: hokein, aaron.ballman, alexfh, malcolm.parsons
Subscribers: xazax.hun, Eugene.Zelenko, cfe-commits, malcolm.parsons, Prazek, mgorny, JDevlieghere
Differential Revision: https://reviews.llvm.org/D27210
llvm-svn: 290747
2016-12-30 18:09:46 +08:00
|
|
|
CheckFactories.registerCheck<StringCompareCheck>("misc-string-compare");
|
2016-04-22 01:28:08 +08:00
|
|
|
CheckFactories.registerCheck<StringConstructorCheck>(
|
|
|
|
"misc-string-constructor");
|
2015-12-15 16:47:20 +08:00
|
|
|
CheckFactories.registerCheck<StringIntegerAssignmentCheck>(
|
|
|
|
"misc-string-integer-assignment");
|
2016-04-08 00:16:36 +08:00
|
|
|
CheckFactories.registerCheck<StringLiteralWithEmbeddedNulCheck>(
|
|
|
|
"misc-string-literal-with-embedded-nul");
|
2016-12-27 18:07:39 +08:00
|
|
|
CheckFactories.registerCheck<SuspiciousEnumUsageCheck>(
|
|
|
|
"misc-suspicious-enum-usage");
|
2016-04-01 02:12:23 +08:00
|
|
|
CheckFactories.registerCheck<SuspiciousMissingCommaCheck>(
|
|
|
|
"misc-suspicious-missing-comma");
|
2016-02-11 17:23:33 +08:00
|
|
|
CheckFactories.registerCheck<SuspiciousSemicolonCheck>(
|
|
|
|
"misc-suspicious-semicolon");
|
2016-04-22 01:19:36 +08:00
|
|
|
CheckFactories.registerCheck<SuspiciousStringCompareCheck>(
|
2016-08-01 20:06:18 +08:00
|
|
|
"misc-suspicious-string-compare");
|
2014-09-10 19:06:43 +08:00
|
|
|
CheckFactories.registerCheck<SwappedArgumentsCheck>(
|
|
|
|
"misc-swapped-arguments");
|
2015-10-10 04:42:44 +08:00
|
|
|
CheckFactories.registerCheck<ThrowByValueCatchByReferenceCheck>(
|
|
|
|
"misc-throw-by-value-catch-by-reference");
|
2014-09-10 19:06:43 +08:00
|
|
|
CheckFactories.registerCheck<UndelegatedConstructorCheck>(
|
|
|
|
"misc-undelegated-constructor");
|
2015-03-09 19:48:54 +08:00
|
|
|
CheckFactories.registerCheck<UniqueptrResetReleaseCheck>(
|
2014-12-05 19:59:05 +08:00
|
|
|
"misc-uniqueptr-reset-release");
|
2015-08-01 00:08:10 +08:00
|
|
|
CheckFactories.registerCheck<UnusedAliasDeclsCheck>(
|
|
|
|
"misc-unused-alias-decls");
|
2015-07-20 09:06:44 +08:00
|
|
|
CheckFactories.registerCheck<UnusedParametersCheck>(
|
|
|
|
"misc-unused-parameters");
|
2014-09-10 19:06:43 +08:00
|
|
|
CheckFactories.registerCheck<UnusedRAIICheck>("misc-unused-raii");
|
2016-04-19 21:48:39 +08:00
|
|
|
CheckFactories.registerCheck<UnusedUsingDeclsCheck>(
|
|
|
|
"misc-unused-using-decls");
|
[clang-tidy] Add check 'misc-use-after-move'
Summary:
The check warns if an object is used after it has been moved, without an
intervening reinitialization.
See user-facing documentation for details.
Reviewers: sbenza, Prazek, alexfh
Subscribers: beanz, mgorny, shadeware, omtcyfz, Eugene.Zelenko, Prazek, fowles, ioeric, cfe-commits
Differential Revision: https://reviews.llvm.org/D23353
llvm-svn: 281453
2016-09-14 18:29:32 +08:00
|
|
|
CheckFactories.registerCheck<UseAfterMoveCheck>("misc-use-after-move");
|
2016-01-13 22:16:35 +08:00
|
|
|
CheckFactories.registerCheck<VirtualNearMissCheck>(
|
|
|
|
"misc-virtual-near-miss");
|
2014-03-05 21:14:32 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-03-02 20:25:03 +08:00
|
|
|
} // namespace misc
|
|
|
|
|
2014-03-05 21:14:32 +08:00
|
|
|
// Register the MiscTidyModule using this statically initialized variable.
|
2015-03-02 20:25:03 +08:00
|
|
|
static ClangTidyModuleRegistry::Add<misc::MiscModule>
|
2016-11-08 15:50:19 +08:00
|
|
|
X("misc-module", "Adds miscellaneous lint checks.");
|
2014-03-05 21:14:32 +08:00
|
|
|
|
|
|
|
// This anchor is used to force the linker to link in the generated object file
|
|
|
|
// and thus register the MiscModule.
|
|
|
|
volatile int MiscModuleAnchorSource = 0;
|
|
|
|
|
|
|
|
} // namespace tidy
|
|
|
|
} // namespace clang
|