Michalis Spyrou | 92ad0ca | 2019-12-17 11:43:32 +0000 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Anthony Barbier | 3dfbdeb | 2017-09-12 16:04:45 +0100 | [diff] [blame] | 2 | import os |
| 3 | import re |
| 4 | import sys |
| 5 | |
| 6 | def get_list_includes(): |
Sang-Hoon Park | 431889a | 2021-05-18 22:52:04 +0100 | [diff] [blame] | 7 | return "src/core/cpu/kernels/assembly " \ |
Michele Di Giorgio | 6ad60af | 2020-06-09 14:52:15 +0100 | [diff] [blame] | 8 | "src/core/NEON/kernels/assembly " \ |
| 9 | "src/core/NEON/kernels/convolution/winograd " \ |
Georgios Pinitas | 51826a4 | 2019-08-02 18:01:21 +0100 | [diff] [blame] | 10 | "include/linux include " \ |
Michele Di Giorgio | 72610dc | 2020-11-18 15:29:08 +0000 | [diff] [blame] | 11 | ". ".split() |
Anthony Barbier | 3dfbdeb | 2017-09-12 16:04:45 +0100 | [diff] [blame] | 12 | |
| 13 | def get_list_flags( filename, arch): |
| 14 | assert arch in ["armv7", "aarch64"] |
Georgios Pinitas | 40f51a6 | 2020-11-21 03:04:18 +0000 | [diff] [blame] | 15 | flags = ["-std=c++14"] |
Anthony Barbier | 3dfbdeb | 2017-09-12 16:04:45 +0100 | [diff] [blame] | 16 | flags.append("-DARM_COMPUTE_CPP_SCHEDULER=1") |
Georgios Pinitas | 30f0215 | 2017-09-27 11:20:48 +0100 | [diff] [blame] | 17 | flags.append("-DARM_COMPUTE_CL") |
Anthony Barbier | 3dfbdeb | 2017-09-12 16:04:45 +0100 | [diff] [blame] | 18 | if arch == "aarch64": |
Ioan-Cristian Szabo | 33fd07b | 2017-10-26 15:42:24 +0100 | [diff] [blame] | 19 | flags.append("-DARM_COMPUTE_AARCH64_V8_2") |
Anthony Barbier | 3dfbdeb | 2017-09-12 16:04:45 +0100 | [diff] [blame] | 20 | return flags |
| 21 | |
| 22 | def filter_files( list_files ): |
| 23 | to_check = [] |
| 24 | for f in list_files: |
| 25 | if os.path.splitext(f)[1] != ".cpp": |
| 26 | continue |
Anthony Barbier | 3dfbdeb | 2017-09-12 16:04:45 +0100 | [diff] [blame] | 27 | # Skip OMPScheduler as it causes problems in clang |
Anthony Barbier | b467021 | 2018-05-18 16:55:39 +0100 | [diff] [blame] | 28 | if (("OMPScheduler.cpp" in f) or |
| 29 | ("CLTracePoint.cpp" in f) or |
| 30 | ("NETracePoint.cpp" in f) or |
| 31 | ("TracePoint.cpp" in f)): |
Anthony Barbier | 3dfbdeb | 2017-09-12 16:04:45 +0100 | [diff] [blame] | 32 | continue |
| 33 | to_check.append(f) |
| 34 | return to_check |
| 35 | |
| 36 | def 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 Giorgio | d556d7b | 2020-10-27 10:56:31 +0000 | [diff] [blame] | 42 | if "/arm_conv/" in line: |
| 43 | continue |
| 44 | |
Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 45 | if "/arm_gemm/" in line: |
| 46 | continue |
| 47 | |
Georgios Pinitas | 4074c99 | 2018-01-30 18:13:46 +0000 | [diff] [blame] | 48 | if "/convolution/" in line: |
Pablo Tello | 8951933 | 2017-11-17 11:52:36 +0000 | [diff] [blame] | 49 | continue |
| 50 | |
Michalis Spyrou | bcfd09a | 2019-05-01 13:03:59 +0100 | [diff] [blame] | 51 | if "/validate_examples/" in line: |
| 52 | continue |
| 53 | |
Anthony Barbier | 3dfbdeb | 2017-09-12 16:04:45 +0100 | [diff] [blame] | 54 | if "error:" in line: |
Georgios Pinitas | 51545e4 | 2020-02-11 15:29:01 +0000 | [diff] [blame] | 55 | if (("Version.cpp" in line and "arm_compute_version.embed" in line and "file not found" in line) or |
Anthony Barbier | 3dfbdeb | 2017-09-12 16:04:45 +0100 | [diff] [blame] | 56 | ("arm_fp16.h" in line) or |
| 57 | ("omp.h" in line) or |
Moritz Pflanzer | beabe3b | 2017-08-31 14:56:32 +0100 | [diff] [blame] | 58 | ("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] | 59 | ("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] | 60 | ("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] | 61 | ("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] | 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 |
Pablo Tello | 7fad9b1 | 2018-03-14 17:55:27 +0000 | [diff] [blame] | 64 | ("CPUUtils.cpp" in line and "'asm/hwcap.h' file not found" in line) or |
Pablo Marquez Tello | a50f193 | 2021-03-08 17:27:05 +0000 | [diff] [blame] | 65 | ("CPUUtils.cpp" in line and "use of undeclared identifier 'HWCAP_SVE'" in line) or |
Manuel Bottini | 569b7e9 | 2020-03-20 14:37:40 +0000 | [diff] [blame] | 66 | ("'arm_compute_version.embed' file not found" in line) ): |
Anthony Barbier | 3dfbdeb | 2017-09-12 16:04:45 +0100 | [diff] [blame] | 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 |
Michalis Spyrou | 2388de1 | 2019-05-13 15:51:05 +0100 | [diff] [blame] | 75 | "assigning newly created 'gsl::owner<>'" in line or |
Georgios Pinitas | b8d5b95 | 2019-05-16 14:13:03 +0100 | [diff] [blame] | 76 | "calling legacy resource function without passing a 'gsl::owner<>'" in line or |
Michalis Spyrou | 2388de1 | 2019-05-13 15:51:05 +0100 | [diff] [blame] | 77 | "deleting a pointer through a type that is not marked 'gsl::owner<>'" in line or |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 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 |
Georgios Pinitas | 84b51ad | 2017-11-07 13:24:57 +0000 | [diff] [blame] | 82 | ("TensorAllocator.cpp" in line and "warning: pointer parameter 'ptr' can be pointer to const" in line) or |
Michalis Spyrou | bcfd09a | 2019-05-01 13:03:59 +0100 | [diff] [blame] | 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 |
Michalis Spyrou | 7dbfc41 | 2019-05-13 13:21:28 +0100 | [diff] [blame] | 85 | ("RawTensor.cpp" in line and "warning: do not declare C-style arrays" in line) or |
Anthony Barbier | 3dfbdeb | 2017-09-12 16:04:45 +0100 | [diff] [blame] | 86 | ("NEMinMaxLocationKernel.cpp" in line and "move constructors should be marked noexcept" in line) or |
| 87 | ("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] | 88 | ("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] | 89 | ("PMUCounter.cpp" in line and "consider replacing 'long long' with 'int64'" in line) or |
| 90 | ("Validation.cpp" in line and "parameter 'classified_labels' is unused" in line) or |
| 91 | ("Validation.cpp" in line and "parameter 'expected_labels' is unused" in line) or |
| 92 | ("Reference.cpp" in line and "parameter 'rois' is unused" in line) or |
| 93 | ("Reference.cpp" in line and "parameter 'shapes' is unused" in line) or |
| 94 | ("Reference.cpp" in line and re.search(r"parameter '[^']+' is unused", line)) or |
| 95 | ("ReferenceCPP.cpp" in line and "parameter 'rois' is unused" in line) or |
| 96 | ("ReferenceCPP.cpp" in line and "parameter 'srcs' is unused" in line) or |
| 97 | ("ReferenceCPP.cpp" in line and re.search(r"parameter '[^']+' is unused", line)) or |
| 98 | ("NEGEMMMatrixMultiplyKernel.cpp" in line and "do not use C-style cast to convert between unrelated types" in line) or |
| 99 | ("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] | 100 | ("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] | 101 | ("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] | 102 | ("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] | 103 | ("ConvolutionLayer.cpp" in line and "move assignment operators should be marked noexcept" in line) or |
| 104 | ("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] | 105 | ("parameter 'memory_manager' is unused" in line) or |
Georgios Pinitas | 658039b | 2017-09-15 16:30:50 +0100 | [diff] [blame] | 106 | ("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] | 107 | ("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] | 108 | ("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] | 109 | ("NEGEMMLowpMatrixMultiplyCore.cpp" in line and "constructor does not initialize these fields" in line) or |
| 110 | ("NEGEMMLowpAssemblyMatrixMultiplyCore" in line and "constructor does not initialize these fields" in line) or |
Michalis Spyrou | 60c3b0e | 2021-04-08 12:02:58 +0100 | [diff] [blame] | 111 | ("CpuDepthwiseConvolutionNativeKernel" in line and re.search(r"parameter '[^']+' is unused", line)) or |
| 112 | ("CpuDepthwiseConvolutionAssemblyDispatch" in line and re.search(r"parameter '[^']+' is unused", line)) or |
| 113 | ("CpuDepthwiseConvolutionAssemblyDispatch" in line and "modernize-use-equals-default" in line) or |
Pablo Tello | 7fad9b1 | 2018-03-14 17:55:27 +0000 | [diff] [blame] | 114 | ("CPUUtils.cpp" in line and "consider replacing 'unsigned long' with 'uint64'" in line) or |
| 115 | ("CPUUtils.cpp" in line and "parameter 'cpusv' is unused" in line) or |
Michalis Spyrou | 8e5174c | 2018-12-04 11:43:23 +0000 | [diff] [blame] | 116 | ("CPUUtils.cpp" in line and "warning: uninitialized record type" in line) or |
Michalis Spyrou | bcfd09a | 2019-05-01 13:03:59 +0100 | [diff] [blame] | 117 | ("Utils.h" in line and "warning: Use of zero-allocated memory" in line) or |
Michalis Spyrou | 60c3b0e | 2021-04-08 12:02:58 +0100 | [diff] [blame] | 118 | ("CpuDepthwiseConvolutionNativeKernel.cpp" in line and "misc-non-private-member-variables-in-classes" in line) or # This is to prevent false positive, should be reassessed with the newer clang-tidy |
| 119 | ("CpuDepthwiseConvolutionNativeKernel.cpp" in line and "cppcoreguidelines-pro-type-member-init" in line)): # This is to prevent false positive, should be reassessed with the newer clang-tidy |
Anthony Barbier | 3dfbdeb | 2017-09-12 16:04:45 +0100 | [diff] [blame] | 120 | print_context=False |
| 121 | continue |
| 122 | |
| 123 | if "do not use C-style cast to convert between unrelated types" in line: |
| 124 | if i + 1 < len(lines) and "vgetq_lane_f16" in lines[i + 1]: |
| 125 | print_context=False |
| 126 | continue |
| 127 | |
| 128 | if "use 'using' instead of 'typedef'" in line: |
| 129 | if i + 1 < len(lines) and "BOOST_FIXTURE_TEST_SUITE" in lines[i + 1]: |
| 130 | print_context=False |
| 131 | continue |
| 132 | |
| 133 | if "do not call c-style vararg functions" in line: |
| 134 | if (i + 1 < len(lines) and |
| 135 | ("BOOST_TEST" in lines[i + 1] or |
| 136 | "BOOST_FAIL" in lines[i + 1] or |
| 137 | "BOOST_CHECK_THROW" in lines[i + 1] or |
Michalis Spyrou | 7c60c99 | 2019-10-10 14:33:47 +0100 | [diff] [blame] | 138 | "ARM_COMPUTE_ERROR_VAR" in lines[i + 1] or |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 139 | "ARM_COMPUTE_RETURN_ON" in lines[i + 1] or |
Anthony Barbier | 3dfbdeb | 2017-09-12 16:04:45 +0100 | [diff] [blame] | 140 | "syscall" in lines[i + 1])): |
| 141 | print_context=False |
| 142 | continue |
| 143 | |
| 144 | out.append(line) |
| 145 | print_context=True |
Georgios Pinitas | 30f0215 | 2017-09-27 11:20:48 +0100 | [diff] [blame] | 146 | elif (("CLMinMaxLocationKernel.cpp" in line and "'?' condition is false" in line) or |
| 147 | ("CLMinMaxLocationKernel.cpp" in line and "Assuming the condition is false" in line) or |
| 148 | ("CLMinMaxLocationKernel.cpp" in line and "Assuming pointer value is null" in line) or |
| 149 | ("CLMinMaxLocationKernel.cpp" in line and "Forming reference to null pointer" in line)): |
| 150 | print_context=False |
| 151 | continue |
Anthony Barbier | 3dfbdeb | 2017-09-12 16:04:45 +0100 | [diff] [blame] | 152 | elif print_context: |
| 153 | out.append(line) |
| 154 | |
| 155 | return out |
| 156 | |
| 157 | if __name__ == "__main__": |
| 158 | if len(sys.argv) != 2: |
| 159 | print("usage: {} CLANG-TIDY_OUTPUT_FILE".format(sys.argv[0])) |
| 160 | sys.exit(1) |
| 161 | |
| 162 | errors = [] |
| 163 | with open(sys.argv[1], mode="r") as clang_tidy_file: |
| 164 | lines = clang_tidy_file.readlines() |
| 165 | errors = filter_clang_tidy_lines(lines) |
Michalis Spyrou | 92ad0ca | 2019-12-17 11:43:32 +0000 | [diff] [blame] | 166 | print("\n".join(errors)) |
Anthony Barbier | 3dfbdeb | 2017-09-12 16:04:45 +0100 | [diff] [blame] | 167 | |
| 168 | sys.exit(0 if len(errors) == 0 else 1) |