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 Tracking Issue #64128

Open
ApricityXX opened this issue May 8, 2024 · 28 comments
Open

引入 clang-tidy Tracking Issue #64128

ApricityXX opened this issue May 8, 2024 · 28 comments
Assignees

Comments

@ApricityXX
Copy link
Contributor

ApricityXX commented May 8, 2024

一、 项目说明

主要是针对PaddlePaddle中引入clang-tidy从而拦截clang-tidy检查项的增量,并修复PaddlePaddle现存的存量,主要规则针对Pytorch进行检测和修复。
具体说明参照:【Hackathon 6th】引入 clang-tidy

二、 主要工作

由于本次任务主要是针对clang-tidy进行存量修复和增量拦截,并且目标是对标pytorch,因此首先对pytorch项目的clang-tidy方面进行了调研,根据pytorch的开启规则进行看齐,并且针对每一条规则都应尽量开启CI的拦截。

看板信息

任务方向 任务数量 提交作品 / 任务认领 提交率 完成 完成率
Fundable Projects No.2 299 44 / 45 14.72% 38 12.71%

1.任务调研

本次任务主要是将检查项开启数量对标pytorch,并且完成存量修复后进行增量拦截,因此,本次调研主要针对pytorch所开启的检查项,如下所示:

Checks: '
bugprone-*,
-bugprone-easily-swappable-parameters,
-bugprone-forward-declaration-namespace,
-bugprone-macro-parentheses,
-bugprone-lambda-function-name,
-bugprone-reserved-identifier,
-bugprone-swapped-arguments,
-bugprone-unchecked-optional-access,
clang-diagnostic-missing-prototypes,
cppcoreguidelines-*,
-cppcoreguidelines-avoid-do-while,
-cppcoreguidelines-avoid-magic-numbers,
-cppcoreguidelines-avoid-non-const-global-variables,
-cppcoreguidelines-interfaces-global-init,
-cppcoreguidelines-macro-usage,
-cppcoreguidelines-owning-memory,
-cppcoreguidelines-pro-bounds-array-to-pointer-decay,
-cppcoreguidelines-pro-bounds-constant-array-index,
-cppcoreguidelines-pro-bounds-pointer-arithmetic,
-cppcoreguidelines-pro-type-cstyle-cast,
-cppcoreguidelines-pro-type-reinterpret-cast,
-cppcoreguidelines-pro-type-static-cast-downcast,
-cppcoreguidelines-pro-type-union-access,
-cppcoreguidelines-pro-type-vararg,
-cppcoreguidelines-special-member-functions,
-cppcoreguidelines-non-private-member-variables-in-classes,
-facebook-hte-RelativeInclude,
hicpp-exception-baseclass,
hicpp-avoid-goto,
misc-*,
-misc-const-correctness,
-misc-include-cleaner,
-misc-use-anonymous-namespace,
-misc-unused-parameters,
-misc-no-recursion,
-misc-non-private-member-variables-in-classes,
-misc-confusable-identifiers,
modernize-*,
-modernize-macro-to-enum,
-modernize-return-braced-init-list,
-modernize-use-auto,
-modernize-use-default-member-init,
-modernize-use-using,
-modernize-use-trailing-return-type,
-modernize-use-nodiscard,
performance-*,
readability-container-size-empty,
readability-delete-null-pointer,
readability-duplicate-include
readability-misplaced-array-index,
readability-redundant-function-ptr-dereference,
readability-redundant-smartptr-get,
readability-simplify-subscript-expr,
readability-string-compare,
'

将所有规则展开后,其实pytorch开启了246条规则,后续我们需要对所有规则进行最新的clang-tidy检测,从而针对每一条规则进行特定的修复,并且能够及时开启CI的检查,保证增量拦截的功能,防止无止境的修复。

2. 存量修复相关

注:下表是2024/5/13针对上述pytorch规则进行的检查(去除0错误的检查项)

