blob: a030f211a4861eae1f8a00e02c03d0e107c1f107 [file] [log] [blame]
Jenkins6a7771e2020-05-28 11:28:36 +01001#!/usr/bin/env python3
2import os
3import re
4import sys
5
6def get_list_includes():
7 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 " \
11 "include/linux include " \
12 ". " \
13 "3rdparty/include kernels".split()
14
15def get_list_flags( filename, arch):
16 assert arch in ["armv7", "aarch64"]
17 flags = ["-std=c++11"]
18 flags.append("-DARM_COMPUTE_CPP_SCHEDULER=1")
19 flags.append("-DARM_COMPUTE_CL")
20 flags.append("-DARM_COMPUTE_GC")
21 if arch == "aarch64":
22 flags.append("-DARM_COMPUTE_AARCH64_V8_2")
23 return flags
24
25def filter_files( list_files ):
26 to_check = []
27 for f in list_files:
28 if os.path.splitext(f)[1] != ".cpp":
29 continue
30 # Skip OMPScheduler as it causes problems in clang
31 if (("OMPScheduler.cpp" in f) or
32 ("CLTracePoint.cpp" in f) or
33 ("NETracePoint.cpp" in f) or
34 ("TracePoint.cpp" in f)):
35 continue
36 to_check.append(f)
37 return to_check
38
39def filter_clang_tidy_lines( lines ):
40 out = []
41 print_context=False
42 for i in range(0, len(lines)):
43 line = lines[i]
44
45 if "/arm_gemm/" in line:
46 continue
47
48 if "/convolution/" in line:
49 continue
50
51 if "/validate_examples/" in line:
52 continue
53
54 if "error:" in line:
55 if (("Version.cpp" in line and "arm_compute_version.embed" in line and "file not found" in line) or
56 ("arm_fp16.h" in line) or
57 ("omp.h" in line) or
58 ("cast from pointer to smaller type 'uintptr_t' (aka 'unsigned int') loses information" in line) or
59 ("cast from pointer to smaller type 'cl_context_properties' (aka 'int') loses information" in line) or
60 ("cast from pointer to smaller type 'std::uintptr_t' (aka 'unsigned int') loses information" in line) or
61 ("NEMath.inl" in line and "statement expression not allowed at file scope" in line) or
62 ("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
64 ("CPUUtils.cpp" in line and "'asm/hwcap.h' file not found" in line) or
65 "3rdparty" in line or
66 ("'arm_compute_version.embed' file not found" in line) ):
67 print_context=False
68 continue
69
70 out.append(line)
71 print_context=True
72 elif "warning:" in line:
73 if ("uninitialized record type: '__ret'" in line or
74 "local variable '__bound_functor' is still referred to by the global variable '__once_callable'" in line or
75 "assigning newly created 'gsl::owner<>'" in line or
76 "calling legacy resource function without passing a 'gsl::owner<>'" in line or
77 "deleting a pointer through a type that is not marked 'gsl::owner<>'" in line or
78 (any(f in line for f in ["Error.cpp","Error.h"]) and "thrown exception type is not nothrow copy constructible" in line) or
79 (any(f in line for f in ["Error.cpp","Error.h"]) and "uninitialized record type: 'args'" in line) or
80 (any(f in line for f in ["Error.cpp","Error.h"]) and "do not call c-style vararg functions" in line) or
81 (any(f in line for f in ["Error.cpp","Error.h"]) and "do not define a C-style variadic function" in line) or
82 ("TensorAllocator.cpp" in line and "warning: pointer parameter 'ptr' can be pointer to const" in line) or
83 ("TensorAllocator.cpp" in line and "warning: do not declare C-style arrays" in line) or
84 ("RawTensor.cpp" in line and "warning: pointer parameter 'ptr' can be pointer to const" in line) or
85 ("RawTensor.cpp" in line and "warning: do not declare C-style arrays" in line) or
86 ("GCBufferAllocator.cpp" in line and "warning: initializing non-owner" in line) or
87 ("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
89 ("CLMinMaxLocationKernel.cpp" in line and "Forming reference to null pointer" in line) or
90 ("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
101 ("NESoftmaxLayerKernel.cpp" in line and "macro argument should be enclosed in parentheses" in line) or
102 ("GraphUtils.cpp" in line and "consider replacing 'unsigned long' with 'uint32'" in line) or
103 ("GraphUtils.cpp" in line and "consider replacing 'unsigned long' with 'uint64'" in line) or
104 ("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
106 ("parameter 'memory_manager' is unused" in line) or
107 ("parameter 'memory_manager' is copied for each invocation but only used as a const reference" in line) or
108 ("DeconvolutionLayer.cpp" in line and "casting (double + 0.5) to integer leads to incorrect rounding; consider using lround" in line) or
109 ("NEWinogradLayerKernel.cpp" in line and "use '= default' to define a trivial destructor" in line) or
110 ("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
112 ("CPUUtils.cpp" in line and "consider replacing 'unsigned long' with 'uint64'" in line) or
113 ("CPUUtils.cpp" in line and "parameter 'cpusv' is unused" in line) or
114 ("CPUUtils.cpp" in line and "warning: uninitialized record type" in line) or
115 ("GCKernelLibrary.cpp" in line and "warning: do not declare C-style arrays" in line) or
116 ("Utils.h" in line and "warning: Use of zero-allocated memory" in line) or
117 "3rdparty" in line):
118 print_context=False
119 continue
120
121 if "do not use C-style cast to convert between unrelated types" in line:
122 if i + 1 < len(lines) and "vgetq_lane_f16" in lines[i + 1]:
123 print_context=False
124 continue
125
126 if "use 'using' instead of 'typedef'" in line:
127 if i + 1 < len(lines) and "BOOST_FIXTURE_TEST_SUITE" in lines[i + 1]:
128 print_context=False
129 continue
130
131 if "do not call c-style vararg functions" in line:
132 if (i + 1 < len(lines) and
133 ("BOOST_TEST" in lines[i + 1] or
134 "BOOST_FAIL" in lines[i + 1] or
135 "BOOST_CHECK_THROW" in lines[i + 1] or
136 "ARM_COMPUTE_ERROR_VAR" in lines[i + 1] or
137 "ARM_COMPUTE_RETURN_ON" in lines[i + 1] or
138 "syscall" in lines[i + 1])):
139 print_context=False
140 continue
141
142 out.append(line)
143 print_context=True
144 elif (("CLMinMaxLocationKernel.cpp" in line and "'?' condition is false" in line) or
145 ("CLMinMaxLocationKernel.cpp" in line and "Assuming the condition is false" in line) or
146 ("CLMinMaxLocationKernel.cpp" in line and "Assuming pointer value is null" in line) or
147 ("CLMinMaxLocationKernel.cpp" in line and "Forming reference to null pointer" in line)):
148 print_context=False
149 continue
150 elif print_context:
151 out.append(line)
152
153 return out
154
155if __name__ == "__main__":
156 if len(sys.argv) != 2:
157 print("usage: {} CLANG-TIDY_OUTPUT_FILE".format(sys.argv[0]))
158 sys.exit(1)
159
160 errors = []
161 with open(sys.argv[1], mode="r") as clang_tidy_file:
162 lines = clang_tidy_file.readlines()
163 errors = filter_clang_tidy_lines(lines)
164 print("\n".join(errors))
165
166 sys.exit(0 if len(errors) == 0 else 1)