blob: d763a07079063d126f89bc87fb9da30adf5a3522 [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():
7 return "include . 3rdparty/include kernels computer_vision".split()
8
9def get_list_flags( filename, arch):
10 assert arch in ["armv7", "aarch64"]
11 flags = ["-std=c++11"]
12 if "tests/validation_old" in filename:
13 flags.append("-DBOOST")
14 flags.append("-DARM_COMPUTE_CPP_SCHEDULER=1")
15 if arch == "aarch64":
16 flags.append("-DARM_COMPUTE_CL")
17 flags.append("-DARM_COMPUTE_ENABLE_FP16")
18 return flags
19
20def filter_files( list_files ):
21 to_check = []
22 for f in list_files:
23 if os.path.splitext(f)[1] != ".cpp":
24 continue
25 if "computer_vision" in f:
26 continue
27 if "openvx-arm_compute" in f:
28 continue
29 if "tests/validation_old" in f:
30 continue
31 # Skip OMPScheduler as it causes problems in clang
32 if "OMPScheduler.cpp" in f:
33 continue
34 to_check.append(f)
35 return to_check
36
37def filter_clang_tidy_lines( lines ):
38 out = []
39 print_context=False
40 for i in range(0, len(lines)):
41 line = lines[i]
42
43 if "error:" in line:
44 if (("Utils.cpp" in line and "'arm_compute_version.embed' file not found" in line) or
45 ("cl2.hpp" in line and "cast from pointer to smaller type 'cl_context_properties' (aka 'int') loses information" in line) or
46 ("arm_fp16.h" in line) or
47 ("omp.h" in line) or
48 ("memory" in line and "cast from pointer to smaller type 'uintptr_t' (aka 'unsigned int') loses information" in line) or
49 ("NEMath.inl" in line and "statement expression not allowed at file scope" in line) or
50 "3rdparty" in line):
51 print_context=False
52 continue
53
54 out.append(line)
55 print_context=True
56 elif "warning:" in line:
57 if ("uninitialized record type: '__ret'" in line or
58 "local variable '__bound_functor' is still referred to by the global variable '__once_callable'" in line or
59 ("Error.cpp" in line and "thrown exception type is not nothrow copy constructible" in line) or
60 ("Error.cpp" in line and "uninitialized record type: 'args'" in line) or
61 ("Error.cpp" in line and "do not call c-style vararg functions" in line) or
62 ("Error.cpp" in line and "do not define a C-style variadic function" in line) or
63 ("NEMinMaxLocationKernel.cpp" in line and "move constructors should be marked noexcept" in line) or
64 ("NEMinMaxLocationKernel.cpp" in line and "move assignment operators should be marked noexcept" in line) or
65 ("PMUCounter.cpp" in line and "consider replacing 'long long' with 'int64'" in line) or
66 ("Validation.cpp" in line and "parameter 'classified_labels' is unused" in line) or
67 ("Validation.cpp" in line and "parameter 'expected_labels' is unused" in line) or
68 ("Reference.cpp" in line and "parameter 'rois' is unused" in line) or
69 ("Reference.cpp" in line and "parameter 'shapes' is unused" in line) or
70 ("Reference.cpp" in line and re.search(r"parameter '[^']+' is unused", line)) or
71 ("ReferenceCPP.cpp" in line and "parameter 'rois' is unused" in line) or
72 ("ReferenceCPP.cpp" in line and "parameter 'srcs' is unused" in line) or
73 ("ReferenceCPP.cpp" in line and re.search(r"parameter '[^']+' is unused", line)) or
74 ("NEGEMMMatrixMultiplyKernel.cpp" in line and "do not use C-style cast to convert between unrelated types" in line) or
75 ("NEPoolingLayerKernel.cpp" in line and "do not use C-style cast to convert between unrelated types" in line) or
76 ("NESoftmaxLayerKernel.cpp" in line and "do not use C-style cast to convert between unrelated types" in line) or
Georgios Pinitasbaf174e2017-09-08 19:47:30 +010077 ("parameter 'memory_manager' is unused" in line) or
Anthony Barbier3dfbdeb2017-09-12 16:04:45 +010078 "3rdparty" in line):
79 print_context=False
80 continue
81
82 if "do not use C-style cast to convert between unrelated types" in line:
83 if i + 1 < len(lines) and "vgetq_lane_f16" in lines[i + 1]:
84 print_context=False
85 continue
86
87 if "use 'using' instead of 'typedef'" in line:
88 if i + 1 < len(lines) and "BOOST_FIXTURE_TEST_SUITE" in lines[i + 1]:
89 print_context=False
90 continue
91
92 if "do not call c-style vararg functions" in line:
93 if (i + 1 < len(lines) and
94 ("BOOST_TEST" in lines[i + 1] or
95 "BOOST_FAIL" in lines[i + 1] or
96 "BOOST_CHECK_THROW" in lines[i + 1] or
97 "syscall" in lines[i + 1])):
98 print_context=False
99 continue
100
101 out.append(line)
102 print_context=True
103 elif print_context:
104 out.append(line)
105
106 return out
107
108if __name__ == "__main__":
109 if len(sys.argv) != 2:
110 print("usage: {} CLANG-TIDY_OUTPUT_FILE".format(sys.argv[0]))
111 sys.exit(1)
112
113 errors = []
114 with open(sys.argv[1], mode="r") as clang_tidy_file:
115 lines = clang_tidy_file.readlines()
116 errors = filter_clang_tidy_lines(lines)
117 print "\n".join(errors)
118
119 sys.exit(0 if len(errors) == 0 else 1)