Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[clang-tidy] enable readability-container-size-empty check #55279

Merged
merged 5 commits into from
Jul 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
209 changes: 209 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,209 @@
---
Checks: '
-bugprone-argument-comment,
-bugprone-assert-side-effect,
-bugprone-bad-signal-to-kill-thread,
-bugprone-bool-pointer-implicit-conversion,
-bugprone-branch-clone,
-bugprone-copy-constructor-init,
-bugprone-dangling-handle,
-bugprone-dynamic-static-initializers,
-bugprone-exception-escape,
-bugprone-fold-init-type,
-bugprone-forwarding-reference-overload,
-bugprone-inaccurate-erase,
-bugprone-incorrect-roundings,
-bugprone-infinite-loop,
-bugprone-integer-division,
-bugprone-macro-repeated-side-effects,
-bugprone-misplaced-operator-in-strlen-in-alloc,
-bugprone-misplaced-widening-cast,
-bugprone-move-forwarding-reference,
-bugprone-multiple-statement-macro,
-bugprone-narrowing-conversions,
-bugprone-not-null-terminated-result,
-bugprone-parent-virtual-call,
-bugprone-posix-return,
-bugprone-signed-char-misuse,
-bugprone-sizeof-container,
-bugprone-sizeof-expression,
-bugprone-string-constructor,
-bugprone-string-integer-assignment,
-bugprone-string-literal-with-embedded-nul,
-bugprone-suspicious-enum-usage,
-bugprone-suspicious-memset-usage,
-bugprone-suspicious-missing-comma,
-bugprone-suspicious-semicolon,
-bugprone-suspicious-string-compare,
-bugprone-terminating-continue,
-bugprone-throw-keyword-missing,
-bugprone-too-small-loop-variable,
-bugprone-undefined-memory-manipulation,
-bugprone-undelegated-constructor,
-bugprone-unhandled-self-assignment,
-bugprone-unused-raii,
-bugprone-unused-return-value,
-bugprone-use-after-move,
-bugprone-virtual-near-miss,
-clang-analyzer-apiModeling.StdCLibraryFunctions,
-clang-analyzer-apiModeling.TrustNonnull,
-clang-analyzer-apiModeling.google.GTest,
-clang-analyzer-apiModeling.llvm.CastValue,
-clang-analyzer-apiModeling.llvm.ReturnValue,
-clang-analyzer-core.CallAndMessage,
-clang-analyzer-core.DivideZero,
-clang-analyzer-core.DynamicTypePropagation,
-clang-analyzer-core.NonNullParamChecker,
-clang-analyzer-core.NonnilStringConstants,
-clang-analyzer-core.NullDereference,
-clang-analyzer-core.StackAddrEscapeBase,
-clang-analyzer-core.StackAddressEscape,
-clang-analyzer-core.UndefinedBinaryOperatorResult,
-clang-analyzer-core.VLASize,
-clang-analyzer-core.builtin.BuiltinFunctions,
-clang-analyzer-core.builtin.NoReturnFunctions,
-clang-analyzer-core.uninitialized.ArraySubscript,
-clang-analyzer-core.uninitialized.Assign,
-clang-analyzer-core.uninitialized.Branch,
-clang-analyzer-core.uninitialized.CapturedBlockVariable,
-clang-analyzer-core.uninitialized.UndefReturn,
-clang-analyzer-cplusplus.InnerPointer,
-clang-analyzer-cplusplus.Move,
-clang-analyzer-cplusplus.NewDelete,
-clang-analyzer-cplusplus.NewDeleteLeaks,
-clang-analyzer-cplusplus.PureVirtualCall,
-clang-analyzer-cplusplus.SelfAssignment,
-clang-analyzer-cplusplus.SmartPtr,
-clang-analyzer-cplusplus.VirtualCallModeling,
-clang-analyzer-deadcode.DeadStores,
-clang-analyzer-fuchsia.HandleChecker,
-clang-analyzer-nullability.NullPassedToNonnull,
-clang-analyzer-nullability.NullReturnedFromNonnull,
-clang-analyzer-nullability.NullabilityBase,
-clang-analyzer-nullability.NullableDereferenced,
-clang-analyzer-nullability.NullablePassedToNonnull,
-clang-analyzer-nullability.NullableReturnedFromNonnull,
-clang-analyzer-optin.cplusplus.UninitializedObject,
-clang-analyzer-optin.cplusplus.VirtualCall,
-clang-analyzer-optin.mpi.MPI-Checker,
-clang-analyzer-optin.osx.OSObjectCStyleCast,
-clang-analyzer-optin.osx.cocoa.localizability.EmptyLocalizationContextChecker,
-clang-analyzer-optin.osx.cocoa.localizability.NonLocalizedStringChecker,
-clang-analyzer-optin.performance.GCDAntipattern,
-clang-analyzer-optin.performance.Padding,
-clang-analyzer-optin.portability.UnixAPI,
-clang-analyzer-osx.API,
-clang-analyzer-osx.MIG,
-clang-analyzer-osx.NSOrCFErrorDerefChecker,
-clang-analyzer-osx.NumberObjectConversion,
-clang-analyzer-osx.OSObjectRetainCount,
-clang-analyzer-osx.ObjCProperty,
-clang-analyzer-osx.SecKeychainAPI,
-clang-analyzer-osx.cocoa.AtSync,
-clang-analyzer-osx.cocoa.AutoreleaseWrite,
-clang-analyzer-osx.cocoa.ClassRelease,
-clang-analyzer-osx.cocoa.Dealloc,
-clang-analyzer-osx.cocoa.IncompatibleMethodTypes,
-clang-analyzer-osx.cocoa.Loops,
-clang-analyzer-osx.cocoa.MissingSuperCall,
-clang-analyzer-osx.cocoa.NSAutoreleasePool,
-clang-analyzer-osx.cocoa.NSError,
-clang-analyzer-osx.cocoa.NilArg,
-clang-analyzer-osx.cocoa.NonNilReturnValue,
-clang-analyzer-osx.cocoa.ObjCGenerics,
-clang-analyzer-osx.cocoa.RetainCount,
-clang-analyzer-osx.cocoa.RetainCountBase,
-clang-analyzer-osx.cocoa.RunLoopAutoreleaseLeak,
-clang-analyzer-osx.cocoa.SelfInit,
-clang-analyzer-osx.cocoa.SuperDealloc,
-clang-analyzer-osx.cocoa.UnusedIvars,
-clang-analyzer-osx.cocoa.VariadicMethodTypes,
-clang-analyzer-osx.coreFoundation.CFError,
-clang-analyzer-osx.coreFoundation.CFNumber,
-clang-analyzer-osx.coreFoundation.CFRetainRelease,
-clang-analyzer-osx.coreFoundation.containers.OutOfBounds,
-clang-analyzer-osx.coreFoundation.containers.PointerSizedValues,
-clang-analyzer-security.FloatLoopCounter,
-clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling,
-clang-analyzer-security.insecureAPI.SecuritySyntaxChecker,
-clang-analyzer-security.insecureAPI.UncheckedReturn,
-clang-analyzer-security.insecureAPI.bcmp,
-clang-analyzer-security.insecureAPI.bcopy,
-clang-analyzer-security.insecureAPI.bzero,
-clang-analyzer-security.insecureAPI.decodeValueOfObjCType,
-clang-analyzer-security.insecureAPI.getpw,
-clang-analyzer-security.insecureAPI.gets,
-clang-analyzer-security.insecureAPI.mkstemp,
-clang-analyzer-security.insecureAPI.mktemp,
-clang-analyzer-security.insecureAPI.rand,
-clang-analyzer-security.insecureAPI.strcpy,
-clang-analyzer-security.insecureAPI.vfork,
-clang-analyzer-unix.API,
-clang-analyzer-unix.DynamicMemoryModeling,
-clang-analyzer-unix.Malloc,
-clang-analyzer-unix.MallocSizeof,
-clang-analyzer-unix.MismatchedDeallocator,
-clang-analyzer-unix.Vfork,
-clang-analyzer-unix.cstring.BadSizeArg,
-clang-analyzer-unix.cstring.CStringModeling,
-clang-analyzer-unix.cstring.NullArg,
-clang-analyzer-valist.CopyToSelf,
-clang-analyzer-valist.Uninitialized,
-clang-analyzer-valist.Unterminated,
-clang-analyzer-valist.ValistBase,
-cppcoreguidelines-avoid-c-arrays,
-cppcoreguidelines-avoid-goto,
-cppcoreguidelines-c-copy-assignment-signature,
-cppcoreguidelines-explicit-virtual-functions,
-cppcoreguidelines-init-variables,
-cppcoreguidelines-narrowing-conversions,
-cppcoreguidelines-no-malloc,
-cppcoreguidelines-pro-type-const-cast,
-cppcoreguidelines-pro-type-member-init,
-cppcoreguidelines-slicing,
-hicpp-avoid-goto,
-hicpp-exception-baseclass,
-misc-unused-alias-decls,
-misc-unused-using-decls,
-modernize-avoid-bind,
-modernize-avoid-c-arrays,
-modernize-deprecated-headers,
-modernize-deprecated-ios-base-aliases,
-modernize-loop-convert,
-modernize-make-shared,
-modernize-make-unique,
-modernize-pass-by-value,
-modernize-raw-string-literal,
-modernize-redundant-void-arg,
-modernize-replace-auto-ptr,
-modernize-replace-random-shuffle,
-modernize-shrink-to-fit,
-modernize-unary-static-assert,
-modernize-use-bool-literals,
-modernize-use-emplace,
-modernize-use-equals-default,
-modernize-use-equals-delete,
-modernize-use-noexcept,
-modernize-use-nullptr,
-modernize-use-override,
-modernize-use-transparent-functors,
-modernize-use-uncaught-exceptions,
-performance-faster-string-find,
-performance-for-range-copy,
-performance-implicit-conversion-in-loop,
-performance-inefficient-algorithm,
-performance-inefficient-string-concatenation,
-performance-inefficient-vector-operation,
-performance-move-const-arg,
-performance-move-constructor-init,
-performance-no-automatic-move,
-performance-noexcept-move-constructor,
-performance-trivially-destructible,
-performance-type-promotion-in-math-fn,
-performance-unnecessary-copy-initialization,
readability-container-size-empty,
'
HeaderFilterRegex: '^(paddle/(?!cinn)).*$'
AnalyzeTemporaryDtors: false
WarningsAsErrors: '*'
...
33 changes: 33 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,39 @@ repos:
(?x)^(
paddle/utils/flat_hash_map\.h
)$
- repo: local
hooks:
- id: clang-tidy
name: clang-tidy
description: Parallel clang-tidy runner.
entry: python ./tools/codestyle/clang-tidy.py
language: system
files: \.(c|cc|cxx|cpp|h|hpp|hxx)$
args:
- -p=build/
- -extra-arg=-Wno-unknown-warning-option
- -extra-arg=-Wno-pessimizing-move
- -extra-arg=-Wno-braced-scalar-init
- -extra-arg=-Wno-dangling-gsl
- -extra-arg=-Wno-deprecated-copy
- -extra-arg=-Wno-final-dtor-non-final-class
- -extra-arg=-Wno-implicit-int-float-conversion
- -extra-arg=-Wno-inconsistent-missing-override
- -extra-arg=-Wno-infinite-recursion
- -extra-arg=-Wno-mismatched-tags
- -extra-arg=-Wno-self-assign
- -extra-arg=-Wno-sign-compare
- -extra-arg=-Wno-sometimes-uninitialized
- -extra-arg=-Wno-tautological-overlap-compare
- -extra-arg=-Wno-unused-const-variable
- -extra-arg=-Wno-unused-lambda-capture
- -extra-arg=-Wno-unused-private-field
- -extra-arg=-Wno-unused-value
- -extra-arg=-Wno-unused-variable
- -extra-arg=-Wno-overloaded-virtual
- -extra-arg=-Wno-defaulted-function-deleted
- -extra-arg=-Wno-delete-non-abstract-non-virtual-dtor
- -extra-arg=-Wno-return-type-c-linkage
# For CMake files
- repo: local
hooks:
Expand Down
4 changes: 2 additions & 2 deletions paddle/fluid/distributed/collective/process_group_nccl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ void ProcessGroupNCCL::BroadcastUniqueNCCLID(ncclUniqueId* nccl_id) {

void ProcessGroupNCCL::CreateNCCLEnvCache(const Place& place,
const std::string& place_key) {
if (place_to_comm_ctx_.size() > 0) {
if (!place_to_comm_ctx_.empty()) {
VLOG(3) << "Warning: Tensors from multiple devices are not supported yet.";
}

Expand Down Expand Up @@ -795,7 +795,7 @@ std::shared_ptr<ProcessGroup::Task> ProcessGroupNCCL::Broadcast(
void CheckTensorsInDifferentDevices(
const std::vector<phi::DenseTensor>& tensors, const size_t num_devices) {
PADDLE_ENFORCE_EQ(
tensors.size() == 0,
tensors.empty(),
false,
phi::errors::InvalidArgument("Tensor list must be nonempty."));
PADDLE_ENFORCE_LE(
Expand Down
4 changes: 2 additions & 2 deletions paddle/fluid/distributed/fleet_executor/dist_model.cc
Original file line number Diff line number Diff line change
Expand Up @@ -541,11 +541,11 @@ bool DistModel::PrepareFeedAndFetch() {
}
}

if (feeds_.size() == 0) {
if (feeds_.empty()) {
LOG(ERROR) << "No feed ops in the inf program, please check the program.";
return false;
}
if (fetches_.size() == 0) {
if (fetches_.empty()) {
LOG(ERROR) << "No fetch op in the inf program, please check the program.";
return false;
}
Expand Down
6 changes: 3 additions & 3 deletions paddle/fluid/distributed/fleet_executor/fleet_executor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ void FleetExecutor::InitMessageBus() {
addr = ip_port;
}
}
if (addr == "") {
if (addr.empty()) {
PADDLE_ENFORCE_EQ(
rank_to_addr.size(),
1,
Expand All @@ -273,9 +273,9 @@ void FleetExecutor::InitMessageBus() {
platform::errors::NotFound("Address is empty but cur rank is not 0."));
}
VLOG(3) << "Current rank is " << cur_rank << " and the ip_port is "
<< (addr == "" ? "empty" : addr) << ".";
<< (addr.empty() ? "empty" : addr) << ".";
VLOG(3) << "The number of ranks are "
<< (rank_to_addr.size() == 0 ? 1 : rank_to_addr.size()) << ".";
<< (rank_to_addr.empty() ? 1 : rank_to_addr.size()) << ".";
VLOG(5) << ss.str();
GlobalVal<MessageBus>::Get()->Init(cur_rank, rank_to_addr, addr);
}
Expand Down
6 changes: 3 additions & 3 deletions paddle/fluid/distributed/fleet_executor/message_bus.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ void MessageBus::Init(
rank_to_addr_ = rank_to_addr;
addr_ = addr;

if (addr_ != "") {
if (!addr_.empty()) {
const auto& addr = GetAddr(rank_);
PADDLE_ENFORCE_EQ(addr,
addr_,
Expand All @@ -55,7 +55,7 @@ void MessageBus::Init(
defined(PADDLE_WITH_XPU_BKCL) || defined(PADDLE_WITH_CUSTOM_DEVICE)
// NOTE: To make the brpc is compatible with collective,
// need release the handler holding the ip address.
if (addr_ != "") {
if (!addr_.empty()) {
VLOG(3) << "Message bus is releasing the fd held by gen_comm_id.";
paddle::platform::SocketServer& socket_server =
paddle::platform::SocketServer::GetInstance(addr_);
Expand Down Expand Up @@ -174,7 +174,7 @@ bool MessageBus::DispatchMsgToCarrier(
}

void MessageBus::ListenPort() {
if (addr_ == "") {
if (addr_.empty()) {
LOG(INFO) << "No need listen to port since training on single card.";
return;
}
Expand Down
4 changes: 2 additions & 2 deletions paddle/fluid/distributed/ps/service/brpc_ps_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ int32_t BrpcPsService::PushSparseParam(Table *table,
1);
CHECK_TABLE_EXIST(table, request, response)
auto &push_data = request.data();
if (push_data.size() < 1) {
if (push_data.empty()) {
// set_response_code(response, 0, "push sparse data is empty");
return 0;
}
Expand Down Expand Up @@ -557,7 +557,7 @@ int32_t BrpcPsService::PushSparse(Table *table,
"PsService->PushSparse", platform::TracerEventType::Communication, 1);
CHECK_TABLE_EXIST(table, request, response)
auto &push_data = request.data();
if (push_data.size() < 1) {
if (push_data.empty()) {
// set_response_code(response, 0, "push sparse data is empty");
return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion paddle/fluid/distributed/ps/service/brpc_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ void SerializeLodTensor(framework::Variable* var,
auto* tensor = var->GetMutable<phi::DenseTensor>();
var_msg->set_type(::paddle::distributed::LOD_TENSOR);
const framework::LoD lod = tensor->lod();
if (lod.size() > 0) {
if (!lod.empty()) {
var_msg->set_lod_level(lod.size());
for (auto& each : lod) {
VarMsg::LodData* lod_inner = var_msg->add_lod();
Expand Down
Loading