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-02-10 01:50:40 +08:00
|
|
|
#include "AssignOperatorSignatureCheck.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"
|
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-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"
|
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-16 00:31:15 +08:00
|
|
|
#include "PointerAndIntegralOperationCheck.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"
|
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-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"
|
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"
|
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");
|
2015-02-10 01:50:40 +08:00
|
|
|
CheckFactories.registerCheck<AssignOperatorSignatureCheck>(
|
|
|
|
"misc-assign-operator-signature");
|
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-03-30 02:02:26 +08:00
|
|
|
CheckFactories.registerCheck<DanglingHandleCheck>(
|
|
|
|
"misc-dangling-handle");
|
2016-01-09 00:37:11 +08:00
|
|
|
CheckFactories.registerCheck<DefinitionsInHeadersCheck>(
|
|
|
|
"misc-definitions-in-headers");
|
2016-04-26 18:05:45 +08:00
|
|
|
CheckFactories.registerCheck<FoldInitTypeCheck>(
|
|
|
|
"misc-fold-init-type");
|
2016-02-24 21:35:32 +08:00
|
|
|
CheckFactories.registerCheck<ForwardDeclarationNamespaceCheck>(
|
|
|
|
"misc-forward-declaration-namespace");
|
2015-02-10 17:14:26 +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");
|
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-16 00:31:15 +08:00
|
|
|
CheckFactories.registerCheck<PointerAndIntegralOperationCheck>(
|
|
|
|
"misc-pointer-and-integral-operation");
|
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");
|
2015-03-02 18:46:43 +08:00
|
|
|
CheckFactories.registerCheck<StaticAssertCheck>(
|
|
|
|
"misc-static-assert");
|
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-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>(
|
|
|
|
"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");
|
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>
|
2014-03-05 21:14:32 +08:00
|
|
|
X("misc-module", "Adds miscellaneous lint checks.");
|
|
|
|
|
|
|
|
// 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
|