blob: d718af0f21412fb3014bfc17cdaedf6dc7ccd10c [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 Pinitas7891a732021-08-20 21:39:25 +01007 return "src/cpu/kernels/assembly " \
Michele Di Giorgio6ad60af2020-06-09 14:52:15 +01008 "src/core/NEON/kernels/assembly " \
9 "src/core/NEON/kernels/convolution/winograd " \
Georgios Pinitas51826a42019-08-02 18:01:21 +010010 "include/linux include " \
Michele Di Giorgio72610dc2020-11-18 15:29:08 +000011 ". ".split()
Anthony Barbier3dfbdeb2017-09-12 16:04:45 +010012
13def get_list_flags( filename, arch):
14 assert arch in ["armv7", "aarch64"]
Georgios Pinitas40f51a62020-11-21 03:04:18 +000015 flags = ["-std=c++14"]
Anthony Barbier3dfbdeb2017-09-12 16:04:45 +010016 flags.append("-DARM_COMPUTE_CPP_SCHEDULER=1")
Georgios Pinitas30f02152017-09-27 11:20:48 +010017 flags.append("-DARM_COMPUTE_CL")
Anthony Barbier3dfbdeb2017-09-12 16:04:45 +010018 if arch == "aarch64":
Ioan-Cristian Szabo33fd07b2017-10-26 15:42:24 +010019 flags.append("-DARM_COMPUTE_AARCH64_V8_2")
Anthony Barbier3dfbdeb2017-09-12 16:04:45 +010020 return flags
21
22def filter_files( list_files ):
23 to_check = []
24 for f in list_files:
25 if os.path.splitext(f)[1] != ".cpp":
26 continue
Anthony Barbier3dfbdeb2017-09-12 16:04:45 +010027 # Skip OMPScheduler as it causes problems in clang
Anthony Barbierb4670212018-05-18 16:55:39 +010028 if (("OMPScheduler.cpp" in f) or
29 ("CLTracePoint.cpp" in f) or
30 ("NETracePoint.cpp" in f) or
31 ("TracePoint.cpp" in f)):
Anthony Barbier3dfbdeb2017-09-12 16:04:45 +010032 continue
33 to_check.append(f)
34 return to_check
35
36def filter_clang_tidy_lines( lines ):
37 out = []
38 print_context=False
39 for i in range(0, len(lines)):
40 line = lines[i]
41
Michele Di Giorgiod556d7b2020-10-27 10:56:31 +000042 if "/arm_conv/" in line:
43 continue
44
Pablo Telloeb82fd22018-02-23 13:43:50 +000045 if "/arm_gemm/" in line:
46 continue
47
Georgios Pinitas4074c992018-01-30 18:13:46 +000048 if "/convolution/" in line:
Pablo Tello89519332017-11-17 11:52:36 +000049 continue
50
Michalis Spyroubcfd09a2019-05-01 13:03:59 +010051 if "/validate_examples/" in line:
52 continue
53
Anthony Barbier3dfbdeb2017-09-12 16:04:45 +010054 if "error:" in line:
Georgios Pinitas51545e42020-02-11 15:29:01 +000055 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 +010056 ("arm_fp16.h" in line) or
57 ("omp.h" in line) or
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +010058 ("cast from pointer to smaller type 'uintptr_t' (aka 'unsigned int') loses information" in line) or
Anthony Barbierb6eb3532018-08-08 13:20:04 +010059 ("cast from pointer to smaller type 'cl_context_properties' (aka 'int') loses information" in line) or
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +010060 ("cast from pointer to smaller type 'std::uintptr_t' (aka 'unsigned int') loses information" in line) or
Anthony Barbier3dfbdeb2017-09-12 16:04:45 +010061 ("NEMath.inl" in line and "statement expression not allowed at file scope" in line) or
Anthony Barbier2a07e182017-08-04 18:20:27 +010062 ("Utils.h" in line and "no member named 'unmap' in 'arm_compute::Tensor'" in line) or
63 ("Utils.h" in line and "no member named 'map' in 'arm_compute::Tensor'" in line) or
Pablo Tello7fad9b12018-03-14 17:55:27 +000064 ("CPUUtils.cpp" in line and "'asm/hwcap.h' file not found" in line) or
Pablo Marquez Telloa50f1932021-03-08 17:27:05 +000065 ("CPUUtils.cpp" in line and "use of undeclared identifier 'HWCAP_SVE'" in line) or
Georgios Pinitasbdcdc392021-04-22 16:42:03 +010066 ("sve" in line) or
Manuel Bottini569b7e92020-03-20 14:37:40 +000067 ("'arm_compute_version.embed' file not found" in line) ):
Anthony Barbier3dfbdeb2017-09-12 16:04:45 +010068 print_context=False
69 continue
70
71 out.append(line)
72 print_context=True
73 elif "warning:" in line:
74 if ("uninitialized record type: '__ret'" in line or
75 "local variable '__bound_functor' is still referred to by the global variable '__once_callable'" in line or
Michalis Spyrou2388de12019-05-13 15:51:05 +010076 "assigning newly created 'gsl::owner<>'" in line or
Georgios Pinitasb8d5b952019-05-16 14:13:03 +010077 "calling legacy resource function without passing a 'gsl::owner<>'" in line or
Michalis Spyrou2388de12019-05-13 15:51:05 +010078 "deleting a pointer through a type that is not marked 'gsl::owner<>'" in line or
Georgios Pinitas3faea252017-10-30 14:13:50 +000079 (any(f in line for f in ["Error.cpp","Error.h"]) and "thrown exception type is not nothrow copy constructible" in line) or
80 (any(f in line for f in ["Error.cpp","Error.h"]) and "uninitialized record type: 'args'" in line) or
81 (any(f in line for f in ["Error.cpp","Error.h"]) and "do not call c-style vararg functions" in line) or
82 (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 +000083 ("TensorAllocator.cpp" in line and "warning: pointer parameter 'ptr' can be pointer to const" in line) or
Michalis Spyroubcfd09a2019-05-01 13:03:59 +010084 ("TensorAllocator.cpp" in line and "warning: do not declare C-style arrays" in line) or
85 ("RawTensor.cpp" in line and "warning: pointer parameter 'ptr' can be pointer to const" in line) or
Michalis Spyrou7dbfc412019-05-13 13:21:28 +010086 ("RawTensor.cpp" in line and "warning: do not declare C-style arrays" in line) or
Anthony Barbier3dfbdeb2017-09-12 16:04:45 +010087 ("NEMinMaxLocationKernel.cpp" in line and "move constructors should be marked noexcept" in line) or
88 ("NEMinMaxLocationKernel.cpp" in line and "move assignment operators should be marked noexcept" in line) or
Georgios Pinitas30f02152017-09-27 11:20:48 +010089 ("CLMinMaxLocationKernel.cpp" in line and "Forming reference to null pointer" in line) or
Anthony Barbier3dfbdeb2017-09-12 16:04:45 +010090 ("PMUCounter.cpp" in line and "consider replacing 'long long' with 'int64'" in line) or
91 ("Validation.cpp" in line and "parameter 'classified_labels' is unused" in line) or
92 ("Validation.cpp" in line and "parameter 'expected_labels' is unused" in line) or
93 ("Reference.cpp" in line and "parameter 'rois' is unused" in line) or
94 ("Reference.cpp" in line and "parameter 'shapes' is unused" in line) or
95 ("Reference.cpp" in line and re.search(r"parameter '[^']+' is unused", line)) or
96 ("ReferenceCPP.cpp" in line and "parameter 'rois' is unused" in line) or
97 ("ReferenceCPP.cpp" in line and "parameter 'srcs' is unused" in line) or
98 ("ReferenceCPP.cpp" in line and re.search(r"parameter '[^']+' is unused", line)) or
99 ("NEGEMMMatrixMultiplyKernel.cpp" in line and "do not use C-style cast to convert between unrelated types" in line) or
100 ("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 +0000101 ("NESoftmaxLayerKernel.cpp" in line and "macro argument should be enclosed in parentheses" in line) or
Georgios Pinitas30f02152017-09-27 11:20:48 +0100102 ("GraphUtils.cpp" in line and "consider replacing 'unsigned long' with 'uint32'" in line) or
Anthony Barbier2a07e182017-08-04 18:20:27 +0100103 ("GraphUtils.cpp" in line and "consider replacing 'unsigned long' with 'uint64'" in line) or
Georgios Pinitas6f669f02017-09-26 12:32:57 +0100104 ("ConvolutionLayer.cpp" in line and "move assignment operators should be marked noexcept" in line) or
105 ("ConvolutionLayer.cpp" in line and "move constructors should be marked noexcept" in line) or
Georgios Pinitasbaf174e2017-09-08 19:47:30 +0100106 ("parameter 'memory_manager' is unused" in line) or
Georgios Pinitas658039b2017-09-15 16:30:50 +0100107 ("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 +0100108 ("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 +0000109 ("NEWinogradLayerKernel.cpp" in line and "use '= default' to define a trivial destructor" in line) or
Pablo Telloeb82fd22018-02-23 13:43:50 +0000110 ("NEGEMMLowpMatrixMultiplyCore.cpp" in line and "constructor does not initialize these fields" in line) or
111 ("NEGEMMLowpAssemblyMatrixMultiplyCore" in line and "constructor does not initialize these fields" in line) or
Manuel Bottinib4bb6a02021-05-24 16:01:32 +0100112 ("CpuDepthwiseConv2dNativeKernel" in line and re.search(r"parameter '[^']+' is unused", line)) or
113 ("CpuDepthwiseConv2dAssemblyDispatch" in line and re.search(r"parameter '[^']+' is unused", line)) or
114 ("CpuDepthwiseConv2dAssemblyDispatch" in line and "modernize-use-equals-default" in line) or
Pablo Tello7fad9b12018-03-14 17:55:27 +0000115 ("CPUUtils.cpp" in line and "consider replacing 'unsigned long' with 'uint64'" in line) or
116 ("CPUUtils.cpp" in line and "parameter 'cpusv' is unused" in line) or
Michalis Spyrou8e5174c2018-12-04 11:43:23 +0000117 ("CPUUtils.cpp" in line and "warning: uninitialized record type" in line) or
Michalis Spyroubcfd09a2019-05-01 13:03:59 +0100118 ("Utils.h" in line and "warning: Use of zero-allocated memory" in line) or
Georgios Pinitasbdcdc392021-04-22 16:42:03 +0100119 ("sve" in line) or
Manuel Bottinib4bb6a02021-05-24 16:01:32 +0100120 ("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 +0100121 print_context=False
122 continue
123
124 if "do not use C-style cast to convert between unrelated types" in line:
125 if i + 1 < len(lines) and "vgetq_lane_f16" in lines[i + 1]:
126 print_context=False
127 continue
128
129 if "use 'using' instead of 'typedef'" in line:
130 if i + 1 < len(lines) and "BOOST_FIXTURE_TEST_SUITE" in lines[i + 1]:
131 print_context=False
132 continue
133
134 if "do not call c-style vararg functions" in line:
135 if (i + 1 < len(lines) and
136 ("BOOST_TEST" in lines[i + 1] or
137 "BOOST_FAIL" in lines[i + 1] or
138 "BOOST_CHECK_THROW" in lines[i + 1] or
Michalis Spyrou7c60c992019-10-10 14:33:47 +0100139 "ARM_COMPUTE_ERROR_VAR" in lines[i + 1] or
Georgios Pinitas3faea252017-10-30 14:13:50 +0000140 "ARM_COMPUTE_RETURN_ON" in lines[i + 1] or
Anthony Barbier3dfbdeb2017-09-12 16:04:45 +0100141 "syscall" in lines[i + 1])):
142 print_context=False
143 continue
144
145 out.append(line)
146 print_context=True
Georgios Pinitas30f02152017-09-27 11:20:48 +0100147 elif (("CLMinMaxLocationKernel.cpp" in line and "'?' condition is false" in line) or
148 ("CLMinMaxLocationKernel.cpp" in line and "Assuming the condition is false" in line) or
149 ("CLMinMaxLocationKernel.cpp" in line and "Assuming pointer value is null" in line) or
150 ("CLMinMaxLocationKernel.cpp" in line and "Forming reference to null pointer" in line)):
151 print_context=False
152 continue
Anthony Barbier3dfbdeb2017-09-12 16:04:45 +0100153 elif print_context:
154 out.append(line)
155
156 return out
157
158if __name__ == "__main__":
159 if len(sys.argv) != 2:
160 print("usage: {} CLANG-TIDY_OUTPUT_FILE".format(sys.argv[0]))
161 sys.exit(1)
162
163 errors = []
164 with open(sys.argv[1], mode="r") as clang_tidy_file:
165 lines = clang_tidy_file.readlines()
166 errors = filter_clang_tidy_lines(lines)
Michalis Spyrou92ad0ca2019-12-17 11:43:32 +0000167 print("\n".join(errors))
Anthony Barbier3dfbdeb2017-09-12 16:04:45 +0100168
169 sys.exit(0 if len(errors) == 0 else 1)