aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRot127 <45763064+Rot127@users.noreply.github.com>2024-05-01 04:04:27 +0000
committerGitHub <noreply@github.com>2024-05-01 12:04:27 +0800
commit8f9a337dfaad6bddec3fb8dc1cccae17a3736b93 (patch)
tree1d59279b577afd0aa74325cc108a29b24d2c6696
parentb91c7274812986f168b7e7b83617f0b6ba2aa981 (diff)
downloadcapstone-8f9a337dfaad6bddec3fb8dc1cccae17a3736b93.tar.gz
Fix clang tidy (#2347)
-rw-r--r--.github/workflows/clang-tidy.yml11
-rwxr-xr-xrun-clang-tidy.sh30
-rw-r--r--suite/cstest/src/ppc_detail.c2
3 files changed, 35 insertions, 8 deletions
diff --git a/.github/workflows/clang-tidy.yml b/.github/workflows/clang-tidy.yml
index 1a814cae..b06d802a 100644
--- a/.github/workflows/clang-tidy.yml
+++ b/.github/workflows/clang-tidy.yml
@@ -10,9 +10,11 @@ jobs:
analyze:
runs-on: ubuntu-latest
- name: Install clang-tidy
+ name: clang-tidy
steps:
- uses: actions/checkout@v3
+ with:
+ fetch-depth: 0
- name: Install clang-tidy
run: |
sudo apt install clang-tidy
@@ -20,10 +22,13 @@ jobs:
- name: Build
run: |
mkdir build && cd build
- cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DBUILD_SHARED_LIBS=1 ..
- sudo cmake --build . --config Release
+ CC=clang cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DBUILD_SHARED_LIBS=1 ..
+ CC=clang sudo cmake --build . --config Release
cd ..
- name: Check for warnings
+ env:
+ base_sha: ${{ github.event.pull_request.base.sha }}
+ head_sha: ${{ github.event.pull_request.head.sha }}
run: |
./run-clang-tidy.sh build
diff --git a/run-clang-tidy.sh b/run-clang-tidy.sh
index 4617884a..3abd4f46 100755
--- a/run-clang-tidy.sh
+++ b/run-clang-tidy.sh
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/sh -x
if [ $# -ne 1 ] || [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
echo "$0 <build-path>"
@@ -7,7 +7,11 @@ fi
BUILD_PATH="$1"
-clang-tidy $(find ./arch ./*.c -type f -iregex ".*\.[c]") -p "$BUILD_PATH" -checks=clang-analyzer-*,-clang-analyzer-cplusplus* | tee ct-warnings.txt
+clang-tidy $(find ./arch ./*.c -type f -iregex ".*\.[c]") -p "$BUILD_PATH" -checks=clang-analyzer-*,-clang-analyzer-cplusplus* > ct-warnings.txt
+if [ $? -ne 0 ]; then
+ echo "clang-tidy failed"
+ exit 1
+fi
tmp=$(mktemp)
grep ": warning" ct-warnings.txt | grep -oE "^[/a-zA-Z0-9]*\.[ch]" | sort | uniq > $tmp
@@ -15,16 +19,34 @@ top_level=$(git rev-parse --show-toplevel)
echo "\n\n###### REPORT\n\n"
-for modified in $(git diff --name-only origin/next); do
+changed_files=$(git diff --name-only $base_sha..$head_sha)
+if [ $? -ne 0 ]; then
+ echo "Failed to get changed files."
+ exit 1
+fi
+
+faulty_files=""
+for modified in $changed_files; do
+ files_changed=1
full_path="$top_level/$modified"
if grep -q "$full_path" $tmp; then
+ faulty_files="$faulty_files $modified"
echo "$full_path as warnings. Please fix them."
needs_fixes=1
fi
done
+if [ -z $files_changed ]; then
+ echo "No files changed."
+ exit 0
+fi
+
if [ -z $needs_fixes ]; then
- echo "All good"
+ echo "None of the changed files has clang-tidy warnings."
exit 0
fi
+
+echo -e "\n\nclang-tidy warnings for: $faulty_files\n"
+echo "Please fix them. Or, if completely unrelated, let us know."
+
exit 1
diff --git a/suite/cstest/src/ppc_detail.c b/suite/cstest/src/ppc_detail.c
index e215cef6..53660e50 100644
--- a/suite/cstest/src/ppc_detail.c
+++ b/suite/cstest/src/ppc_detail.c
@@ -78,7 +78,7 @@ char *get_detail_ppc(csh *handle, cs_mode mode, cs_insn *ins)
}
if (ppc->bc.pred_ctr != PPC_PRED_INVALID)
printf("\t\tpred CTR: %s\n", get_pred_name(ppc->bc.pred_ctr));
- if (ppc->bc.hint != PPC_BH_INVALID)
+ if (ppc->bc.hint != PPC_BR_NOT_GIVEN)
printf("\t\thint: %u\n", ppc->bc.hint);
}