Chih-Hung Hsieh | 949205a | 2020-01-10 10:33:40 -0800 | [diff] [blame] | 1 | # python3 |
Chih-Hung Hsieh | 888d143 | 2019-12-09 19:32:03 -0800 | [diff] [blame] | 2 | # 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 Hsieh | 98b285d | 2021-04-28 14:49:32 -0700 | [diff] [blame] | 18 | # No need of doc strings for trivial small functions. |
| 19 | # pylint:disable=missing-function-docstring |
| 20 | |
Chih-Hung Hsieh | 949205a | 2020-01-10 10:33:40 -0800 | [diff] [blame] | 21 | # pylint:disable=relative-beyond-top-level |
Chih-Hung Hsieh | 3cce2bc | 2020-02-27 15:39:18 -0800 | [diff] [blame] | 22 | from .cpp_warn_patterns import compile_patterns |
Chih-Hung Hsieh | 949205a | 2020-01-10 10:33:40 -0800 | [diff] [blame] | 23 | from .severity import Severity |
Chih-Hung Hsieh | 888d143 | 2019-12-09 19:32:03 -0800 | [diff] [blame] | 24 | |
| 25 | |
Chih-Hung Hsieh | 3bb6c94 | 2021-09-23 13:48:34 -0700 | [diff] [blame] | 26 | def tidy_warn(description, patterns): |
Chih-Hung Hsieh | 888d143 | 2019-12-09 19:32:03 -0800 | [diff] [blame] | 27 | return { |
| 28 | 'category': 'C/C++', |
| 29 | 'severity': Severity.TIDY, |
| 30 | 'description': 'clang-tidy ' + description, |
Chih-Hung Hsieh | 3bb6c94 | 2021-09-23 13:48:34 -0700 | [diff] [blame] | 31 | 'patterns': patterns, |
Chih-Hung Hsieh | 888d143 | 2019-12-09 19:32:03 -0800 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | |
Chih-Hung Hsieh | 3bb6c94 | 2021-09-23 13:48:34 -0700 | [diff] [blame] | 35 | def tidy_warn_pattern(description, pattern): |
| 36 | return tidy_warn(description, [r'.*: .+\[' + pattern + r'\]$']) |
| 37 | |
| 38 | |
Chih-Hung Hsieh | 888d143 | 2019-12-09 19:32:03 -0800 | [diff] [blame] | 39 | def simple_tidy_warn_pattern(description): |
| 40 | return tidy_warn_pattern(description, description) |
| 41 | |
| 42 | |
| 43 | def group_tidy_warn_pattern(description): |
| 44 | return tidy_warn_pattern(description, description + r'-.+') |
| 45 | |
| 46 | |
Chih-Hung Hsieh | 949205a | 2020-01-10 10:33:40 -0800 | [diff] [blame] | 47 | def analyzer_high(description, patterns): |
Chih-Hung Hsieh | 888d143 | 2019-12-09 19:32:03 -0800 | [diff] [blame] | 48 | return { |
| 49 | 'category': 'C/C++', |
| 50 | 'severity': Severity.HIGH, |
| 51 | 'description': description, |
Chih-Hung Hsieh | 949205a | 2020-01-10 10:33:40 -0800 | [diff] [blame] | 52 | 'patterns': patterns |
Chih-Hung Hsieh | 888d143 | 2019-12-09 19:32:03 -0800 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | |
| 56 | def analyzer_high_check(check): |
| 57 | return analyzer_high(check, [r'.*: .+\[' + check + r'\]$']) |
| 58 | |
| 59 | |
| 60 | def analyzer_group_high(check): |
| 61 | return analyzer_high(check, [r'.*: .+\[' + check + r'.+\]$']) |
| 62 | |
| 63 | |
Chih-Hung Hsieh | 949205a | 2020-01-10 10:33:40 -0800 | [diff] [blame] | 64 | def analyzer_warn(description, patterns): |
Chih-Hung Hsieh | 888d143 | 2019-12-09 19:32:03 -0800 | [diff] [blame] | 65 | return { |
| 66 | 'category': 'C/C++', |
| 67 | 'severity': Severity.ANALYZER, |
| 68 | 'description': description, |
Chih-Hung Hsieh | 949205a | 2020-01-10 10:33:40 -0800 | [diff] [blame] | 69 | 'patterns': patterns |
Chih-Hung Hsieh | 888d143 | 2019-12-09 19:32:03 -0800 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | |
| 73 | def analyzer_warn_check(check): |
| 74 | return analyzer_warn(check, [r'.*: .+\[' + check + r'\]$']) |
| 75 | |
| 76 | |
| 77 | def analyzer_group_check(check): |
| 78 | return analyzer_warn(check, [r'.*: .+\[' + check + r'.+\]$']) |
| 79 | |
| 80 | |
Chih-Hung Hsieh | 949205a | 2020-01-10 10:33:40 -0800 | [diff] [blame] | 81 | warn_patterns = [ |
Chih-Hung Hsieh | 98b285d | 2021-04-28 14:49:32 -0700 | [diff] [blame] | 82 | # pylint does not recognize g-inconsistent-quotes |
| 83 | # pylint:disable=line-too-long,bad-option-value,g-inconsistent-quotes |
Chih-Hung Hsieh | f36e01d | 2021-10-08 13:14:41 -0700 | [diff] [blame] | 84 | group_tidy_warn_pattern('altera'), |
Chih-Hung Hsieh | 888d143 | 2019-12-09 19:32:03 -0800 | [diff] [blame] | 85 | group_tidy_warn_pattern('android'), |
| 86 | simple_tidy_warn_pattern('abseil-string-find-startswith'), |
| 87 | simple_tidy_warn_pattern('bugprone-argument-comment'), |
Chih-Hung Hsieh | 445ad81 | 2020-02-26 14:34:21 -0800 | [diff] [blame] | 88 | simple_tidy_warn_pattern('bugprone-branch-clone'), |
Chih-Hung Hsieh | 888d143 | 2019-12-09 19:32:03 -0800 | [diff] [blame] | 89 | 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 Hsieh | 445ad81 | 2020-02-26 14:34:21 -0800 | [diff] [blame] | 100 | 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 Hsieh | 888d143 | 2019-12-09 19:32:03 -0800 | [diff] [blame] | 103 | 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 Hsieh | 445ad81 | 2020-02-26 14:34:21 -0800 | [diff] [blame] | 110 | simple_tidy_warn_pattern('bugprone-terminating-continue'), |
| 111 | simple_tidy_warn_pattern('bugprone-too-small-loop-variable'), |
Chih-Hung Hsieh | 888d143 | 2019-12-09 19:32:03 -0800 | [diff] [blame] | 112 | simple_tidy_warn_pattern('bugprone-undefined-memory-manipulation'), |
Chih-Hung Hsieh | 445ad81 | 2020-02-26 14:34:21 -0800 | [diff] [blame] | 113 | simple_tidy_warn_pattern('bugprone-unhandled-self-assignment'), |
Chih-Hung Hsieh | 888d143 | 2019-12-09 19:32:03 -0800 | [diff] [blame] | 114 | simple_tidy_warn_pattern('bugprone-unused-raii'), |
Chih-Hung Hsieh | 445ad81 | 2020-02-26 14:34:21 -0800 | [diff] [blame] | 115 | simple_tidy_warn_pattern('bugprone-unused-return-value'), |
Chih-Hung Hsieh | 888d143 | 2019-12-09 19:32:03 -0800 | [diff] [blame] | 116 | simple_tidy_warn_pattern('bugprone-use-after-move'), |
| 117 | group_tidy_warn_pattern('bugprone'), |
Chih-Hung Hsieh | 445ad81 | 2020-02-26 14:34:21 -0800 | [diff] [blame] | 118 | 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 Hsieh | 888d143 | 2019-12-09 19:32:03 -0800 | [diff] [blame] | 129 | group_tidy_warn_pattern('cert'), |
| 130 | group_tidy_warn_pattern('clang-diagnostic'), |
Chih-Hung Hsieh | f36e01d | 2021-10-08 13:14:41 -0700 | [diff] [blame] | 131 | group_tidy_warn_pattern('concurrency'), |
Chih-Hung Hsieh | 888d143 | 2019-12-09 19:32:03 -0800 | [diff] [blame] | 132 | group_tidy_warn_pattern('cppcoreguidelines'), |
Chih-Hung Hsieh | f36e01d | 2021-10-08 13:14:41 -0700 | [diff] [blame] | 133 | group_tidy_warn_pattern('fuchsia'), |
Chih-Hung Hsieh | 888d143 | 2019-12-09 19:32:03 -0800 | [diff] [blame] | 134 | 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 Hsieh | f36e01d | 2021-10-08 13:14:41 -0700 | [diff] [blame] | 157 | group_tidy_warn_pattern('llvm'), |
| 158 | group_tidy_warn_pattern('llvmlibc'), |
Chih-Hung Hsieh | 888d143 | 2019-12-09 19:32:03 -0800 | [diff] [blame] | 159 | group_tidy_warn_pattern('misc'), |
Chih-Hung Hsieh | f36e01d | 2021-10-08 13:14:41 -0700 | [diff] [blame] | 160 | group_tidy_warn_pattern('modernize'), |
Chih-Hung Hsieh | 888d143 | 2019-12-09 19:32:03 -0800 | [diff] [blame] | 161 | 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 Hsieh | 949205a | 2020-01-10 10:33:40 -0800 | [diff] [blame] | 171 | 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 Hsieh | 888d143 | 2019-12-09 19:32:03 -0800 | [diff] [blame] | 178 | |
Chih-Hung Hsieh | 3bb6c94 | 2021-09-23 13:48:34 -0700 | [diff] [blame] | 179 | tidy_warn('TIMEOUT', [r".*: warning: clang-tidy aborted "]), |
Chih-Hung Hsieh | f36e01d | 2021-10-08 13:14:41 -0700 | [diff] [blame] | 180 | tidy_warn('Long Runs', [r".*: warning: clang-tidy used "]), |
Chih-Hung Hsieh | 3bb6c94 | 2021-09-23 13:48:34 -0700 | [diff] [blame] | 181 | |
Chih-Hung Hsieh | 888d143 | 2019-12-09 19:32:03 -0800 | [diff] [blame] | 182 | # 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 Hsieh | 1a1f90e | 2023-01-09 14:19:11 -0800 | [diff] [blame] | 227 | analyzer_warn_check('clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling'), |
Chih-Hung Hsieh | 02f0df8 | 2022-01-20 16:13:12 -0800 | [diff] [blame] | 228 | 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 Hsieh | 888d143 | 2019-12-09 19:32:03 -0800 | [diff] [blame] | 231 | 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 Hsieh | 949205a | 2020-01-10 10:33:40 -0800 | [diff] [blame] | 238 | analyzer_group_check('clang-analyzer'), # catch all |
Chih-Hung Hsieh | 888d143 | 2019-12-09 19:32:03 -0800 | [diff] [blame] | 239 | ] |
Chih-Hung Hsieh | 949205a | 2020-01-10 10:33:40 -0800 | [diff] [blame] | 240 | |
| 241 | |
| 242 | compile_patterns(warn_patterns) |