编号 错误类型 错误数量 认领人/PR链接
1 bugprone-assignment-in-if-condition 5个 @walkalone20 #64521
2 bugprone-branch-clone 79个 @walkalone20 #65589
3 bugprone-copy-constructor-init 2个 @ApricityXX #64378
4 bugprone-exception-escape 5个 @walkalone20 #64586
5 bugprone-fold-init-type 1个 @ApricityXX #64438
6 bugprone-implicit-widening-of-multiplication-result 149个
7 bugprone-narrowing-conversions 472个
8 bugprone-signed-char-misuse 3个 @ApricityXX #64607
9 bugprone-use-after-move 1个 @ApricityXX #64590
10 clang-analyzer-core.CallAndMessage 3个 @ApricityXX #64622
11 clang-analyzer-core.NullDereference 21个 @walkalone20 #65534
12 clang-analyzer-cplusplus.NewDeleteLeaks 2个 @ApricityXX #64600
13 clang-analyzer-deadcode.DeadStores 1个 @ApricityXX
14 clang-analyzer-optin.cplusplus.VirtualCall 26个
15 cppcoreguidelines-avoid-c-arrays 76个 @walkalone20
16 cppcoreguidelines-explicit-virtual-functions 2个 @ApricityXX #64648
17 cppcoreguidelines-init-variables 4654个
18 cppcoreguidelines-narrowing-conversions 472个
19 cppcoreguidelines-no-malloc 20个 @walkalone20 #63752
20 cppcoreguidelines-prefer-member-initializer 299个
21 cppcoreguidelines-pro-type-const-cast 168个
22 cppcoreguidelines-pro-type-member-init 229个 @walkalone20 #64384 #64383 #64039 #64037 #64035 #63995 #63938 #64374 #64367
23 cppcoreguidelines-slicing 9个 @walkalone20 #65211
24 cppcoreguidelines-virtual-class-destructor 15个 @walkalone20 #64742
25 misc-redundant-expression 20个 @walkalone20 #64617
26 misc-unused-alias-decls 3个 @walkalone20 #64739
27 misc-unused-using-decls 6个 @walkalone20 #64740
28 modernize-avoid-c-arrays 76个 @walkalone20 #64511 #64434 #64520
29 modernize-concat-nested-namespaces 1314个 @walkalone20 #64691 #64781 #64780 #64779 #64778 #64777 #64776 #64775 #64774 #64773 #64772 #64770 #64769 #64768 #64767 #64766 #64765 #64764 #64763 #64762 #64761 #64760 #64759 #64758 #64757 #64755
30 modernize-deprecated-headers 3个 @ApricityXX #64650
31 modernize-loop-convert 32个 @walkalone20 #64608
32 modernize-pass-by-value 136个 @ApricityXX #64040 #64033 #64026 #63985
33 modernize-redundant-void-arg 13个 @walkalone20 #63795
34 modernize-use-bool-literals 6个 @walkalone20 #64580
35 modernize-use-emplace 17个 @ApricityXX #63847 #64377
36 modernize-use-equals-default 5个 @walkalone20 #64605
37 modernize-use-nullptr 41个 @walkalone20 #64483
38 modernize-use-override 2个 @ApricityXX #64648
39 modernize-use-transparent-functors 4个 @walkalone20 #64583
40 performance-faster-string-find 2个 @walkalone20 #64428
41 performance-for-range-copy 5个 @walkalone20 #64429
42 performance-inefficient-string-concatenation 5个 @walkalone20 #63779
43 performance-inefficient-vector-operation 10个 @walkalone20 #64427
44 performance-move-const-arg 9个 @ApricityXX #64829
45 performance-no-int-to-ptr 19个 @walkalone20 #64426
46 performance-trivially-destructible 1个 @ApricityXX #64593
47 performance-unnecessary-copy-initialization 255个 @ApricityXX #64041 #64030 #64029
48 performance-unnecessary-value-param 353个
49 readability-container-size-empty 26个 @walkalone20 #64585
50 readability-delete-null-pointer 10个 @walkalone20 #64584 #64604
51 readability-misplaced-array-index 19个 @walkalone20 #64604
52 readability-redundant-smartptr-get 32个 @walkalone20 #64582
53 readability-string-compare 10个 @walkalone20 #64522

3. 增量拦截相关

关于增量拦截相关任务,我们希望可以在CI中开启对检查项的增量拦截,因此我们可以按照错误为0以及错误非0的检查项进行分类,0检查项错误可以先开启CI的拦截规则,而非0错误项可以先进行存量修复,并通过流水线检测后进行CI的拦截。

注:下表是2024/5/13针对上述pytorch规则进行的检查(0错误的检查项)

