Skip to content

Fix clang tidy #2347

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions .github/workflows/clang-tidy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,25 @@ 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

- 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
30 changes: 26 additions & 4 deletions run-clang-tidy.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/sh -x

if [ $# -ne 1 ] || [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
echo "$0 <build-path>"
Expand All @@ -7,24 +7,46 @@ 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
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
2 changes: 1 addition & 1 deletion suite/cstest/src/ppc_detail.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Loading