blob: 4e6ede3efbff07e1ab5e900ea6c7d28b4daddc59 [file] [log] [blame]
Anthony Barbier3dfbdeb2017-09-12 16:04:45 +01001#!/usr/bin/env python
2import os
3import re
4import sys
5
6def get_list_includes():
Michalis Spyroua4f378d2019-04-26 14:54:54 +01007 return "arm_compute/core/NEON/kernels/assembly arm_compute/core/NEON/kernels/convolution/common include/linux include . 3rdparty/include kernels".split()
Anthony Barbier3dfbdeb2017-09-12 16:04:45 +01008
9def get_list_flags( filename, arch):
10 assert arch in ["armv7", "aarch64"]
11 flags = ["-std=c++11"]
Anthony Barbier3dfbdeb2017-09-12 16:04:45 +010012 flags.append("-DARM_COMPUTE_CPP_SCHEDULER=1")
Georgios Pinitas30f02152017-09-27 11:20:48 +010013 flags.append("-DARM_COMPUTE_CL")
Anthony Barbier7068f992017-10-26 15:23:08 +010014 flags.append("-DARM_COMPUTE_GC")
Anthony Barbier3dfbdeb2017-09-12 16:04:45 +010015 if arch == "aarch64":
Ioan-Cristian Szabo33fd07b2017-10-26 15:42:24 +010016 flags.append("-DARM_COMPUTE_AARCH64_V8_2")
Anthony Barbier3dfbdeb2017-09-12 16:04:45 +010017 return flags
18
19def filter_files( list_files ):
20 to_check = []
21 for f in list_files:
22 if os.path.splitext(f)[1] != ".cpp":
23 continue
Anthony Barbier3dfbdeb2017-09-12 16:04:45 +010024 # Skip OMPScheduler as it causes problems in clang
25 if "OMPScheduler.cpp" in f:
26 continue
27 to_check.append(f)
28 return to_check
29
30def filter_clang_tidy_lines( lines ):
31 out = []
32 print_context=False
33 for i in range(0, len(lines)):
34 line = lines[i]
35
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +010036 if "/assembly/" in line:
37 continue
38
Pablo Telloeb82fd22018-02-23 13:43:50 +000039 if "/arm_gemm/" in line:
40 continue
41
Georgios Pinitas4074c992018-01-30 18:13:46 +000042 if "/convolution/" in line:
Pablo Tello89519332017-11-17 11:52:36 +000043 continue
44
Michalis Spyrou9d0b5f82019-05-01 13:03:59 +010045 if "/validate_examples/" in line:
46 continue
47
Anthony Barbier3dfbdeb2017-09-12 16:04:45 +010048 if "error:" in line:
49 if (("Utils.cpp" in line and "'arm_compute_version.embed' file not found" in line) or
Anthony Barbier3dfbdeb2017-09-12 16:04:45 +010050 ("arm_fp16.h" in line) or
51 ("omp.h" in line) or
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +010052 ("cast from pointer to smaller type 'uintptr_t' (aka 'unsigned int') loses information" in line) or
Anthony Barbierb6eb3532018-08-08 13:20:04 +010053 ("cast from pointer to smaller type 'cl_context_properties' (aka 'int') loses information" in line) or
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +010054 ("cast from pointer to smaller type 'std::uintptr_t' (aka 'unsigned int') loses information" in line) or
Anthony Barbier3dfbdeb2017-09-12 16:04:45 +010055 ("NEMath.inl" in line and "statement expression not allowed at file scope" in line) or
Anthony Barbier2a07e182017-08-04 18:20:27 +010056 ("Utils.h" in line and "no member named 'unmap' in 'arm_compute::Tensor'" in line) or
57 ("Utils.h" in line and "no member named 'map' in 'arm_compute::Tensor'" in line) or
Pablo Tello7fad9b12018-03-14 17:55:27 +000058 ("CPUUtils.cpp" in line and "'asm/hwcap.h' file not found" in line) or
Anthony Barbier3dfbdeb2017-09-12 16:04:45 +010059 "3rdparty" in line):
60 print_context=False
61 continue
62
63 out.append(line)
64 print_context=True
65 elif "warning:" in line:
66 if ("uninitialized record type: '__ret'" in line or
67 "local variable '__bound_functor' is still referred to by the global variable '__once_callable'" in line or
Michalis Spyrou57f5d282019-05-13 15:51:05 +010068 "assigning newly created 'gsl::owner<>'" in line or
69 "deleting a pointer through a type that is not marked 'gsl::owner<>'" in line or
Georgios Pinitas3faea252017-10-30 14:13:50 +000070 (any(f in line for f in ["Error.cpp","Error.h"]) and "thrown exception type is not nothrow copy constructible" in line) or
71 (any(f in line for f in ["Error.cpp","Error.h"]) and "uninitialized record type: 'args'" in line) or
72 (any(f in line for f in ["Error.cpp","Error.h"]) and "do not call c-style vararg functions" in line) or
73 (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 +000074 ("TensorAllocator.cpp" in line and "warning: pointer parameter 'ptr' can be pointer to const" in line) or
Michalis Spyrou9d0b5f82019-05-01 13:03:59 +010075 ("TensorAllocator.cpp" in line and "warning: do not declare C-style arrays" in line) or
76 ("RawTensor.cpp" in line and "warning: pointer parameter 'ptr' can be pointer to const" in line) or
Michalis Spyroubf38cff2019-05-13 13:21:28 +010077 ("RawTensor.cpp" in line and "warning: do not declare C-style arrays" in line) or
78 ("GCBufferAllocator.cpp" in line and "warning: initializing non-owner" in line) or
Anthony Barbier3dfbdeb2017-09-12 16:04:45 +010079 ("NEMinMaxLocationKernel.cpp" in line and "move constructors should be marked noexcept" in line) or
80 ("NEMinMaxLocationKernel.cpp" in line and "move assignment operators should be marked noexcept" in line) or
Georgios Pinitas30f02152017-09-27 11:20:48 +010081 ("CLMinMaxLocationKernel.cpp" in line and "Forming reference to null pointer" in line) or
Anthony Barbier3dfbdeb2017-09-12 16:04:45 +010082 ("PMUCounter.cpp" in line and "consider replacing 'long long' with 'int64'" in line) or
83 ("Validation.cpp" in line and "parameter 'classified_labels' is unused" in line) or
84 ("Validation.cpp" in line and "parameter 'expected_labels' is unused" in line) or
85 ("Reference.cpp" in line and "parameter 'rois' is unused" in line) or
86 ("Reference.cpp" in line and "parameter 'shapes' is unused" in line) or
87 ("Reference.cpp" in line and re.search(r"parameter '[^']+' is unused", line)) or
88 ("ReferenceCPP.cpp" in line and "parameter 'rois' is unused" in line) or
89 ("ReferenceCPP.cpp" in line and "parameter 'srcs' is unused" in line) or
90 ("ReferenceCPP.cpp" in line and re.search(r"parameter '[^']+' is unused", line)) or
91 ("NEGEMMMatrixMultiplyKernel.cpp" in line and "do not use C-style cast to convert between unrelated types" in line) or
92 ("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 +000093 ("NESoftmaxLayerKernel.cpp" in line and "macro argument should be enclosed in parentheses" in line) or
Georgios Pinitas30f02152017-09-27 11:20:48 +010094 ("GraphUtils.cpp" in line and "consider replacing 'unsigned long' with 'uint32'" in line) or
Anthony Barbier2a07e182017-08-04 18:20:27 +010095 ("GraphUtils.cpp" in line and "consider replacing 'unsigned long' with 'uint64'" in line) or
Georgios Pinitas6f669f02017-09-26 12:32:57 +010096 ("ConvolutionLayer.cpp" in line and "move assignment operators should be marked noexcept" in line) or
97 ("ConvolutionLayer.cpp" in line and "move constructors should be marked noexcept" in line) or
Georgios Pinitasbaf174e2017-09-08 19:47:30 +010098 ("parameter 'memory_manager' is unused" in line) or
Georgios Pinitas658039b2017-09-15 16:30:50 +010099 ("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 +0100100 ("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 +0000101 ("NEWinogradLayerKernel.cpp" in line and "use '= default' to define a trivial destructor" in line) or
Pablo Telloeb82fd22018-02-23 13:43:50 +0000102 ("NEGEMMLowpMatrixMultiplyCore.cpp" in line and "constructor does not initialize these fields" in line) or
103 ("NEGEMMLowpAssemblyMatrixMultiplyCore" in line and "constructor does not initialize these fields" in line) or
Pablo Tello7fad9b12018-03-14 17:55:27 +0000104 ("CPUUtils.cpp" in line and "consider replacing 'unsigned long' with 'uint64'" in line) or
105 ("CPUUtils.cpp" in line and "parameter 'cpusv' is unused" in line) or
Michalis Spyrou8e5174c2018-12-04 11:43:23 +0000106 ("CPUUtils.cpp" in line and "warning: uninitialized record type" in line) or
Michalis Spyrou9d0b5f82019-05-01 13:03:59 +0100107 ("GCKernelLibrary.cpp" in line and "warning: do not declare C-style arrays" in line) or
108 ("Utils.h" in line and "warning: Use of zero-allocated memory" in line) or
Anthony Barbier3dfbdeb2017-09-12 16:04:45 +0100109 "3rdparty" in line):
110 print_context=False
111 continue
112
113 if "do not use C-style cast to convert between unrelated types" in line:
114 if i + 1 < len(lines) and "vgetq_lane_f16" in lines[i + 1]:
115 print_context=False
116 continue
117
118 if "use 'using' instead of 'typedef'" in line:
119 if i + 1 < len(lines) and "BOOST_FIXTURE_TEST_SUITE" in lines[i + 1]:
120 print_context=False
121 continue
122
123 if "do not call c-style vararg functions" in line:
124 if (i + 1 < len(lines) and
125 ("BOOST_TEST" in lines[i + 1] or
126 "BOOST_FAIL" in lines[i + 1] or
127 "BOOST_CHECK_THROW" in lines[i + 1] or
Georgios Pinitas3faea252017-10-30 14:13:50 +0000128 "ARM_COMPUTE_RETURN_ON" in lines[i + 1] or
Anthony Barbier3dfbdeb2017-09-12 16:04:45 +0100129 "syscall" in lines[i + 1])):
130 print_context=False
131 continue
132
133 out.append(line)
134 print_context=True
Georgios Pinitas30f02152017-09-27 11:20:48 +0100135 elif (("CLMinMaxLocationKernel.cpp" in line and "'?' condition is false" in line) or
136 ("CLMinMaxLocationKernel.cpp" in line and "Assuming the condition is false" in line) or
137 ("CLMinMaxLocationKernel.cpp" in line and "Assuming pointer value is null" in line) or
138 ("CLMinMaxLocationKernel.cpp" in line and "Forming reference to null pointer" in line)):
139 print_context=False
140 continue
Anthony Barbier3dfbdeb2017-09-12 16:04:45 +0100141 elif print_context:
142 out.append(line)
143
144 return out
145
146if __name__ == "__main__":
147 if len(sys.argv) != 2:
148 print("usage: {} CLANG-TIDY_OUTPUT_FILE".format(sys.argv[0]))
149 sys.exit(1)
150
151 errors = []
152 with open(sys.argv[1], mode="r") as clang_tidy_file:
153 lines = clang_tidy_file.readlines()
154 errors = filter_clang_tidy_lines(lines)
155 print "\n".join(errors)
156
157 sys.exit(0 if len(errors) == 0 else 1)