Anthony Barbier | 3dfbdeb | 2017-09-12 16:04:45 +0100 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | import os |
| 3 | import re |
| 4 | import sys |
| 5 | |
| 6 | def get_list_includes(): |
Anthony Barbier | 72f4ae5 | 2018-11-07 17:33:54 +0000 | [diff] [blame] | 7 | return "include/linux include . 3rdparty/include kernels".split() |
Anthony Barbier | 3dfbdeb | 2017-09-12 16:04:45 +0100 | [diff] [blame] | 8 | |
| 9 | def get_list_flags( filename, arch): |
| 10 | assert arch in ["armv7", "aarch64"] |
| 11 | flags = ["-std=c++11"] |
Anthony Barbier | 3dfbdeb | 2017-09-12 16:04:45 +0100 | [diff] [blame] | 12 | flags.append("-DARM_COMPUTE_CPP_SCHEDULER=1") |
Georgios Pinitas | 30f0215 | 2017-09-27 11:20:48 +0100 | [diff] [blame] | 13 | flags.append("-DARM_COMPUTE_CL") |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 14 | flags.append("-DARM_COMPUTE_GC") |
Anthony Barbier | 3dfbdeb | 2017-09-12 16:04:45 +0100 | [diff] [blame] | 15 | if arch == "aarch64": |
Ioan-Cristian Szabo | 33fd07b | 2017-10-26 15:42:24 +0100 | [diff] [blame] | 16 | flags.append("-DARM_COMPUTE_AARCH64_V8_2") |
Anthony Barbier | 3dfbdeb | 2017-09-12 16:04:45 +0100 | [diff] [blame] | 17 | return flags |
| 18 | |
| 19 | def filter_files( list_files ): |
| 20 | to_check = [] |
| 21 | for f in list_files: |
| 22 | if os.path.splitext(f)[1] != ".cpp": |
| 23 | continue |
Anthony Barbier | 3dfbdeb | 2017-09-12 16:04:45 +0100 | [diff] [blame] | 24 | # 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 | |
| 30 | def 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 Pflanzer | beabe3b | 2017-08-31 14:56:32 +0100 | [diff] [blame] | 36 | if "/assembly/" in line: |
| 37 | continue |
| 38 | |
Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 39 | if "/arm_gemm/" in line: |
| 40 | continue |
| 41 | |
Georgios Pinitas | 4074c99 | 2018-01-30 18:13:46 +0000 | [diff] [blame] | 42 | if "/convolution/" in line: |
Pablo Tello | 8951933 | 2017-11-17 11:52:36 +0000 | [diff] [blame] | 43 | continue |
| 44 | |
Anthony Barbier | 3dfbdeb | 2017-09-12 16:04:45 +0100 | [diff] [blame] | 45 | if "error:" in line: |
| 46 | if (("Utils.cpp" in line and "'arm_compute_version.embed' file not found" in line) or |
Anthony Barbier | 3dfbdeb | 2017-09-12 16:04:45 +0100 | [diff] [blame] | 47 | ("arm_fp16.h" in line) or |
| 48 | ("omp.h" in line) or |
Moritz Pflanzer | beabe3b | 2017-08-31 14:56:32 +0100 | [diff] [blame] | 49 | ("cast from pointer to smaller type 'uintptr_t' (aka 'unsigned int') loses information" in line) or |
Anthony Barbier | b6eb353 | 2018-08-08 13:20:04 +0100 | [diff] [blame] | 50 | ("cast from pointer to smaller type 'cl_context_properties' (aka 'int') loses information" in line) or |
Moritz Pflanzer | beabe3b | 2017-08-31 14:56:32 +0100 | [diff] [blame] | 51 | ("cast from pointer to smaller type 'std::uintptr_t' (aka 'unsigned int') loses information" in line) or |
Anthony Barbier | 3dfbdeb | 2017-09-12 16:04:45 +0100 | [diff] [blame] | 52 | ("NEMath.inl" in line and "statement expression not allowed at file scope" in line) or |
Anthony Barbier | 2a07e18 | 2017-08-04 18:20:27 +0100 | [diff] [blame] | 53 | ("Utils.h" in line and "no member named 'unmap' in 'arm_compute::Tensor'" in line) or |
| 54 | ("Utils.h" in line and "no member named 'map' in 'arm_compute::Tensor'" in line) or |
Pablo Tello | 7fad9b1 | 2018-03-14 17:55:27 +0000 | [diff] [blame] | 55 | ("CPUUtils.cpp" in line and "'asm/hwcap.h' file not found" in line) or |
Anthony Barbier | 3dfbdeb | 2017-09-12 16:04:45 +0100 | [diff] [blame] | 56 | "3rdparty" in line): |
| 57 | print_context=False |
| 58 | continue |
| 59 | |
| 60 | out.append(line) |
| 61 | print_context=True |
| 62 | elif "warning:" in line: |
| 63 | if ("uninitialized record type: '__ret'" in line or |
| 64 | "local variable '__bound_functor' is still referred to by the global variable '__once_callable'" in line or |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 65 | (any(f in line for f in ["Error.cpp","Error.h"]) and "thrown exception type is not nothrow copy constructible" in line) or |
| 66 | (any(f in line for f in ["Error.cpp","Error.h"]) and "uninitialized record type: 'args'" in line) or |
| 67 | (any(f in line for f in ["Error.cpp","Error.h"]) and "do not call c-style vararg functions" in line) or |
| 68 | (any(f in line for f in ["Error.cpp","Error.h"]) and "do not define a C-style variadic function" in line) or |
Georgios Pinitas | 84b51ad | 2017-11-07 13:24:57 +0000 | [diff] [blame] | 69 | ("TensorAllocator.cpp" in line and "warning: pointer parameter 'ptr' can be pointer to const" in line) or |
Anthony Barbier | 3dfbdeb | 2017-09-12 16:04:45 +0100 | [diff] [blame] | 70 | ("NEMinMaxLocationKernel.cpp" in line and "move constructors should be marked noexcept" in line) or |
| 71 | ("NEMinMaxLocationKernel.cpp" in line and "move assignment operators should be marked noexcept" in line) or |
Georgios Pinitas | 30f0215 | 2017-09-27 11:20:48 +0100 | [diff] [blame] | 72 | ("CLMinMaxLocationKernel.cpp" in line and "Forming reference to null pointer" in line) or |
Anthony Barbier | 3dfbdeb | 2017-09-12 16:04:45 +0100 | [diff] [blame] | 73 | ("PMUCounter.cpp" in line and "consider replacing 'long long' with 'int64'" in line) or |
| 74 | ("Validation.cpp" in line and "parameter 'classified_labels' is unused" in line) or |
| 75 | ("Validation.cpp" in line and "parameter 'expected_labels' is unused" in line) or |
| 76 | ("Reference.cpp" in line and "parameter 'rois' is unused" in line) or |
| 77 | ("Reference.cpp" in line and "parameter 'shapes' is unused" in line) or |
| 78 | ("Reference.cpp" in line and re.search(r"parameter '[^']+' is unused", line)) or |
| 79 | ("ReferenceCPP.cpp" in line and "parameter 'rois' is unused" in line) or |
| 80 | ("ReferenceCPP.cpp" in line and "parameter 'srcs' is unused" in line) or |
| 81 | ("ReferenceCPP.cpp" in line and re.search(r"parameter '[^']+' is unused", line)) or |
| 82 | ("NEGEMMMatrixMultiplyKernel.cpp" in line and "do not use C-style cast to convert between unrelated types" in line) or |
| 83 | ("NEPoolingLayerKernel.cpp" in line and "do not use C-style cast to convert between unrelated types" in line) or |
Diego Lopez Recas | 35ceeb2 | 2017-12-04 18:56:10 +0000 | [diff] [blame] | 84 | ("NESoftmaxLayerKernel.cpp" in line and "macro argument should be enclosed in parentheses" in line) or |
Georgios Pinitas | 30f0215 | 2017-09-27 11:20:48 +0100 | [diff] [blame] | 85 | ("GraphUtils.cpp" in line and "consider replacing 'unsigned long' with 'uint32'" in line) or |
Anthony Barbier | 2a07e18 | 2017-08-04 18:20:27 +0100 | [diff] [blame] | 86 | ("GraphUtils.cpp" in line and "consider replacing 'unsigned long' with 'uint64'" in line) or |
Georgios Pinitas | 6f669f0 | 2017-09-26 12:32:57 +0100 | [diff] [blame] | 87 | ("ConvolutionLayer.cpp" in line and "move assignment operators should be marked noexcept" in line) or |
| 88 | ("ConvolutionLayer.cpp" in line and "move constructors should be marked noexcept" in line) or |
Georgios Pinitas | baf174e | 2017-09-08 19:47:30 +0100 | [diff] [blame] | 89 | ("parameter 'memory_manager' is unused" in line) or |
Georgios Pinitas | 658039b | 2017-09-15 16:30:50 +0100 | [diff] [blame] | 90 | ("parameter 'memory_manager' is copied for each invocation but only used as a const reference" in line) or |
Pablo Tello | daaa1fa | 2017-10-25 11:40:50 +0100 | [diff] [blame] | 91 | ("DeconvolutionLayer.cpp" in line and "casting (double + 0.5) to integer leads to incorrect rounding; consider using lround" in line) or |
Pablo Tello | 3d4968a | 2017-12-04 15:03:35 +0000 | [diff] [blame] | 92 | ("NEWinogradLayerKernel.cpp" in line and "use '= default' to define a trivial destructor" in line) or |
Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 93 | ("NEGEMMLowpMatrixMultiplyCore.cpp" in line and "constructor does not initialize these fields" in line) or |
| 94 | ("NEGEMMLowpAssemblyMatrixMultiplyCore" in line and "constructor does not initialize these fields" in line) or |
Pablo Tello | 7fad9b1 | 2018-03-14 17:55:27 +0000 | [diff] [blame] | 95 | ("CPUUtils.cpp" in line and "consider replacing 'unsigned long' with 'uint64'" in line) or |
| 96 | ("CPUUtils.cpp" in line and "parameter 'cpusv' is unused" in line) or |
Anthony Barbier | 3dfbdeb | 2017-09-12 16:04:45 +0100 | [diff] [blame] | 97 | "3rdparty" in line): |
| 98 | print_context=False |
| 99 | continue |
| 100 | |
| 101 | if "do not use C-style cast to convert between unrelated types" in line: |
| 102 | if i + 1 < len(lines) and "vgetq_lane_f16" in lines[i + 1]: |
| 103 | print_context=False |
| 104 | continue |
| 105 | |
| 106 | if "use 'using' instead of 'typedef'" in line: |
| 107 | if i + 1 < len(lines) and "BOOST_FIXTURE_TEST_SUITE" in lines[i + 1]: |
| 108 | print_context=False |
| 109 | continue |
| 110 | |
| 111 | if "do not call c-style vararg functions" in line: |
| 112 | if (i + 1 < len(lines) and |
| 113 | ("BOOST_TEST" in lines[i + 1] or |
| 114 | "BOOST_FAIL" in lines[i + 1] or |
| 115 | "BOOST_CHECK_THROW" in lines[i + 1] or |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 116 | "ARM_COMPUTE_RETURN_ON" in lines[i + 1] or |
Anthony Barbier | 3dfbdeb | 2017-09-12 16:04:45 +0100 | [diff] [blame] | 117 | "syscall" in lines[i + 1])): |
| 118 | print_context=False |
| 119 | continue |
| 120 | |
| 121 | out.append(line) |
| 122 | print_context=True |
Georgios Pinitas | 30f0215 | 2017-09-27 11:20:48 +0100 | [diff] [blame] | 123 | elif (("CLMinMaxLocationKernel.cpp" in line and "'?' condition is false" in line) or |
| 124 | ("CLMinMaxLocationKernel.cpp" in line and "Assuming the condition is false" in line) or |
| 125 | ("CLMinMaxLocationKernel.cpp" in line and "Assuming pointer value is null" in line) or |
| 126 | ("CLMinMaxLocationKernel.cpp" in line and "Forming reference to null pointer" in line)): |
| 127 | print_context=False |
| 128 | continue |
Anthony Barbier | 3dfbdeb | 2017-09-12 16:04:45 +0100 | [diff] [blame] | 129 | elif print_context: |
| 130 | out.append(line) |
| 131 | |
| 132 | return out |
| 133 | |
| 134 | if __name__ == "__main__": |
| 135 | if len(sys.argv) != 2: |
| 136 | print("usage: {} CLANG-TIDY_OUTPUT_FILE".format(sys.argv[0])) |
| 137 | sys.exit(1) |
| 138 | |
| 139 | errors = [] |
| 140 | with open(sys.argv[1], mode="r") as clang_tidy_file: |
| 141 | lines = clang_tidy_file.readlines() |
| 142 | errors = filter_clang_tidy_lines(lines) |
| 143 | print "\n".join(errors) |
| 144 | |
| 145 | sys.exit(0 if len(errors) == 0 else 1) |