Skip to content

Commit

Permalink
Add simple static checker using clang-query
Browse files Browse the repository at this point in the history
  • Loading branch information
real-or-random committed Oct 15, 2020
1 parent c6b6b8f commit 3b05077
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
35 changes: 35 additions & 0 deletions clang-query.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/sh

set -eu

matcher=$(cat <<'EOF'
set print-matcher true
# expressions of any floating point type (unless in a system header)
match expr(allOf(unless(isExpansionInSystemHeader()), hasType(realFloatingPointType())))
# calls to memcmp (secp256k1_memcmp_var should be used instead)
match callExpr(callee(functionDecl(hasName("memcmp"))))
quit
EOF
)

check() {
local file=$1
shift
local extra=
for arg in $@
do
extra="$extra --extra-arg=$arg "
done
output=$(echo "$matcher" | clang-query --extra-arg="-DHAVE_CONFIG" --extra-arg="-DSECP256K1_BUILD" $extra "src/$file")

! echo "$output" | grep -C 9999999 -E "^Match"
echo
}

check secp256k1.c -DHAVE_CONFIG -DSECP256K1_BUILD
check tests.c -DHAVE_CONFIG -DSECP256K1_BUILD -DVERIFY
check tests_exhaustive.c -DHAVE_CONFIG -DSECP256K1_BUILD -DVERIFY
check valgrind_ctime_test.c -DVALGRIND
2 changes: 2 additions & 0 deletions contrib/travis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,5 @@ if [ "$CTIMETEST" = "yes" ]
then
./libtool --mode=execute valgrind --error-exitcode=42 ./valgrind_ctime_test > valgrind_ctime_test.log 2>&1
fi

./clang-query.sh

0 comments on commit 3b05077

Please sign in to comment.