编号 错误类型 错误数量 认领人/PR链接
54 bugprone-argument-comment 0
55 bugprone-assert-side-effect 0
56 bugprone-bad-signal-to-kill-thread 0
57 bugprone-bool-pointer-implicit-conversion 0
58 bugprone-dangling-handle 0
59 bugprone-dynamic-static-initializers 0
60 bugprone-forwarding-reference-overload 0
61 bugprone-inaccurate-erase 0
62 bugprone-incorrect-roundings 0
63 bugprone-infinite-loop 0
64 bugprone-integer-division 0
65 bugprone-macro-repeated-side-effects 0
66 bugprone-misplaced-operator-in-strlen-in-alloc 0
67 bugprone-misplaced-pointer-arithmetic-in-alloc 0
68 bugprone-misplaced-widening-cast 0
69 bugprone-move-forwarding-reference 0
70 bugprone-multiple-statement-macro 0
71 bugprone-no-escape 0
72 bugprone-not-null-terminated-result 0
73 bugprone-parent-virtual-call 0
74 bugprone-posix-return 0
75 bugprone-redundant-branch-condition 0
76 bugprone-shared-ptr-array-mismatch 0
77 bugprone-signal-handler 0
78 bugprone-sizeof-container 0
79 bugprone-sizeof-expression 0
80 bugprone-spuriously-wake-up-functions 0
81 bugprone-string-constructor 0
82 bugprone-string-integer-assignment 0
83 bugprone-string-literal-with-embedded-nul 0
84 bugprone-stringview-nullptr 0
85 bugprone-suspicious-enum-usage 0
86 bugprone-suspicious-include 0
87 bugprone-suspicious-memory-comparison 0
88 bugprone-suspicious-memset-usage 0
89 bugprone-suspicious-missing-comma 0
90 bugprone-suspicious-semicolon 0
91 bugprone-suspicious-string-compare 0
92 bugprone-terminating-continue 0
93 bugprone-throw-keyword-missing 0
94 bugprone-too-small-loop-variable 0
95 bugprone-undefined-memory-manipulation 0
96 bugprone-undelegated-constructor 0
97 bugprone-unhandled-exception-at-new 0
98 bugprone-unhandled-self-assignment 0
99 bugprone-unused-raii 0
100 bugprone-unused-return-value 0
101 bugprone-virtual-near-miss 0
102 clang-analyzer-apiModeling.Errno 0
103 clang-analyzer-apiModeling.StdCLibraryFunctions 0
104 clang-analyzer-apiModeling.TrustNonnull 0
105 clang-analyzer-apiModeling.TrustReturnsNonnull 0
106 clang-analyzer-apiModeling.google.GTest 0
107 clang-analyzer-apiModeling.llvm.CastValue 0
108 clang-analyzer-apiModeling.llvm.ReturnValue 0
109 clang-analyzer-core.CallAndMessageModeling 0
110 clang-analyzer-core.DivideZero 0
111 clang-analyzer-core.DynamicTypePropagation 0
112 clang-analyzer-core.NonNullParamChecker 0
113 clang-analyzer-core.NonnilStringConstants 0
114 clang-analyzer-core.StackAddrEscapeBase 0
115 clang-analyzer-core.StackAddressEscape 0
116 clang-analyzer-core.UndefinedBinaryOperatorResult 0
117 clang-analyzer-core.VLASize 0
118 clang-analyzer-core.builtin.BuiltinFunctions 0
119 clang-analyzer-core.builtin.NoReturnFunctions 0
120 clang-analyzer-core.uninitialized.ArraySubscript 0
121 clang-analyzer-core.uninitialized.Assign 0
122 clang-analyzer-core.uninitialized.Branch 0
123 clang-analyzer-core.uninitialized.CapturedBlockVariable 0
124 clang-analyzer-core.uninitialized.UndefReturn 0
125 clang-analyzer-cplusplus.InnerPointer 0
126 clang-analyzer-cplusplus.Move 0
127 clang-analyzer-cplusplus.NewDelete 0
128 clang-analyzer-cplusplus.PlacementNew 0
129 clang-analyzer-cplusplus.PureVirtualCall 0
130 clang-analyzer-cplusplus.SelfAssignment 0
131 clang-analyzer-cplusplus.SmartPtrModeling 0
132 clang-analyzer-cplusplus.StringChecker 0
133 clang-analyzer-cplusplus.VirtualCallModeling 0
134 clang-analyzer-fuchsia.HandleChecker 0
135 clang-analyzer-nullability.NullPassedToNonnull 0
136 clang-analyzer-nullability.NullReturnedFromNonnull 0
137 clang-analyzer-nullability.NullabilityBase 0
138 clang-analyzer-nullability.NullableDereferenced 0
139 clang-analyzer-nullability.NullablePassedToNonnull 0
140 clang-analyzer-nullability.NullableReturnedFromNonnull 0
141 clang-analyzer-optin.cplusplus.UninitializedObject 0
142 clang-analyzer-optin.mpi.MPI-Checker 0
143 clang-analyzer-optin.osx.OSObjectCStyleCast 0
144 clang-analyzer-optin.osx.cocoa.localizability.EmptyLocalizationContextChecker 0
145 clang-analyzer-optin.osx.cocoa.localizability.NonLocalizedStringChecker 0
146 clang-analyzer-optin.performance.GCDAntipattern 0
147 clang-analyzer-optin.performance.Padding 0
148 clang-analyzer-optin.portability.UnixAPI 0
149 clang-analyzer-osx.API 0
150 clang-analyzer-osx.MIG 0
151 clang-analyzer-osx.NSOrCFErrorDerefChecker 0
152 clang-analyzer-osx.NumberObjectConversion 0
153 clang-analyzer-osx.OSObjectRetainCount 0
154 clang-analyzer-osx.ObjCProperty 0
155 clang-analyzer-osx.SecKeychainAPI 0
156 clang-analyzer-osx.cocoa.AtSync 0
157 clang-analyzer-osx.cocoa.AutoreleaseWrite 0
158 clang-analyzer-osx.cocoa.ClassRelease 0
159 clang-analyzer-osx.cocoa.Dealloc 0
160 clang-analyzer-osx.cocoa.IncompatibleMethodTypes 0
161 clang-analyzer-osx.cocoa.Loops 0
162 clang-analyzer-osx.cocoa.MissingSuperCall 0
163 clang-analyzer-osx.cocoa.NSAutoreleasePool 0
164 clang-analyzer-osx.cocoa.NSError 0
165 clang-analyzer-osx.cocoa.NilArg 0
166 clang-analyzer-osx.cocoa.NonNilReturnValue 0
167 clang-analyzer-osx.cocoa.ObjCGenerics 0
168 clang-analyzer-osx.cocoa.RetainCount 0
169 clang-analyzer-osx.cocoa.RetainCountBase 0
170 clang-analyzer-osx.cocoa.RunLoopAutoreleaseLeak 0
171 clang-analyzer-osx.cocoa.SelfInit 0
172 clang-analyzer-osx.cocoa.SuperDealloc 0
173 clang-analyzer-osx.cocoa.UnusedIvars 0
174 clang-analyzer-osx.cocoa.VariadicMethodTypes 0
175 clang-analyzer-osx.coreFoundation.CFError 0
176 clang-analyzer-osx.coreFoundation.CFNumber 0
177 clang-analyzer-osx.coreFoundation.CFRetainRelease 0
178 clang-analyzer-osx.coreFoundation.containers.OutOfBounds 0
179 clang-analyzer-osx.coreFoundation.containers.PointerSizedValues 0
180 clang-analyzer-security.FloatLoopCounter 0
181 clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling 0
182 clang-analyzer-security.insecureAPI.SecuritySyntaxChecker 0
183 clang-analyzer-security.insecureAPI.UncheckedReturn 0
184 clang-analyzer-security.insecureAPI.bcmp 0
185 clang-analyzer-security.insecureAPI.bcopy 0
186 clang-analyzer-security.insecureAPI.bzero 0
187 clang-analyzer-security.insecureAPI.decodeValueOfObjCType 0
188 clang-analyzer-security.insecureAPI.getpw 0
189 clang-analyzer-security.insecureAPI.gets 0
190 clang-analyzer-security.insecureAPI.mkstemp 0
191 clang-analyzer-security.insecureAPI.mktemp 0
192 clang-analyzer-security.insecureAPI.rand 0
193 clang-analyzer-security.insecureAPI.strcpy 0
194 clang-analyzer-security.insecureAPI.vfork 0
195 clang-analyzer-unix.API 0
196 clang-analyzer-unix.DynamicMemoryModeling 0
197 clang-analyzer-unix.Malloc 0
198 clang-analyzer-unix.MallocSizeof 0
199 clang-analyzer-unix.MismatchedDeallocator 0
200 clang-analyzer-unix.Vfork 0
201 clang-analyzer-unix.cstring.BadSizeArg 0
202 clang-analyzer-unix.cstring.CStringModeling 0
203 clang-analyzer-unix.cstring.NullArg 0
204 clang-analyzer-valist.CopyToSelf 0
205 clang-analyzer-valist.Uninitialized 0
206 clang-analyzer-valist.Unterminated 0
207 clang-analyzer-valist.ValistBase 0
208 clang-analyzer-webkit.NoUncountedMemberChecker 0
209 clang-analyzer-webkit.RefCntblBaseVirtualDtor 0
210 clang-analyzer-webkit.UncountedLambdaCapturesChecker 0
211 cppcoreguidelines-avoid-goto 0
212 cppcoreguidelines-c-copy-assignment-signature 0
213 hicpp-avoid-goto 0
214 hicpp-exception-baseclass 0
215 misc-definitions-in-headers 0
216 misc-misleading-bidirectional 0
217 misc-misleading-identifier 0
218 misc-misplaced-const 0
219 misc-new-delete-overloads 0
220 misc-non-copyable-objects 0
221 misc-static-assert 0
222 misc-throw-by-value-catch-by-reference 0
223 misc-unconventional-assign-operator 0
224 misc-uniqueptr-reset-release 0
225 modernize-avoid-bind 0
226 modernize-deprecated-ios-base-aliases 0
227 modernize-make-shared 0
228 modernize-make-unique 0
229 modernize-raw-string-literal 0
230 modernize-replace-auto-ptr 0
231 modernize-replace-disallow-copy-and-assign-macro 0
232 modernize-replace-random-shuffle 0
233 modernize-shrink-to-fit 0
234 modernize-unary-static-assert 0
235 modernize-use-equals-delete 0
236 modernize-use-noexcept 0
237 modernize-use-uncaught-exceptions 0
238 performance-implicit-conversion-in-loop 0
239 performance-inefficient-algorithm 0
240 performance-move-constructor-init 0
241 performance-no-automatic-move 0
242 performance-noexcept-move-constructor 0
243 performance-type-promotion-in-math-fn 0
244 readability-duplicate-include 0
245 readability-redundant-function-ptr-dereference 0
246 readability-simplify-subscript-expr 0

