Skip to content

Commit 2d175d8

Browse files
GreatVwz1qqx
authored andcommitted
[clang-tidy] enable readability-container-size-empty check (PaddlePaddle#55279)
* [clang-tidy] enable readability-container-size-empty check * fix test_custom_kernel Failed * add clang-tid-10 in dockerfile * add clang-tidy in dockerfile * fix bug
1 parent b3d60d1 commit 2d175d8

File tree

185 files changed

+1146
-488
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

185 files changed

+1146
-488
lines changed

.clang-tidy

Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
---
2+
Checks: '
3+
-bugprone-argument-comment,
4+
-bugprone-assert-side-effect,
5+
-bugprone-bad-signal-to-kill-thread,
6+
-bugprone-bool-pointer-implicit-conversion,
7+
-bugprone-branch-clone,
8+
-bugprone-copy-constructor-init,
9+
-bugprone-dangling-handle,
10+
-bugprone-dynamic-static-initializers,
11+
-bugprone-exception-escape,
12+
-bugprone-fold-init-type,
13+
-bugprone-forwarding-reference-overload,
14+
-bugprone-inaccurate-erase,
15+
-bugprone-incorrect-roundings,
16+
-bugprone-infinite-loop,
17+
-bugprone-integer-division,
18+
-bugprone-macro-repeated-side-effects,
19+
-bugprone-misplaced-operator-in-strlen-in-alloc,
20+
-bugprone-misplaced-widening-cast,
21+
-bugprone-move-forwarding-reference,
22+
-bugprone-multiple-statement-macro,
23+
-bugprone-narrowing-conversions,
24+
-bugprone-not-null-terminated-result,
25+
-bugprone-parent-virtual-call,
26+
-bugprone-posix-return,
27+
-bugprone-signed-char-misuse,
28+
-bugprone-sizeof-container,
29+
-bugprone-sizeof-expression,
30+
-bugprone-string-constructor,
31+
-bugprone-string-integer-assignment,
32+
-bugprone-string-literal-with-embedded-nul,
33+
-bugprone-suspicious-enum-usage,
34+
-bugprone-suspicious-memset-usage,
35+
-bugprone-suspicious-missing-comma,
36+
-bugprone-suspicious-semicolon,
37+
-bugprone-suspicious-string-compare,
38+
-bugprone-terminating-continue,
39+
-bugprone-throw-keyword-missing,
40+
-bugprone-too-small-loop-variable,
41+
-bugprone-undefined-memory-manipulation,
42+
-bugprone-undelegated-constructor,
43+
-bugprone-unhandled-self-assignment,
44+
-bugprone-unused-raii,
45+
-bugprone-unused-return-value,
46+
-bugprone-use-after-move,
47+
-bugprone-virtual-near-miss,
48+
-clang-analyzer-apiModeling.StdCLibraryFunctions,
49+
-clang-analyzer-apiModeling.TrustNonnull,
50+
-clang-analyzer-apiModeling.google.GTest,
51+
-clang-analyzer-apiModeling.llvm.CastValue,
52+
-clang-analyzer-apiModeling.llvm.ReturnValue,
53+
-clang-analyzer-core.CallAndMessage,
54+
-clang-analyzer-core.DivideZero,
55+
-clang-analyzer-core.DynamicTypePropagation,
56+
-clang-analyzer-core.NonNullParamChecker,
57+
-clang-analyzer-core.NonnilStringConstants,
58+
-clang-analyzer-core.NullDereference,
59+
-clang-analyzer-core.StackAddrEscapeBase,
60+
-clang-analyzer-core.StackAddressEscape,
61+
-clang-analyzer-core.UndefinedBinaryOperatorResult,
62+
-clang-analyzer-core.VLASize,
63+
-clang-analyzer-core.builtin.BuiltinFunctions,
64+
-clang-analyzer-core.builtin.NoReturnFunctions,
65+
-clang-analyzer-core.uninitialized.ArraySubscript,
66+
-clang-analyzer-core.uninitialized.Assign,
67+
-clang-analyzer-core.uninitialized.Branch,
68+
-clang-analyzer-core.uninitialized.CapturedBlockVariable,
69+
-clang-analyzer-core.uninitialized.UndefReturn,
70+
-clang-analyzer-cplusplus.InnerPointer,
71+
-clang-analyzer-cplusplus.Move,
72+
-clang-analyzer-cplusplus.NewDelete,
73+
-clang-analyzer-cplusplus.NewDeleteLeaks,
74+
-clang-analyzer-cplusplus.PureVirtualCall,
75+
-clang-analyzer-cplusplus.SelfAssignment,
76+
-clang-analyzer-cplusplus.SmartPtr,
77+
-clang-analyzer-cplusplus.VirtualCallModeling,
78+
-clang-analyzer-deadcode.DeadStores,
79+
-clang-analyzer-fuchsia.HandleChecker,
80+
-clang-analyzer-nullability.NullPassedToNonnull,
81+
-clang-analyzer-nullability.NullReturnedFromNonnull,
82+
-clang-analyzer-nullability.NullabilityBase,
83+
-clang-analyzer-nullability.NullableDereferenced,
84+
-clang-analyzer-nullability.NullablePassedToNonnull,
85+
-clang-analyzer-nullability.NullableReturnedFromNonnull,
86+
-clang-analyzer-optin.cplusplus.UninitializedObject,
87+
-clang-analyzer-optin.cplusplus.VirtualCall,
88+
-clang-analyzer-optin.mpi.MPI-Checker,
89+
-clang-analyzer-optin.osx.OSObjectCStyleCast,
90+
-clang-analyzer-optin.osx.cocoa.localizability.EmptyLocalizationContextChecker,
91+
-clang-analyzer-optin.osx.cocoa.localizability.NonLocalizedStringChecker,
92+
-clang-analyzer-optin.performance.GCDAntipattern,
93+
-clang-analyzer-optin.performance.Padding,
94+
-clang-analyzer-optin.portability.UnixAPI,
95+
-clang-analyzer-osx.API,
96+
-clang-analyzer-osx.MIG,
97+
-clang-analyzer-osx.NSOrCFErrorDerefChecker,
98+
-clang-analyzer-osx.NumberObjectConversion,
99+
-clang-analyzer-osx.OSObjectRetainCount,
100+
-clang-analyzer-osx.ObjCProperty,
101+
-clang-analyzer-osx.SecKeychainAPI,
102+
-clang-analyzer-osx.cocoa.AtSync,
103+
-clang-analyzer-osx.cocoa.AutoreleaseWrite,
104+
-clang-analyzer-osx.cocoa.ClassRelease,
105+
-clang-analyzer-osx.cocoa.Dealloc,
106+
-clang-analyzer-osx.cocoa.IncompatibleMethodTypes,
107+
-clang-analyzer-osx.cocoa.Loops,
108+
-clang-analyzer-osx.cocoa.MissingSuperCall,
109+
-clang-analyzer-osx.cocoa.NSAutoreleasePool,
110+
-clang-analyzer-osx.cocoa.NSError,
111+
-clang-analyzer-osx.cocoa.NilArg,
112+
-clang-analyzer-osx.cocoa.NonNilReturnValue,
113+
-clang-analyzer-osx.cocoa.ObjCGenerics,
114+
-clang-analyzer-osx.cocoa.RetainCount,
115+
-clang-analyzer-osx.cocoa.RetainCountBase,
116+
-clang-analyzer-osx.cocoa.RunLoopAutoreleaseLeak,
117+
-clang-analyzer-osx.cocoa.SelfInit,
118+
-clang-analyzer-osx.cocoa.SuperDealloc,
119+
-clang-analyzer-osx.cocoa.UnusedIvars,
120+
-clang-analyzer-osx.cocoa.VariadicMethodTypes,
121+
-clang-analyzer-osx.coreFoundation.CFError,
122+
-clang-analyzer-osx.coreFoundation.CFNumber,
123+
-clang-analyzer-osx.coreFoundation.CFRetainRelease,
124+
-clang-analyzer-osx.coreFoundation.containers.OutOfBounds,
125+
-clang-analyzer-osx.coreFoundation.containers.PointerSizedValues,
126+
-clang-analyzer-security.FloatLoopCounter,
127+
-clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling,
128+
-clang-analyzer-security.insecureAPI.SecuritySyntaxChecker,
129+
-clang-analyzer-security.insecureAPI.UncheckedReturn,
130+
-clang-analyzer-security.insecureAPI.bcmp,
131+
-clang-analyzer-security.insecureAPI.bcopy,
132+
-clang-analyzer-security.insecureAPI.bzero,
133+
-clang-analyzer-security.insecureAPI.decodeValueOfObjCType,
134+
-clang-analyzer-security.insecureAPI.getpw,
135+
-clang-analyzer-security.insecureAPI.gets,
136+
-clang-analyzer-security.insecureAPI.mkstemp,
137+
-clang-analyzer-security.insecureAPI.mktemp,
138+
-clang-analyzer-security.insecureAPI.rand,
139+
-clang-analyzer-security.insecureAPI.strcpy,
140+
-clang-analyzer-security.insecureAPI.vfork,
141+
-clang-analyzer-unix.API,
142+
-clang-analyzer-unix.DynamicMemoryModeling,
143+
-clang-analyzer-unix.Malloc,
144+
-clang-analyzer-unix.MallocSizeof,
145+
-clang-analyzer-unix.MismatchedDeallocator,
146+
-clang-analyzer-unix.Vfork,
147+
-clang-analyzer-unix.cstring.BadSizeArg,
148+
-clang-analyzer-unix.cstring.CStringModeling,
149+
-clang-analyzer-unix.cstring.NullArg,
150+
-clang-analyzer-valist.CopyToSelf,
151+
-clang-analyzer-valist.Uninitialized,
152+
-clang-analyzer-valist.Unterminated,
153+
-clang-analyzer-valist.ValistBase,
154+
-cppcoreguidelines-avoid-c-arrays,
155+
-cppcoreguidelines-avoid-goto,
156+
-cppcoreguidelines-c-copy-assignment-signature,
157+
-cppcoreguidelines-explicit-virtual-functions,
158+
-cppcoreguidelines-init-variables,
159+
-cppcoreguidelines-narrowing-conversions,
160+
-cppcoreguidelines-no-malloc,
161+
-cppcoreguidelines-pro-type-const-cast,
162+
-cppcoreguidelines-pro-type-member-init,
163+
-cppcoreguidelines-slicing,
164+
-hicpp-avoid-goto,
165+
-hicpp-exception-baseclass,
166+
-misc-unused-alias-decls,
167+
-misc-unused-using-decls,
168+
-modernize-avoid-bind,
169+
-modernize-avoid-c-arrays,
170+
-modernize-deprecated-headers,
171+
-modernize-deprecated-ios-base-aliases,
172+
-modernize-loop-convert,
173+
-modernize-make-shared,
174+
-modernize-make-unique,
175+
-modernize-pass-by-value,
176+
-modernize-raw-string-literal,
177+
-modernize-redundant-void-arg,
178+
-modernize-replace-auto-ptr,
179+
-modernize-replace-random-shuffle,
180+
-modernize-shrink-to-fit,
181+
-modernize-unary-static-assert,
182+
-modernize-use-bool-literals,
183+
-modernize-use-emplace,
184+
-modernize-use-equals-default,
185+
-modernize-use-equals-delete,
186+
-modernize-use-noexcept,
187+
-modernize-use-nullptr,
188+
-modernize-use-override,
189+
-modernize-use-transparent-functors,
190+
-modernize-use-uncaught-exceptions,
191+
-performance-faster-string-find,
192+
-performance-for-range-copy,
193+
-performance-implicit-conversion-in-loop,
194+
-performance-inefficient-algorithm,
195+
-performance-inefficient-string-concatenation,
196+
-performance-inefficient-vector-operation,
197+
-performance-move-const-arg,
198+
-performance-move-constructor-init,
199+
-performance-no-automatic-move,
200+
-performance-noexcept-move-constructor,
201+
-performance-trivially-destructible,
202+
-performance-type-promotion-in-math-fn,
203+
-performance-unnecessary-copy-initialization,
204+
readability-container-size-empty,
205+
'
206+
HeaderFilterRegex: '^(paddle/(?!cinn)).*$'
207+
AnalyzeTemporaryDtors: false
208+
WarningsAsErrors: '*'
209+
...

.pre-commit-config.yaml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,39 @@ repos:
104104
(?x)^(
105105
paddle/utils/flat_hash_map\.h
106106
)$
107+
- repo: local
108+
hooks:
109+
- id: clang-tidy
110+
name: clang-tidy
111+
description: Parallel clang-tidy runner.
112+
entry: python ./tools/codestyle/clang-tidy.py
113+
language: system
114+
files: \.(c|cc|cxx|cpp|h|hpp|hxx)$
115+
args:
116+
- -p=build/
117+
- -extra-arg=-Wno-unknown-warning-option
118+
- -extra-arg=-Wno-pessimizing-move
119+
- -extra-arg=-Wno-braced-scalar-init
120+
- -extra-arg=-Wno-dangling-gsl
121+
- -extra-arg=-Wno-deprecated-copy
122+
- -extra-arg=-Wno-final-dtor-non-final-class
123+
- -extra-arg=-Wno-implicit-int-float-conversion
124+
- -extra-arg=-Wno-inconsistent-missing-override
125+
- -extra-arg=-Wno-infinite-recursion
126+
- -extra-arg=-Wno-mismatched-tags
127+
- -extra-arg=-Wno-self-assign
128+
- -extra-arg=-Wno-sign-compare
129+
- -extra-arg=-Wno-sometimes-uninitialized
130+
- -extra-arg=-Wno-tautological-overlap-compare
131+
- -extra-arg=-Wno-unused-const-variable
132+
- -extra-arg=-Wno-unused-lambda-capture
133+
- -extra-arg=-Wno-unused-private-field
134+
- -extra-arg=-Wno-unused-value
135+
- -extra-arg=-Wno-unused-variable
136+
- -extra-arg=-Wno-overloaded-virtual
137+
- -extra-arg=-Wno-defaulted-function-deleted
138+
- -extra-arg=-Wno-delete-non-abstract-non-virtual-dtor
139+
- -extra-arg=-Wno-return-type-c-linkage
107140
# For CMake files
108141
- repo: local
109142
hooks:

paddle/fluid/distributed/collective/process_group_nccl.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ void ProcessGroupNCCL::BroadcastUniqueNCCLID(ncclUniqueId* nccl_id) {
490490

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

@@ -795,7 +795,7 @@ std::shared_ptr<ProcessGroup::Task> ProcessGroupNCCL::Broadcast(
795795
void CheckTensorsInDifferentDevices(
796796
const std::vector<phi::DenseTensor>& tensors, const size_t num_devices) {
797797
PADDLE_ENFORCE_EQ(
798-
tensors.size() == 0,
798+
tensors.empty(),
799799
false,
800800
phi::errors::InvalidArgument("Tensor list must be nonempty."));
801801
PADDLE_ENFORCE_LE(

paddle/fluid/distributed/fleet_executor/dist_model.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -541,11 +541,11 @@ bool DistModel::PrepareFeedAndFetch() {
541541
}
542542
}
543543

544-
if (feeds_.size() == 0) {
544+
if (feeds_.empty()) {
545545
LOG(ERROR) << "No feed ops in the inf program, please check the program.";
546546
return false;
547547
}
548-
if (fetches_.size() == 0) {
548+
if (fetches_.empty()) {
549549
LOG(ERROR) << "No fetch op in the inf program, please check the program.";
550550
return false;
551551
}

paddle/fluid/distributed/fleet_executor/fleet_executor.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ void FleetExecutor::InitMessageBus() {
261261
addr = ip_port;
262262
}
263263
}
264-
if (addr == "") {
264+
if (addr.empty()) {
265265
PADDLE_ENFORCE_EQ(
266266
rank_to_addr.size(),
267267
1,
@@ -273,9 +273,9 @@ void FleetExecutor::InitMessageBus() {
273273
platform::errors::NotFound("Address is empty but cur rank is not 0."));
274274
}
275275
VLOG(3) << "Current rank is " << cur_rank << " and the ip_port is "
276-
<< (addr == "" ? "empty" : addr) << ".";
276+
<< (addr.empty() ? "empty" : addr) << ".";
277277
VLOG(3) << "The number of ranks are "
278-
<< (rank_to_addr.size() == 0 ? 1 : rank_to_addr.size()) << ".";
278+
<< (rank_to_addr.empty() ? 1 : rank_to_addr.size()) << ".";
279279
VLOG(5) << ss.str();
280280
GlobalVal<MessageBus>::Get()->Init(cur_rank, rank_to_addr, addr);
281281
}

paddle/fluid/distributed/fleet_executor/message_bus.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ void MessageBus::Init(
3939
rank_to_addr_ = rank_to_addr;
4040
addr_ = addr;
4141

42-
if (addr_ != "") {
42+
if (!addr_.empty()) {
4343
const auto& addr = GetAddr(rank_);
4444
PADDLE_ENFORCE_EQ(addr,
4545
addr_,
@@ -55,7 +55,7 @@ void MessageBus::Init(
5555
defined(PADDLE_WITH_XPU_BKCL) || defined(PADDLE_WITH_CUSTOM_DEVICE)
5656
// NOTE: To make the brpc is compatible with collective,
5757
// need release the handler holding the ip address.
58-
if (addr_ != "") {
58+
if (!addr_.empty()) {
5959
VLOG(3) << "Message bus is releasing the fd held by gen_comm_id.";
6060
paddle::platform::SocketServer& socket_server =
6161
paddle::platform::SocketServer::GetInstance(addr_);
@@ -174,7 +174,7 @@ bool MessageBus::DispatchMsgToCarrier(
174174
}
175175

176176
void MessageBus::ListenPort() {
177-
if (addr_ == "") {
177+
if (addr_.empty()) {
178178
LOG(INFO) << "No need listen to port since training on single card.";
179179
return;
180180
}

paddle/fluid/distributed/ps/service/brpc_ps_server.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ int32_t BrpcPsService::PushSparseParam(Table *table,
428428
1);
429429
CHECK_TABLE_EXIST(table, request, response)
430430
auto &push_data = request.data();
431-
if (push_data.size() < 1) {
431+
if (push_data.empty()) {
432432
// set_response_code(response, 0, "push sparse data is empty");
433433
return 0;
434434
}
@@ -557,7 +557,7 @@ int32_t BrpcPsService::PushSparse(Table *table,
557557
"PsService->PushSparse", platform::TracerEventType::Communication, 1);
558558
CHECK_TABLE_EXIST(table, request, response)
559559
auto &push_data = request.data();
560-
if (push_data.size() < 1) {
560+
if (push_data.empty()) {
561561
// set_response_code(response, 0, "push sparse data is empty");
562562
return 0;
563563
}

paddle/fluid/distributed/ps/service/brpc_utils.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ void SerializeLodTensor(framework::Variable* var,
9595
auto* tensor = var->GetMutable<phi::DenseTensor>();
9696
var_msg->set_type(::paddle::distributed::LOD_TENSOR);
9797
const framework::LoD lod = tensor->lod();
98-
if (lod.size() > 0) {
98+
if (!lod.empty()) {
9999
var_msg->set_lod_level(lod.size());
100100
for (auto& each : lod) {
101101
VarMsg::LodData* lod_inner = var_msg->add_lod();

0 commit comments

Comments
 (0)