blob: 5ee66c0791496b49e2c8b39f08febba14a4d1735 [file] [log] [blame]
Chih-Hung Hsieh949205a2020-01-10 10:33:40 -08001# python3
Chih-Hung Hsieh888d1432019-12-09 19:32:03 -08002# Copyright (C) 2019 The Android Open Source Project
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16"""Warning patterns for clang-tidy."""
17
Chih-Hung Hsieh98b285d2021-04-28 14:49:32 -070018# No need of doc strings for trivial small functions.
19# pylint:disable=missing-function-docstring
20
Chih-Hung Hsieh949205a2020-01-10 10:33:40 -080021# pylint:disable=relative-beyond-top-level
Chih-Hung Hsieh3cce2bc2020-02-27 15:39:18 -080022from .cpp_warn_patterns import compile_patterns
Chih-Hung Hsieh949205a2020-01-10 10:33:40 -080023from .severity import Severity
Chih-Hung Hsieh888d1432019-12-09 19:32:03 -080024
25
Chih-Hung Hsieh3bb6c942021-09-23 13:48:34 -070026def tidy_warn(description, patterns):
Chih-Hung Hsieh888d1432019-12-09 19:32:03 -080027 return {
28 'category': 'C/C++',
29 'severity': Severity.TIDY,
30 'description': 'clang-tidy ' + description,
Chih-Hung Hsieh3bb6c942021-09-23 13:48:34 -070031 'patterns': patterns,
Chih-Hung Hsieh888d1432019-12-09 19:32:03 -080032 }
33
34
Chih-Hung Hsieh3bb6c942021-09-23 13:48:34 -070035def tidy_warn_pattern(description, pattern):
36 return tidy_warn(description, [r'.*: .+\[' + pattern + r'\]$'])
37
38
Chih-Hung Hsieh888d1432019-12-09 19:32:03 -080039def simple_tidy_warn_pattern(description):
40 return tidy_warn_pattern(description, description)
41
42
43def group_tidy_warn_pattern(description):
44 return tidy_warn_pattern(description, description + r'-.+')
45
46
Chih-Hung Hsieh949205a2020-01-10 10:33:40 -080047def analyzer_high(description, patterns):
Chih-Hung Hsieh888d1432019-12-09 19:32:03 -080048 return {
49 'category': 'C/C++',
50 'severity': Severity.HIGH,
51 'description': description,
Chih-Hung Hsieh949205a2020-01-10 10:33:40 -080052 'patterns': patterns
Chih-Hung Hsieh888d1432019-12-09 19:32:03 -080053 }
54
55
56def analyzer_high_check(check):
57 return analyzer_high(check, [r'.*: .+\[' + check + r'\]$'])
58
59
60def analyzer_group_high(check):
61 return analyzer_high(check, [r'.*: .+\[' + check + r'.+\]$'])
62
63
Chih-Hung Hsieh949205a2020-01-10 10:33:40 -080064def analyzer_warn(description, patterns):
Chih-Hung Hsieh888d1432019-12-09 19:32:03 -080065 return {
66 'category': 'C/C++',
67 'severity': Severity.ANALYZER,
68 'description': description,
Chih-Hung Hsieh949205a2020-01-10 10:33:40 -080069 'patterns': patterns
Chih-Hung Hsieh888d1432019-12-09 19:32:03 -080070 }
71
72
73def analyzer_warn_check(check):
74 return analyzer_warn(check, [r'.*: .+\[' + check + r'\]$'])
75
76
77def analyzer_group_check(check):
78 return analyzer_warn(check, [r'.*: .+\[' + check + r'.+\]$'])
79
80
Chih-Hung Hsieh949205a2020-01-10 10:33:40 -080081warn_patterns = [
Chih-Hung Hsieh98b285d2021-04-28 14:49:32 -070082 # pylint does not recognize g-inconsistent-quotes
83 # pylint:disable=line-too-long,bad-option-value,g-inconsistent-quotes
Chih-Hung Hsiehf36e01d2021-10-08 13:14:41 -070084 group_tidy_warn_pattern('altera'),
Chih-Hung Hsieh888d1432019-12-09 19:32:03 -080085 group_tidy_warn_pattern('android'),
86 simple_tidy_warn_pattern('abseil-string-find-startswith'),
87 simple_tidy_warn_pattern('bugprone-argument-comment'),
Chih-Hung Hsieh445ad812020-02-26 14:34:21 -080088 simple_tidy_warn_pattern('bugprone-branch-clone'),
Chih-Hung Hsieh888d1432019-12-09 19:32:03 -080089 simple_tidy_warn_pattern('bugprone-copy-constructor-init'),
90 simple_tidy_warn_pattern('bugprone-fold-init-type'),
91 simple_tidy_warn_pattern('bugprone-forward-declaration-namespace'),
92 simple_tidy_warn_pattern('bugprone-forwarding-reference-overload'),
93 simple_tidy_warn_pattern('bugprone-inaccurate-erase'),
94 simple_tidy_warn_pattern('bugprone-incorrect-roundings'),
95 simple_tidy_warn_pattern('bugprone-integer-division'),
96 simple_tidy_warn_pattern('bugprone-lambda-function-name'),
97 simple_tidy_warn_pattern('bugprone-macro-parentheses'),
98 simple_tidy_warn_pattern('bugprone-misplaced-widening-cast'),
99 simple_tidy_warn_pattern('bugprone-move-forwarding-reference'),
Chih-Hung Hsieh445ad812020-02-26 14:34:21 -0800100 simple_tidy_warn_pattern('bugprone-parent-virtual-call'),
101 simple_tidy_warn_pattern('bugprone-posix-return'),
102 simple_tidy_warn_pattern('bugprone-sizeof-container'),
Chih-Hung Hsieh888d1432019-12-09 19:32:03 -0800103 simple_tidy_warn_pattern('bugprone-sizeof-expression'),
104 simple_tidy_warn_pattern('bugprone-string-constructor'),
105 simple_tidy_warn_pattern('bugprone-string-integer-assignment'),
106 simple_tidy_warn_pattern('bugprone-suspicious-enum-usage'),
107 simple_tidy_warn_pattern('bugprone-suspicious-missing-comma'),
108 simple_tidy_warn_pattern('bugprone-suspicious-string-compare'),
109 simple_tidy_warn_pattern('bugprone-suspicious-semicolon'),
Chih-Hung Hsieh445ad812020-02-26 14:34:21 -0800110 simple_tidy_warn_pattern('bugprone-terminating-continue'),
111 simple_tidy_warn_pattern('bugprone-too-small-loop-variable'),
Chih-Hung Hsieh888d1432019-12-09 19:32:03 -0800112 simple_tidy_warn_pattern('bugprone-undefined-memory-manipulation'),
Chih-Hung Hsieh445ad812020-02-26 14:34:21 -0800113 simple_tidy_warn_pattern('bugprone-unhandled-self-assignment'),
Chih-Hung Hsieh888d1432019-12-09 19:32:03 -0800114 simple_tidy_warn_pattern('bugprone-unused-raii'),
Chih-Hung Hsieh445ad812020-02-26 14:34:21 -0800115 simple_tidy_warn_pattern('bugprone-unused-return-value'),
Chih-Hung Hsieh888d1432019-12-09 19:32:03 -0800116 simple_tidy_warn_pattern('bugprone-use-after-move'),
117 group_tidy_warn_pattern('bugprone'),
Chih-Hung Hsieh445ad812020-02-26 14:34:21 -0800118 simple_tidy_warn_pattern('cert-dcl16-c'),
119 simple_tidy_warn_pattern('cert-dcl21-cpp'),
120 simple_tidy_warn_pattern('cert-dcl50-cpp'),
121 simple_tidy_warn_pattern('cert-dcl54-cpp'),
122 simple_tidy_warn_pattern('cert-dcl59-cpp'),
123 simple_tidy_warn_pattern('cert-env33-c'),
124 simple_tidy_warn_pattern('cert-err34-c'),
125 simple_tidy_warn_pattern('cert-err52-cpp'),
126 simple_tidy_warn_pattern('cert-msc30-c'),
127 simple_tidy_warn_pattern('cert-msc50-cpp'),
128 simple_tidy_warn_pattern('cert-oop54-cpp'),
Chih-Hung Hsieh888d1432019-12-09 19:32:03 -0800129 group_tidy_warn_pattern('cert'),
130 group_tidy_warn_pattern('clang-diagnostic'),
Chih-Hung Hsiehf36e01d2021-10-08 13:14:41 -0700131 group_tidy_warn_pattern('concurrency'),
Chih-Hung Hsieh888d1432019-12-09 19:32:03 -0800132 group_tidy_warn_pattern('cppcoreguidelines'),
Chih-Hung Hsiehf36e01d2021-10-08 13:14:41 -0700133 group_tidy_warn_pattern('fuchsia'),
Chih-Hung Hsieh888d1432019-12-09 19:32:03 -0800134 simple_tidy_warn_pattern('google-default-arguments'),
135 simple_tidy_warn_pattern('google-runtime-int'),
136 simple_tidy_warn_pattern('google-runtime-operator'),
137 simple_tidy_warn_pattern('google-runtime-references'),
138 group_tidy_warn_pattern('google-build'),
139 group_tidy_warn_pattern('google-explicit'),
140 group_tidy_warn_pattern('google-redability'),
141 group_tidy_warn_pattern('google-global'),
142 group_tidy_warn_pattern('google-redability'),
143 group_tidy_warn_pattern('google-redability'),
144 group_tidy_warn_pattern('google'),
145 simple_tidy_warn_pattern('hicpp-explicit-conversions'),
146 simple_tidy_warn_pattern('hicpp-function-size'),
147 simple_tidy_warn_pattern('hicpp-invalid-access-moved'),
148 simple_tidy_warn_pattern('hicpp-member-init'),
149 simple_tidy_warn_pattern('hicpp-delete-operators'),
150 simple_tidy_warn_pattern('hicpp-special-member-functions'),
151 simple_tidy_warn_pattern('hicpp-use-equals-default'),
152 simple_tidy_warn_pattern('hicpp-use-equals-delete'),
153 simple_tidy_warn_pattern('hicpp-no-assembler'),
154 simple_tidy_warn_pattern('hicpp-noexcept-move'),
155 simple_tidy_warn_pattern('hicpp-use-override'),
156 group_tidy_warn_pattern('hicpp'),
Chih-Hung Hsiehf36e01d2021-10-08 13:14:41 -0700157 group_tidy_warn_pattern('llvm'),
158 group_tidy_warn_pattern('llvmlibc'),
Chih-Hung Hsieh888d1432019-12-09 19:32:03 -0800159 group_tidy_warn_pattern('misc'),
Chih-Hung Hsiehf36e01d2021-10-08 13:14:41 -0700160 group_tidy_warn_pattern('modernize'),
Chih-Hung Hsieh888d1432019-12-09 19:32:03 -0800161 simple_tidy_warn_pattern('performance-faster-string-find'),
162 simple_tidy_warn_pattern('performance-for-range-copy'),
163 simple_tidy_warn_pattern('performance-implicit-cast-in-loop'),
164 simple_tidy_warn_pattern('performance-inefficient-string-concatenation'),
165 simple_tidy_warn_pattern('performance-type-promotion-in-math-fn'),
166 simple_tidy_warn_pattern('performance-unnecessary-copy-initialization'),
167 simple_tidy_warn_pattern('performance-unnecessary-value-param'),
168 simple_tidy_warn_pattern('portability-simd-intrinsics'),
169 group_tidy_warn_pattern('performance'),
170 group_tidy_warn_pattern('readability'),
Chih-Hung Hsieh949205a2020-01-10 10:33:40 -0800171 simple_tidy_warn_pattern('abseil-string-find-startwith'),
172 simple_tidy_warn_pattern('abseil-faster-strsplit-delimiter'),
173 simple_tidy_warn_pattern('abseil-no-namespace'),
174 simple_tidy_warn_pattern('abseil-no-internal-dependencies'),
175 group_tidy_warn_pattern('abseil'),
176 simple_tidy_warn_pattern('portability-simd-intrinsics'),
177 group_tidy_warn_pattern('portability'),
Chih-Hung Hsieh888d1432019-12-09 19:32:03 -0800178
Chih-Hung Hsieh3bb6c942021-09-23 13:48:34 -0700179 tidy_warn('TIMEOUT', [r".*: warning: clang-tidy aborted "]),
Chih-Hung Hsiehf36e01d2021-10-08 13:14:41 -0700180 tidy_warn('Long Runs', [r".*: warning: clang-tidy used "]),
Chih-Hung Hsieh3bb6c942021-09-23 13:48:34 -0700181
Chih-Hung Hsieh888d1432019-12-09 19:32:03 -0800182 # warnings from clang-tidy's clang-analyzer checks
183 analyzer_high('clang-analyzer-core, null pointer',
184 [r".*: warning: .+ pointer is null .*\[clang-analyzer-core"]),
185 analyzer_high('clang-analyzer-core, uninitialized value',
186 [r".*: warning: .+ uninitialized (value|data) .*\[clang-analyzer-core"]),
187 analyzer_warn('clang-analyzer-optin.performance.Padding',
188 [r".*: warning: Excessive padding in '.*'"]),
189 # analyzer_warn('clang-analyzer Unreachable code',
190 # [r".*: warning: This statement is never executed.*UnreachableCode"]),
191 analyzer_warn('clang-analyzer Size of malloc may overflow',
192 [r".*: warning: .* size of .* may overflow .*MallocOverflow"]),
193 analyzer_warn('clang-analyzer sozeof() on a pointer type',
194 [r".*: warning: .*calls sizeof.* on a pointer type.*SizeofPtr"]),
195 analyzer_warn('clang-analyzer Pointer arithmetic on non-array variables',
196 [r".*: warning: Pointer arithmetic on non-array variables .*PointerArithm"]),
197 analyzer_warn('clang-analyzer Subtraction of pointers of different memory chunks',
198 [r".*: warning: Subtraction of two pointers .*PointerSub"]),
199 analyzer_warn('clang-analyzer Access out-of-bound array element',
200 [r".*: warning: Access out-of-bound array element .*ArrayBound"]),
201 analyzer_warn('clang-analyzer Out of bound memory access',
202 [r".*: warning: Out of bound memory access .*ArrayBoundV2"]),
203 analyzer_warn('clang-analyzer Possible lock order reversal',
204 [r".*: warning: .* Possible lock order reversal.*PthreadLock"]),
205 analyzer_warn('clang-analyzer call path problems',
206 [r".*: warning: Call Path : .+"]),
207 analyzer_warn_check('clang-analyzer-core.CallAndMessage'),
208 analyzer_high_check('clang-analyzer-core.NonNullParamChecker'),
209 analyzer_high_check('clang-analyzer-core.NullDereference'),
210 analyzer_warn_check('clang-analyzer-core.UndefinedBinaryOperatorResult'),
211 analyzer_warn_check('clang-analyzer-core.DivideZero'),
212 analyzer_warn_check('clang-analyzer-core.VLASize'),
213 analyzer_warn_check('clang-analyzer-core.uninitialized.ArraySubscript'),
214 analyzer_warn_check('clang-analyzer-core.uninitialized.Assign'),
215 analyzer_warn_check('clang-analyzer-core.uninitialized.UndefReturn'),
216 analyzer_warn_check('clang-analyzer-cplusplus.Move'),
217 analyzer_warn_check('clang-analyzer-deadcode.DeadStores'),
218 analyzer_warn_check('clang-analyzer-optin.cplusplus.UninitializedObject'),
219 analyzer_warn_check('clang-analyzer-optin.cplusplus.VirtualCall'),
220 analyzer_warn_check('clang-analyzer-portability.UnixAPI'),
221 analyzer_warn_check('clang-analyzer-unix.cstring.NullArg'),
222 analyzer_high_check('clang-analyzer-unix.MallocSizeof'),
223 analyzer_warn_check('clang-analyzer-valist.Uninitialized'),
224 analyzer_warn_check('clang-analyzer-valist.Unterminated'),
225 analyzer_group_check('clang-analyzer-core.uninitialized'),
226 analyzer_group_check('clang-analyzer-deadcode'),
Chih-Hung Hsieh1a1f90e2023-01-09 14:19:11 -0800227 analyzer_warn_check('clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling'),
Chih-Hung Hsieh02f0df82022-01-20 16:13:12 -0800228 analyzer_warn_check('clang-analyzer-security.insecureAPI.bcmp'),
229 analyzer_warn_check('clang-analyzer-security.insecureAPI.bcopy'),
230 analyzer_warn_check('clang-analyzer-security.insecureAPI.bzero'),
Chih-Hung Hsieh888d1432019-12-09 19:32:03 -0800231 analyzer_warn_check('clang-analyzer-security.insecureAPI.strcpy'),
232 analyzer_group_high('clang-analyzer-security.insecureAPI'),
233 analyzer_group_high('clang-analyzer-security'),
234 analyzer_high_check('clang-analyzer-unix.Malloc'),
235 analyzer_high_check('clang-analyzer-cplusplus.NewDeleteLeaks'),
236 analyzer_high_check('clang-analyzer-cplusplus.NewDelete'),
237 analyzer_group_check('clang-analyzer-unix'),
Chih-Hung Hsieh949205a2020-01-10 10:33:40 -0800238 analyzer_group_check('clang-analyzer'), # catch all
Chih-Hung Hsieh888d1432019-12-09 19:32:03 -0800239]
Chih-Hung Hsieh949205a2020-01-10 10:33:40 -0800240
241
242compile_patterns(warn_patterns)