下表是需要进行存量修复后引入CI拦截的检查项(非0错误)

编号 错误类型 错误数量 认领人/PR链接
247 bugprone-assignment-in-if-condition 5
248 bugprone-branch-clone 79
249 bugprone-copy-constructor-init 2
250 bugprone-exception-escape 5
251 bugprone-fold-init-type 1
252 bugprone-implicit-widening-of-multiplication-result 149
253 bugprone-narrowing-conversions 472
254 bugprone-signed-char-misuse 3
255 bugprone-use-after-move 1
256 clang-analyzer-core.CallAndMessage 3
257 clang-analyzer-core.NullDereference 21
258 clang-analyzer-cplusplus.NewDeleteLeaks 2
259 clang-analyzer-deadcode.DeadStores 1
260 clang-analyzer-optin.cplusplus.VirtualCall 26
261 cppcoreguidelines-avoid-c-arrays 76
262 cppcoreguidelines-explicit-virtual-functions 2
263 cppcoreguidelines-init-variables 4654
264 cppcoreguidelines-narrowing-conversions 472
265 cppcoreguidelines-no-malloc 20
266 cppcoreguidelines-prefer-member-initializer 299
267 cppcoreguidelines-pro-type-const-cast 168
268 cppcoreguidelines-pro-type-member-init 229
269 cppcoreguidelines-slicing 9
270 cppcoreguidelines-virtual-class-destructor 15
271 misc-redundant-expression 20
272 misc-unused-alias-decls 3
273 misc-unused-using-decls 6
274 modernize-avoid-c-arrays 76
275 modernize-concat-nested-namespaces 1314
276 modernize-deprecated-headers 3
277 modernize-loop-convert 32
278 modernize-pass-by-value 136
279 modernize-redundant-void-arg 13
280 modernize-use-bool-literals 6
281 modernize-use-emplace 17
282 modernize-use-equals-default 5
283 modernize-use-nullptr 41
284 modernize-use-override 2
285 modernize-use-transparent-functors 4
286 performance-faster-string-find 2
287 performance-for-range-copy 5
288 performance-inefficient-string-concatenation 5
289 performance-inefficient-vector-operation 10
290 performance-move-const-arg 9
291 performance-no-int-to-ptr 19
292 performance-trivially-destructible 1
293 performance-unnecessary-copy-initialization 255
294 performance-unnecessary-value-param 353
295 readability-container-size-empty 26
296 readability-delete-null-pointer 10
297 readability-misplaced-array-index 19
298 readability-redundant-smartptr-get 32
299 readability-string-compare 10

4.认领方式

请大家以 comment 的形式认领任务,如:
【报名】:1、3、12-13
多个任务之间需要使用中文顿号分隔,报名多个连续任务可用横线表示,如 2-5
PR 提交格式:在 PR 的标题中以 【Hackathon 6th Fundable Projects 2 No.xxx】 开头,注明任务编号

统计信息

排名不分先后 @walkalone20 (26) @ApricityXX (12)

@ApricityXX
Copy link
Contributor Author

【报名】:35

@walkalone20
Copy link
Contributor

【报名】:15、28、37、40

@ApricityXX
Copy link
Contributor Author

【报名】:3、5、8、9、10、12、13、16

@walkalone20
Copy link
Contributor

【报名】:43、45

This was referenced May 30, 2024
@walkalone20
Copy link
Contributor

【报名】:11

@walkalone20
Copy link
Contributor

【报名】:2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants