From 3dfbdebcb9072a02a6aae59f0700333bd0dc18ec Mon Sep 17 00:00:00 2001 From: Anthony Barbier Date: Tue, 12 Sep 2017 16:04:45 +0100 Subject: COMPMID-451 regroup clang-tidy scripts and port to python Change-Id: I8a87ec5a7ab29a908d6a3f07d7ebf5619355a57a Reviewed-on: http://mpd-gerrit.cambridge.arm.com/87407 Tested-by: Kaizen Reviewed-by: Moritz Pflanzer --- scripts/check_clang-tidy.py | 74 --------------------------- scripts/clang-tidy.sh | 93 ---------------------------------- scripts/clang_tidy_rules.py | 118 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 118 insertions(+), 167 deletions(-) delete mode 100755 scripts/check_clang-tidy.py delete mode 100755 scripts/clang-tidy.sh create mode 100755 scripts/clang_tidy_rules.py (limited to 'scripts') diff --git a/scripts/check_clang-tidy.py b/scripts/check_clang-tidy.py deleted file mode 100755 index e95204610b..0000000000 --- a/scripts/check_clang-tidy.py +++ /dev/null @@ -1,74 +0,0 @@ -#!/usr/bin/env python3 - -import re -import sys - -if __name__ == "__main__": - if len(sys.argv) != 2: - print("usage: {} CLANG-TIDY_OUTPUT_FILE".format(sys.argv[0])) - sys.exit(1) - - failed = False - - with open(sys.argv[1], mode="r") as clang_tidy_file: - lines = clang_tidy_file.readlines() - - for i in range(0, len(lines)): - line = lines[i] - - if "error:" in line: - if (("Utils.cpp" in line and "'arm_compute_version.embed' file not found" in line) or - ("cl2.hpp" in line and "cast from pointer to smaller type 'cl_context_properties' (aka 'int') loses information" in line) or - ("arm_fp16.h" in line) or - ("omp.h" in line) or - ("memory" in line and "cast from pointer to smaller type 'uintptr_t' (aka 'unsigned int') loses information" in line) or - ("NEMath.inl" in line and "statement expression not allowed at file scope" in line) or - "3rdparty" in line): - continue - - failed = True - print(line) - elif "warning:" in line: - if ("uninitialized record type: '__ret'" in line or - "local variable '__bound_functor' is still referred to by the global variable '__once_callable'" in line or - ("Error.cpp" in line and "thrown exception type is not nothrow copy constructible" in line) or - ("Error.cpp" in line and "uninitialized record type: 'args'" in line) or - ("Error.cpp" in line and "do not call c-style vararg functions" in line) or - ("Error.cpp" in line and "do not define a C-style variadic function" in line) or - ("NEMinMaxLocationKernel.cpp" in line and "move constructors should be marked noexcept" in line) or - ("NEMinMaxLocationKernel.cpp" in line and "move assignment operators should be marked noexcept" in line) or - ("PMUCounter.cpp" in line and "consider replacing 'long long' with 'int64'" in line) or - ("Validation.cpp" in line and "parameter 'classified_labels' is unused" in line) or - ("Validation.cpp" in line and "parameter 'expected_labels' is unused" in line) or - ("Reference.cpp" in line and "parameter 'rois' is unused" in line) or - ("Reference.cpp" in line and "parameter 'shapes' is unused" in line) or - ("Reference.cpp" in line and re.search(r"parameter '[^']+' is unused", line)) or - ("ReferenceCPP.cpp" in line and "parameter 'rois' is unused" in line) or - ("ReferenceCPP.cpp" in line and "parameter 'srcs' is unused" in line) or - ("ReferenceCPP.cpp" in line and re.search(r"parameter '[^']+' is unused", line)) or - ("NEGEMMMatrixMultiplyKernel.cpp" in line and "do not use C-style cast to convert between unrelated types" in line) or - ("NEPoolingLayerKernel.cpp" in line and "do not use C-style cast to convert between unrelated types" in line) or - ("NESoftmaxLayerKernel.cpp" in line and "do not use C-style cast to convert between unrelated types" in line) or - "3rdparty" in line): - continue - - if "do not use C-style cast to convert between unrelated types" in line: - if i + 1 < len(lines) and "vgetq_lane_f16" in lines[i + 1]: - continue - - if "use 'using' instead of 'typedef'" in line: - if i + 1 < len(lines) and "BOOST_FIXTURE_TEST_SUITE" in lines[i + 1]: - continue - - if "do not call c-style vararg functions" in line: - if (i + 1 < len(lines) and - ("BOOST_TEST" in lines[i + 1] or - "BOOST_FAIL" in lines[i + 1] or - "BOOST_CHECK_THROW" in lines[i + 1] or - "syscall" in lines[i + 1])): - continue - - failed = True - print(line) - - sys.exit(0 if not failed else 1) diff --git a/scripts/clang-tidy.sh b/scripts/clang-tidy.sh deleted file mode 100755 index b9ae0cfe60..0000000000 --- a/scripts/clang-tidy.sh +++ /dev/null @@ -1,93 +0,0 @@ -#!/usr/bin/env bash - -DIRECTORIES="./arm_compute ./src ./examples ./tests ./utils ./support" - -if [ $# -eq 0 ] -then - files=$(find $DIRECTORIES -type f -name \*.cpp | sort) -else - files=$@ -fi - -SCRIPT_PATH=$(dirname $0) - -CLANG_TIDY=$(which clang-tidy) - -if [[ -z $CLANG_TIDY ]]; then - echo "clang-tidy not found!" - exit 1 -else - echo "Found clang-tidy:" $CLANG_TIDY -fi - -CLANG_TIDY_PATH=$(dirname $CLANG_TIDY)/.. - -ARMV7_GCC=$(which arm-linux-gnueabihf-g++) - -if [[ -z $ARMV7_GCC ]]; then - echo "arm-linux-gnueabihf-g++ not found!" - exit 1 -else - echo "Found arm-linux-gnueabihf-g++:" $ARMV7_GCC -fi - -ARMV7_GCC_PATH=$(dirname $ARMV7_GCC)/.. - -AARCH64_GCC=$(which aarch64-linux-gnu-g++) - -if [[ -z $AARCH64_GCC ]]; then - echo "aarch64-linux-gnu-g++ not found!" - exit 1 -else - echo "Found aarch64-linux-gnu-g++:" $AARCH64_GCC -fi - -ARMV7_GCC_PATH=$(dirname $ARMV7_GCC)/.. -AARCH64_GCC_PATH=$(dirname $AARCH64_GCC)/.. - -INCLUDE_PATHS="-Iinclude -I. -I3rdparty/include -Ikernels -Icomputer_vision" - -function armv7 -{ - USE_BOOST="" - - if [[ "$1" == *tests/validation_old* ]] - then - USE_BOOST="-DBOOST" - fi - - $CLANG_TIDY \ - "$1" \ - -- \ - -target armv7a-none-linux-gnueabihf \ - --gcc-toolchain=$ARMV7_GCC_PATH \ - -std=c++11 \ - $INCLUDE_PATHS \ - -DARM_COMPUTE_CPP_SCHEDULER=1 $USE_BOOST - #read -rsp $'Press enter to continue...\n' -} - -function aarch64 -{ - USE_BOOST="" - - if [[ "$1" == *tests/validation_old* ]] - then - USE_BOOST="-DBOOST" - fi - - $CLANG_TIDY \ - "$1" \ - -- \ - -target aarch64-none-linux-gnueabi \ - --gcc-toolchain=$AARCH64_GCC_PATH \ - -std=c++11 \ - -include $SCRIPT_PATH/clang-tidy.h \ - $INCLUDE_PATHS \ - -DARM_COMPUTE_CL -DARM_COMPUTE_ENABLE_FP16 -DARM_COMPUTE_CPP_SCHEDULER=1 $USE_BOOST -} - -for f in $files; do - #armv7 "$f" - aarch64 "$f" -done diff --git a/scripts/clang_tidy_rules.py b/scripts/clang_tidy_rules.py new file mode 100755 index 0000000000..d4419df38f --- /dev/null +++ b/scripts/clang_tidy_rules.py @@ -0,0 +1,118 @@ +#!/usr/bin/env python +import os +import re +import sys + +def get_list_includes(): + return "include . 3rdparty/include kernels computer_vision".split() + +def get_list_flags( filename, arch): + assert arch in ["armv7", "aarch64"] + flags = ["-std=c++11"] + if "tests/validation_old" in filename: + flags.append("-DBOOST") + flags.append("-DARM_COMPUTE_CPP_SCHEDULER=1") + if arch == "aarch64": + flags.append("-DARM_COMPUTE_CL") + flags.append("-DARM_COMPUTE_ENABLE_FP16") + return flags + +def filter_files( list_files ): + to_check = [] + for f in list_files: + if os.path.splitext(f)[1] != ".cpp": + continue + if "computer_vision" in f: + continue + if "openvx-arm_compute" in f: + continue + if "tests/validation_old" in f: + continue + # Skip OMPScheduler as it causes problems in clang + if "OMPScheduler.cpp" in f: + continue + to_check.append(f) + return to_check + +def filter_clang_tidy_lines( lines ): + out = [] + print_context=False + for i in range(0, len(lines)): + line = lines[i] + + if "error:" in line: + if (("Utils.cpp" in line and "'arm_compute_version.embed' file not found" in line) or + ("cl2.hpp" in line and "cast from pointer to smaller type 'cl_context_properties' (aka 'int') loses information" in line) or + ("arm_fp16.h" in line) or + ("omp.h" in line) or + ("memory" in line and "cast from pointer to smaller type 'uintptr_t' (aka 'unsigned int') loses information" in line) or + ("NEMath.inl" in line and "statement expression not allowed at file scope" in line) or + "3rdparty" in line): + print_context=False + continue + + out.append(line) + print_context=True + elif "warning:" in line: + if ("uninitialized record type: '__ret'" in line or + "local variable '__bound_functor' is still referred to by the global variable '__once_callable'" in line or + ("Error.cpp" in line and "thrown exception type is not nothrow copy constructible" in line) or + ("Error.cpp" in line and "uninitialized record type: 'args'" in line) or + ("Error.cpp" in line and "do not call c-style vararg functions" in line) or + ("Error.cpp" in line and "do not define a C-style variadic function" in line) or + ("NEMinMaxLocationKernel.cpp" in line and "move constructors should be marked noexcept" in line) or + ("NEMinMaxLocationKernel.cpp" in line and "move assignment operators should be marked noexcept" in line) or + ("PMUCounter.cpp" in line and "consider replacing 'long long' with 'int64'" in line) or + ("Validation.cpp" in line and "parameter 'classified_labels' is unused" in line) or + ("Validation.cpp" in line and "parameter 'expected_labels' is unused" in line) or + ("Reference.cpp" in line and "parameter 'rois' is unused" in line) or + ("Reference.cpp" in line and "parameter 'shapes' is unused" in line) or + ("Reference.cpp" in line and re.search(r"parameter '[^']+' is unused", line)) or + ("ReferenceCPP.cpp" in line and "parameter 'rois' is unused" in line) or + ("ReferenceCPP.cpp" in line and "parameter 'srcs' is unused" in line) or + ("ReferenceCPP.cpp" in line and re.search(r"parameter '[^']+' is unused", line)) or + ("NEGEMMMatrixMultiplyKernel.cpp" in line and "do not use C-style cast to convert between unrelated types" in line) or + ("NEPoolingLayerKernel.cpp" in line and "do not use C-style cast to convert between unrelated types" in line) or + ("NESoftmaxLayerKernel.cpp" in line and "do not use C-style cast to convert between unrelated types" in line) or + "3rdparty" in line): + print_context=False + continue + + if "do not use C-style cast to convert between unrelated types" in line: + if i + 1 < len(lines) and "vgetq_lane_f16" in lines[i + 1]: + print_context=False + continue + + if "use 'using' instead of 'typedef'" in line: + if i + 1 < len(lines) and "BOOST_FIXTURE_TEST_SUITE" in lines[i + 1]: + print_context=False + continue + + if "do not call c-style vararg functions" in line: + if (i + 1 < len(lines) and + ("BOOST_TEST" in lines[i + 1] or + "BOOST_FAIL" in lines[i + 1] or + "BOOST_CHECK_THROW" in lines[i + 1] or + "syscall" in lines[i + 1])): + print_context=False + continue + + out.append(line) + print_context=True + elif print_context: + out.append(line) + + return out + +if __name__ == "__main__": + if len(sys.argv) != 2: + print("usage: {} CLANG-TIDY_OUTPUT_FILE".format(sys.argv[0])) + sys.exit(1) + + errors = [] + with open(sys.argv[1], mode="r") as clang_tidy_file: + lines = clang_tidy_file.readlines() + errors = filter_clang_tidy_lines(lines) + print "\n".join(errors) + + sys.exit(0 if len(errors) == 0 else 1) -- cgit v1.2.1