blob: f244017dbd13705aa54305460d5e0f5a5fd8b5bb [file] [log] [blame]
Michalis Spyrou92ad0ca2019-12-17 11:43:32 +00001#!/usr/bin/env python3
Jakub Sujak2cc6e0b2023-02-15 12:27:30 +00002# -*- coding: utf-8 -*-
3#
Gunes Bayir0ee13af2024-02-07 15:34:45 +00004# Copyright (c) 2017-2024 Arm Limited.
Jakub Sujak2cc6e0b2023-02-15 12:27:30 +00005#
6# SPDX-License-Identifier: MIT
7#
8# Permission is hereby granted, free of charge, to any person obtaining a copy
9# of this software and associated documentation files (the "Software"), to
10# deal in the Software without restriction, including without limitation the
11# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
12# sell copies of the Software, and to permit persons to whom the Software is
13# furnished to do so, subject to the following conditions:
14#
15# The above copyright notice and this permission notice shall be included in all
16# copies or substantial portions of the Software.
17#
18# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24# SOFTWARE.
25
Anthony Barbier3dfbdeb2017-09-12 16:04:45 +010026import os
27import re
28import sys
29
30def get_list_includes():
Gunes Bayir0ee13af2024-02-07 15:34:45 +000031 return "compute_kernel_writer/include " \
Jakub Sujak8c49f162023-06-16 09:52:50 +010032 "src/cpu/kernels/assembly " \
Michele Di Giorgio6ad60af2020-06-09 14:52:15 +010033 "src/core/NEON/kernels/assembly " \
34 "src/core/NEON/kernels/convolution/winograd " \
Georgios Pinitas51826a42019-08-02 18:01:21 +010035 "include/linux include " \
Michele Di Giorgio72610dc2020-11-18 15:29:08 +000036 ". ".split()
Anthony Barbier3dfbdeb2017-09-12 16:04:45 +010037
38def get_list_flags( filename, arch):
39 assert arch in ["armv7", "aarch64"]
Georgios Pinitas40f51a62020-11-21 03:04:18 +000040 flags = ["-std=c++14"]
Anthony Barbier3dfbdeb2017-09-12 16:04:45 +010041 flags.append("-DARM_COMPUTE_CPP_SCHEDULER=1")
Georgios Pinitas30f02152017-09-27 11:20:48 +010042 flags.append("-DARM_COMPUTE_CL")
Jakub Sujak2cc6e0b2023-02-15 12:27:30 +000043 flags.append("-DARM_COMPUTE_OPENCL_ENABLED")
Anthony Barbier3dfbdeb2017-09-12 16:04:45 +010044 if arch == "aarch64":
Ioan-Cristian Szabo33fd07b2017-10-26 15:42:24 +010045 flags.append("-DARM_COMPUTE_AARCH64_V8_2")
SiCong Li23882a92023-06-28 09:49:45 +010046
Anthony Barbier3dfbdeb2017-09-12 16:04:45 +010047 return flags
48
49def filter_files( list_files ):
50 to_check = []
51 for f in list_files:
52 if os.path.splitext(f)[1] != ".cpp":
53 continue
Anthony Barbier3dfbdeb2017-09-12 16:04:45 +010054 # Skip OMPScheduler as it causes problems in clang
Anthony Barbierb4670212018-05-18 16:55:39 +010055 if (("OMPScheduler.cpp" in f) or
56 ("CLTracePoint.cpp" in f) or
57 ("NETracePoint.cpp" in f) or
58 ("TracePoint.cpp" in f)):
Anthony Barbier3dfbdeb2017-09-12 16:04:45 +010059 continue
60 to_check.append(f)
61 return to_check
62
63def filter_clang_tidy_lines( lines ):
64 out = []
65 print_context=False
66 for i in range(0, len(lines)):
67 line = lines[i]
68
Michele Di Giorgiod556d7b2020-10-27 10:56:31 +000069 if "/arm_conv/" in line:
70 continue
71
Pablo Telloeb82fd22018-02-23 13:43:50 +000072 if "/arm_gemm/" in line:
73 continue
74
Gian Marco Iodice6c113ed2023-01-19 17:14:26 +000075 if "compute_kernel_writer/" in line:
76 continue
77
Georgios Pinitas4074c992018-01-30 18:13:46 +000078 if "/convolution/" in line:
Pablo Tello89519332017-11-17 11:52:36 +000079 continue
80
Michalis Spyroubcfd09a2019-05-01 13:03:59 +010081 if "/validate_examples/" in line:
82 continue
83
Anthony Barbier3dfbdeb2017-09-12 16:04:45 +010084 if "error:" in line:
Georgios Pinitas51545e42020-02-11 15:29:01 +000085 if (("Version.cpp" in line and "arm_compute_version.embed" in line and "file not found" in line) or
Anthony Barbier3dfbdeb2017-09-12 16:04:45 +010086 ("arm_fp16.h" in line) or
87 ("omp.h" in line) or
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +010088 ("cast from pointer to smaller type 'uintptr_t' (aka 'unsigned int') loses information" in line) or
Anthony Barbierb6eb3532018-08-08 13:20:04 +010089 ("cast from pointer to smaller type 'cl_context_properties' (aka 'int') loses information" in line) or
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +010090 ("cast from pointer to smaller type 'std::uintptr_t' (aka 'unsigned int') loses information" in line) or
Anthony Barbier3dfbdeb2017-09-12 16:04:45 +010091 ("NEMath.inl" in line and "statement expression not allowed at file scope" in line) or
Anthony Barbier2a07e182017-08-04 18:20:27 +010092 ("Utils.h" in line and "no member named 'unmap' in 'arm_compute::Tensor'" in line) or
93 ("Utils.h" in line and "no member named 'map' in 'arm_compute::Tensor'" in line) or
Pablo Tello7fad9b12018-03-14 17:55:27 +000094 ("CPUUtils.cpp" in line and "'asm/hwcap.h' file not found" in line) or
Pablo Marquez Telloa50f1932021-03-08 17:27:05 +000095 ("CPUUtils.cpp" in line and "use of undeclared identifier 'HWCAP_SVE'" in line) or
Georgios Pinitasbdcdc392021-04-22 16:42:03 +010096 ("sve" in line) or
Manuel Bottini569b7e92020-03-20 14:37:40 +000097 ("'arm_compute_version.embed' file not found" in line) ):
Anthony Barbier3dfbdeb2017-09-12 16:04:45 +010098 print_context=False
99 continue
100
101 out.append(line)
102 print_context=True
103 elif "warning:" in line:
104 if ("uninitialized record type: '__ret'" in line or
105 "local variable '__bound_functor' is still referred to by the global variable '__once_callable'" in line or
Michalis Spyrou2388de12019-05-13 15:51:05 +0100106 "assigning newly created 'gsl::owner<>'" in line or
Georgios Pinitasb8d5b952019-05-16 14:13:03 +0100107 "calling legacy resource function without passing a 'gsl::owner<>'" in line or
Michalis Spyrou2388de12019-05-13 15:51:05 +0100108 "deleting a pointer through a type that is not marked 'gsl::owner<>'" in line or
Georgios Pinitas3faea252017-10-30 14:13:50 +0000109 (any(f in line for f in ["Error.cpp","Error.h"]) and "thrown exception type is not nothrow copy constructible" in line) or
110 (any(f in line for f in ["Error.cpp","Error.h"]) and "uninitialized record type: 'args'" in line) or
111 (any(f in line for f in ["Error.cpp","Error.h"]) and "do not call c-style vararg functions" in line) or
112 (any(f in line for f in ["Error.cpp","Error.h"]) and "do not define a C-style variadic function" in line) or
Georgios Pinitas84b51ad2017-11-07 13:24:57 +0000113 ("TensorAllocator.cpp" in line and "warning: pointer parameter 'ptr' can be pointer to const" in line) or
Michalis Spyroubcfd09a2019-05-01 13:03:59 +0100114 ("TensorAllocator.cpp" in line and "warning: do not declare C-style arrays" in line) or
115 ("RawTensor.cpp" in line and "warning: pointer parameter 'ptr' can be pointer to const" in line) or
Michalis Spyrou7dbfc412019-05-13 13:21:28 +0100116 ("RawTensor.cpp" in line and "warning: do not declare C-style arrays" in line) or
Anthony Barbier3dfbdeb2017-09-12 16:04:45 +0100117 ("NEMinMaxLocationKernel.cpp" in line and "move constructors should be marked noexcept" in line) or
118 ("NEMinMaxLocationKernel.cpp" in line and "move assignment operators should be marked noexcept" in line) or
Georgios Pinitas30f02152017-09-27 11:20:48 +0100119 ("CLMinMaxLocationKernel.cpp" in line and "Forming reference to null pointer" in line) or
Anthony Barbier3dfbdeb2017-09-12 16:04:45 +0100120 ("PMUCounter.cpp" in line and "consider replacing 'long long' with 'int64'" in line) or
121 ("Validation.cpp" in line and "parameter 'classified_labels' is unused" in line) or
122 ("Validation.cpp" in line and "parameter 'expected_labels' is unused" in line) or
123 ("Reference.cpp" in line and "parameter 'rois' is unused" in line) or
124 ("Reference.cpp" in line and "parameter 'shapes' is unused" in line) or
125 ("Reference.cpp" in line and re.search(r"parameter '[^']+' is unused", line)) or
126 ("ReferenceCPP.cpp" in line and "parameter 'rois' is unused" in line) or
127 ("ReferenceCPP.cpp" in line and "parameter 'srcs' is unused" in line) or
128 ("ReferenceCPP.cpp" in line and re.search(r"parameter '[^']+' is unused", line)) or
129 ("NEGEMMMatrixMultiplyKernel.cpp" in line and "do not use C-style cast to convert between unrelated types" in line) or
130 ("NEPoolingLayerKernel.cpp" in line and "do not use C-style cast to convert between unrelated types" in line) or
Diego Lopez Recas35ceeb22017-12-04 18:56:10 +0000131 ("NESoftmaxLayerKernel.cpp" in line and "macro argument should be enclosed in parentheses" in line) or
Georgios Pinitas30f02152017-09-27 11:20:48 +0100132 ("GraphUtils.cpp" in line and "consider replacing 'unsigned long' with 'uint32'" in line) or
Anthony Barbier2a07e182017-08-04 18:20:27 +0100133 ("GraphUtils.cpp" in line and "consider replacing 'unsigned long' with 'uint64'" in line) or
Georgios Pinitas6f669f02017-09-26 12:32:57 +0100134 ("ConvolutionLayer.cpp" in line and "move assignment operators should be marked noexcept" in line) or
135 ("ConvolutionLayer.cpp" in line and "move constructors should be marked noexcept" in line) or
Georgios Pinitasbaf174e2017-09-08 19:47:30 +0100136 ("parameter 'memory_manager' is unused" in line) or
Georgios Pinitas658039b2017-09-15 16:30:50 +0100137 ("parameter 'memory_manager' is copied for each invocation but only used as a const reference" in line) or
Pablo Tellodaaa1fa2017-10-25 11:40:50 +0100138 ("DeconvolutionLayer.cpp" in line and "casting (double + 0.5) to integer leads to incorrect rounding; consider using lround" in line) or
Pablo Tello3d4968a2017-12-04 15:03:35 +0000139 ("NEWinogradLayerKernel.cpp" in line and "use '= default' to define a trivial destructor" in line) or
Pablo Telloeb82fd22018-02-23 13:43:50 +0000140 ("NEGEMMLowpMatrixMultiplyCore.cpp" in line and "constructor does not initialize these fields" in line) or
141 ("NEGEMMLowpAssemblyMatrixMultiplyCore" in line and "constructor does not initialize these fields" in line) or
Manuel Bottinib4bb6a02021-05-24 16:01:32 +0100142 ("CpuDepthwiseConv2dNativeKernel" in line and re.search(r"parameter '[^']+' is unused", line)) or
143 ("CpuDepthwiseConv2dAssemblyDispatch" in line and re.search(r"parameter '[^']+' is unused", line)) or
144 ("CpuDepthwiseConv2dAssemblyDispatch" in line and "modernize-use-equals-default" in line) or
Pablo Tello7fad9b12018-03-14 17:55:27 +0000145 ("CPUUtils.cpp" in line and "consider replacing 'unsigned long' with 'uint64'" in line) or
146 ("CPUUtils.cpp" in line and "parameter 'cpusv' is unused" in line) or
Michalis Spyrou8e5174c2018-12-04 11:43:23 +0000147 ("CPUUtils.cpp" in line and "warning: uninitialized record type" in line) or
Michalis Spyroubcfd09a2019-05-01 13:03:59 +0100148 ("Utils.h" in line and "warning: Use of zero-allocated memory" in line) or
Georgios Pinitasbdcdc392021-04-22 16:42:03 +0100149 ("sve" in line) or
Manuel Bottinib4bb6a02021-05-24 16:01:32 +0100150 ("CpuDepthwiseConv2dNativeKernel.cpp" in line and "misc-non-private-member-variables-in-classes" in line)): # This is to prevent false positive, should be reassessed with the newer clang-tidy
Anthony Barbier3dfbdeb2017-09-12 16:04:45 +0100151 print_context=False
152 continue
153
154 if "do not use C-style cast to convert between unrelated types" in line:
155 if i + 1 < len(lines) and "vgetq_lane_f16" in lines[i + 1]:
156 print_context=False
157 continue
158
159 if "use 'using' instead of 'typedef'" in line:
160 if i + 1 < len(lines) and "BOOST_FIXTURE_TEST_SUITE" in lines[i + 1]:
161 print_context=False
162 continue
163
164 if "do not call c-style vararg functions" in line:
165 if (i + 1 < len(lines) and
166 ("BOOST_TEST" in lines[i + 1] or
167 "BOOST_FAIL" in lines[i + 1] or
168 "BOOST_CHECK_THROW" in lines[i + 1] or
Michalis Spyrou7c60c992019-10-10 14:33:47 +0100169 "ARM_COMPUTE_ERROR_VAR" in lines[i + 1] or
Georgios Pinitas3faea252017-10-30 14:13:50 +0000170 "ARM_COMPUTE_RETURN_ON" in lines[i + 1] or
Anthony Barbier3dfbdeb2017-09-12 16:04:45 +0100171 "syscall" in lines[i + 1])):
172 print_context=False
173 continue
174
175 out.append(line)
176 print_context=True
Georgios Pinitas30f02152017-09-27 11:20:48 +0100177 elif (("CLMinMaxLocationKernel.cpp" in line and "'?' condition is false" in line) or
178 ("CLMinMaxLocationKernel.cpp" in line and "Assuming the condition is false" in line) or
179 ("CLMinMaxLocationKernel.cpp" in line and "Assuming pointer value is null" in line) or
180 ("CLMinMaxLocationKernel.cpp" in line and "Forming reference to null pointer" in line)):
181 print_context=False
182 continue
Anthony Barbier3dfbdeb2017-09-12 16:04:45 +0100183 elif print_context:
184 out.append(line)
185
186 return out
187
188if __name__ == "__main__":
189 if len(sys.argv) != 2:
190 print("usage: {} CLANG-TIDY_OUTPUT_FILE".format(sys.argv[0]))
191 sys.exit(1)
192
193 errors = []
194 with open(sys.argv[1], mode="r") as clang_tidy_file:
195 lines = clang_tidy_file.readlines()
196 errors = filter_clang_tidy_lines(lines)
Michalis Spyrou92ad0ca2019-12-17 11:43:32 +0000197 print("\n".join(errors))
Anthony Barbier3dfbdeb2017-09-12 16:04:45 +0100198
199 sys.exit(0 if len(errors) == 0 else 1)