blob: 2e72c824f079588926317f65efa44720caae85f3 [file] [log] [blame]
Michalis Spyrou92ad0ca2019-12-17 11:43:32 +00001#!/usr/bin/env python3
Anthony Barbier3dfbdeb2017-09-12 16:04:45 +01002import os
3import re
4import sys
5
6def get_list_includes():
Georgios Pinitas51826a42019-08-02 18:01:21 +01007 return "arm_compute/core/NEON/kernels/assembly " \
8 "arm_compute/core/NEON/kernels/convolution/common " \
9 "arm_compute/core/NEON/kernels/convolution/depthwise " \
10 "arm_compute/core/NEON/kernels/convolution/winograd " \
Michele Di Giorgio6ad60af2020-06-09 14:52:15 +010011 "src/core/NEON/kernels/assembly " \
12 "src/core/NEON/kernels/convolution/winograd " \
Georgios Pinitas51826a42019-08-02 18:01:21 +010013 "include/linux include " \
Michele Di Giorgio72610dc2020-11-18 15:29:08 +000014 ". ".split()
Anthony Barbier3dfbdeb2017-09-12 16:04:45 +010015
16def get_list_flags( filename, arch):
17 assert arch in ["armv7", "aarch64"]
Georgios Pinitas40f51a62020-11-21 03:04:18 +000018 flags = ["-std=c++14"]
Anthony Barbier3dfbdeb2017-09-12 16:04:45 +010019 flags.append("-DARM_COMPUTE_CPP_SCHEDULER=1")
Georgios Pinitas30f02152017-09-27 11:20:48 +010020 flags.append("-DARM_COMPUTE_CL")
Anthony Barbier7068f992017-10-26 15:23:08 +010021 flags.append("-DARM_COMPUTE_GC")
Anthony Barbier3dfbdeb2017-09-12 16:04:45 +010022 if arch == "aarch64":
Ioan-Cristian Szabo33fd07b2017-10-26 15:42:24 +010023 flags.append("-DARM_COMPUTE_AARCH64_V8_2")
Anthony Barbier3dfbdeb2017-09-12 16:04:45 +010024 return flags
25
26def filter_files( list_files ):
27 to_check = []
28 for f in list_files:
29 if os.path.splitext(f)[1] != ".cpp":
30 continue
Anthony Barbier3dfbdeb2017-09-12 16:04:45 +010031 # Skip OMPScheduler as it causes problems in clang
Anthony Barbierb4670212018-05-18 16:55:39 +010032 if (("OMPScheduler.cpp" in f) or
33 ("CLTracePoint.cpp" in f) or
34 ("NETracePoint.cpp" in f) or
35 ("TracePoint.cpp" in f)):
Anthony Barbier3dfbdeb2017-09-12 16:04:45 +010036 continue
37 to_check.append(f)
38 return to_check
39
40def filter_clang_tidy_lines( lines ):
41 out = []
42 print_context=False
43 for i in range(0, len(lines)):
44 line = lines[i]
45
Michele Di Giorgiod556d7b2020-10-27 10:56:31 +000046 if "/arm_conv/" in line:
47 continue
48
Pablo Telloeb82fd22018-02-23 13:43:50 +000049 if "/arm_gemm/" in line:
50 continue
51
Georgios Pinitas4074c992018-01-30 18:13:46 +000052 if "/convolution/" in line:
Pablo Tello89519332017-11-17 11:52:36 +000053 continue
54
Michalis Spyroubcfd09a2019-05-01 13:03:59 +010055 if "/validate_examples/" in line:
56 continue
57
Anthony Barbier3dfbdeb2017-09-12 16:04:45 +010058 if "error:" in line:
Georgios Pinitas51545e42020-02-11 15:29:01 +000059 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 +010060 ("arm_fp16.h" in line) or
61 ("omp.h" in line) or
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +010062 ("cast from pointer to smaller type 'uintptr_t' (aka 'unsigned int') loses information" in line) or
Anthony Barbierb6eb3532018-08-08 13:20:04 +010063 ("cast from pointer to smaller type 'cl_context_properties' (aka 'int') loses information" in line) or
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +010064 ("cast from pointer to smaller type 'std::uintptr_t' (aka 'unsigned int') loses information" in line) or
Anthony Barbier3dfbdeb2017-09-12 16:04:45 +010065 ("NEMath.inl" in line and "statement expression not allowed at file scope" in line) or
Anthony Barbier2a07e182017-08-04 18:20:27 +010066 ("Utils.h" in line and "no member named 'unmap' in 'arm_compute::Tensor'" in line) or
67 ("Utils.h" in line and "no member named 'map' in 'arm_compute::Tensor'" in line) or
Pablo Tello7fad9b12018-03-14 17:55:27 +000068 ("CPUUtils.cpp" in line and "'asm/hwcap.h' file not found" in line) or
Pablo Marquez Telloa50f1932021-03-08 17:27:05 +000069 ("CPUUtils.cpp" in line and "use of undeclared identifier 'HWCAP_SVE'" in line) or
Manuel Bottini569b7e92020-03-20 14:37:40 +000070 ("'arm_compute_version.embed' file not found" in line) ):
Anthony Barbier3dfbdeb2017-09-12 16:04:45 +010071 print_context=False
72 continue
73
74 out.append(line)
75 print_context=True
76 elif "warning:" in line:
77 if ("uninitialized record type: '__ret'" in line or
78 "local variable '__bound_functor' is still referred to by the global variable '__once_callable'" in line or
Michalis Spyrou2388de12019-05-13 15:51:05 +010079 "assigning newly created 'gsl::owner<>'" in line or
Georgios Pinitasb8d5b952019-05-16 14:13:03 +010080 "calling legacy resource function without passing a 'gsl::owner<>'" in line or
Michalis Spyrou2388de12019-05-13 15:51:05 +010081 "deleting a pointer through a type that is not marked 'gsl::owner<>'" in line or
Georgios Pinitas3faea252017-10-30 14:13:50 +000082 (any(f in line for f in ["Error.cpp","Error.h"]) and "thrown exception type is not nothrow copy constructible" in line) or
83 (any(f in line for f in ["Error.cpp","Error.h"]) and "uninitialized record type: 'args'" in line) or
84 (any(f in line for f in ["Error.cpp","Error.h"]) and "do not call c-style vararg functions" in line) or
85 (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 +000086 ("TensorAllocator.cpp" in line and "warning: pointer parameter 'ptr' can be pointer to const" in line) or
Michalis Spyroubcfd09a2019-05-01 13:03:59 +010087 ("TensorAllocator.cpp" in line and "warning: do not declare C-style arrays" in line) or
88 ("RawTensor.cpp" in line and "warning: pointer parameter 'ptr' can be pointer to const" in line) or
Michalis Spyrou7dbfc412019-05-13 13:21:28 +010089 ("RawTensor.cpp" in line and "warning: do not declare C-style arrays" in line) or
90 ("GCBufferAllocator.cpp" in line and "warning: initializing non-owner" in line) or
Anthony Barbier3dfbdeb2017-09-12 16:04:45 +010091 ("NEMinMaxLocationKernel.cpp" in line and "move constructors should be marked noexcept" in line) or
92 ("NEMinMaxLocationKernel.cpp" in line and "move assignment operators should be marked noexcept" in line) or
Georgios Pinitas30f02152017-09-27 11:20:48 +010093 ("CLMinMaxLocationKernel.cpp" in line and "Forming reference to null pointer" in line) or
Anthony Barbier3dfbdeb2017-09-12 16:04:45 +010094 ("PMUCounter.cpp" in line and "consider replacing 'long long' with 'int64'" in line) or
95 ("Validation.cpp" in line and "parameter 'classified_labels' is unused" in line) or
96 ("Validation.cpp" in line and "parameter 'expected_labels' is unused" in line) or
97 ("Reference.cpp" in line and "parameter 'rois' is unused" in line) or
98 ("Reference.cpp" in line and "parameter 'shapes' is unused" in line) or
99 ("Reference.cpp" in line and re.search(r"parameter '[^']+' is unused", line)) or
100 ("ReferenceCPP.cpp" in line and "parameter 'rois' is unused" in line) or
101 ("ReferenceCPP.cpp" in line and "parameter 'srcs' is unused" in line) or
102 ("ReferenceCPP.cpp" in line and re.search(r"parameter '[^']+' is unused", line)) or
103 ("NEGEMMMatrixMultiplyKernel.cpp" in line and "do not use C-style cast to convert between unrelated types" in line) or
104 ("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 +0000105 ("NESoftmaxLayerKernel.cpp" in line and "macro argument should be enclosed in parentheses" in line) or
Georgios Pinitas30f02152017-09-27 11:20:48 +0100106 ("GraphUtils.cpp" in line and "consider replacing 'unsigned long' with 'uint32'" in line) or
Anthony Barbier2a07e182017-08-04 18:20:27 +0100107 ("GraphUtils.cpp" in line and "consider replacing 'unsigned long' with 'uint64'" in line) or
Georgios Pinitas6f669f02017-09-26 12:32:57 +0100108 ("ConvolutionLayer.cpp" in line and "move assignment operators should be marked noexcept" in line) or
109 ("ConvolutionLayer.cpp" in line and "move constructors should be marked noexcept" in line) or
Georgios Pinitasbaf174e2017-09-08 19:47:30 +0100110 ("parameter 'memory_manager' is unused" in line) or
Georgios Pinitas658039b2017-09-15 16:30:50 +0100111 ("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 +0100112 ("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 +0000113 ("NEWinogradLayerKernel.cpp" in line and "use '= default' to define a trivial destructor" in line) or
Pablo Telloeb82fd22018-02-23 13:43:50 +0000114 ("NEGEMMLowpMatrixMultiplyCore.cpp" in line and "constructor does not initialize these fields" in line) or
115 ("NEGEMMLowpAssemblyMatrixMultiplyCore" in line and "constructor does not initialize these fields" in line) or
Sang-Hoon Park68dd25f2020-10-19 16:00:11 +0100116 ("NEDepthwiseConvolutionLayerNativeKernel" in line and re.search(r"parameter '[^']+' is unused", line)) or
117 ("NEDepthwiseConvolutionAssemblyDispatch" in line and re.search(r"parameter '[^']+' is unused", line)) or
Pablo Tello7fad9b12018-03-14 17:55:27 +0000118 ("CPUUtils.cpp" in line and "consider replacing 'unsigned long' with 'uint64'" in line) or
119 ("CPUUtils.cpp" in line and "parameter 'cpusv' is unused" in line) or
Michalis Spyrou8e5174c2018-12-04 11:43:23 +0000120 ("CPUUtils.cpp" in line and "warning: uninitialized record type" in line) or
Michalis Spyroubcfd09a2019-05-01 13:03:59 +0100121 ("GCKernelLibrary.cpp" in line and "warning: do not declare C-style arrays" in line) or
122 ("Utils.h" in line and "warning: Use of zero-allocated memory" in line) or
Sang-Hoon Park68dd25f2020-10-19 16:00:11 +0100123 ("NEDepthwiseConvolutionLayerNativeKernel.cpp" in line and "misc-non-private-member-variables-in-classes" in line) or # This is to prevent false positive, should be reassessed with the newer clang-tidy
Michele Di Giorgio72610dc2020-11-18 15:29:08 +0000124 ("NEDepthwiseConvolutionLayerNativeKernel.cpp" in line and "cppcoreguidelines-pro-type-member-init" in line)): # This is to prevent false positive, should be reassessed with the newer clang-tidy
Anthony Barbier3dfbdeb2017-09-12 16:04:45 +0100125 print_context=False
126 continue
127
128 if "do not use C-style cast to convert between unrelated types" in line:
129 if i + 1 < len(lines) and "vgetq_lane_f16" in lines[i + 1]:
130 print_context=False
131 continue
132
133 if "use 'using' instead of 'typedef'" in line:
134 if i + 1 < len(lines) and "BOOST_FIXTURE_TEST_SUITE" in lines[i + 1]:
135 print_context=False
136 continue
137
138 if "do not call c-style vararg functions" in line:
139 if (i + 1 < len(lines) and
140 ("BOOST_TEST" in lines[i + 1] or
141 "BOOST_FAIL" in lines[i + 1] or
142 "BOOST_CHECK_THROW" in lines[i + 1] or
Michalis Spyrou7c60c992019-10-10 14:33:47 +0100143 "ARM_COMPUTE_ERROR_VAR" in lines[i + 1] or
Georgios Pinitas3faea252017-10-30 14:13:50 +0000144 "ARM_COMPUTE_RETURN_ON" in lines[i + 1] or
Anthony Barbier3dfbdeb2017-09-12 16:04:45 +0100145 "syscall" in lines[i + 1])):
146 print_context=False
147 continue
148
149 out.append(line)
150 print_context=True
Georgios Pinitas30f02152017-09-27 11:20:48 +0100151 elif (("CLMinMaxLocationKernel.cpp" in line and "'?' condition is false" in line) or
152 ("CLMinMaxLocationKernel.cpp" in line and "Assuming the condition is false" in line) or
153 ("CLMinMaxLocationKernel.cpp" in line and "Assuming pointer value is null" in line) or
154 ("CLMinMaxLocationKernel.cpp" in line and "Forming reference to null pointer" in line)):
155 print_context=False
156 continue
Anthony Barbier3dfbdeb2017-09-12 16:04:45 +0100157 elif print_context:
158 out.append(line)
159
160 return out
161
162if __name__ == "__main__":
163 if len(sys.argv) != 2:
164 print("usage: {} CLANG-TIDY_OUTPUT_FILE".format(sys.argv[0]))
165 sys.exit(1)
166
167 errors = []
168 with open(sys.argv[1], mode="r") as clang_tidy_file:
169 lines = clang_tidy_file.readlines()
170 errors = filter_clang_tidy_lines(lines)
Michalis Spyrou92ad0ca2019-12-17 11:43:32 +0000171 print("\n".join(errors))
Anthony Barbier3dfbdeb2017-09-12 16:04:45 +0100172
173 sys.exit(0 if len(errors) == 0 else 1)