-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add simple static checker using clang-query
- Loading branch information
1 parent
c6b6b8f
commit 931cc9b
Showing
4 changed files
with
55 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/bin/sh | ||
|
||
set -u | ||
|
||
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 | ||
) | ||
|
||
output=$(echo "$matcher" | clang-query src/*.c) | ||
status=$? | ||
if [ $status -ne 0 ] | ||
then | ||
exit $status | ||
fi | ||
echo "$output" | ||
# For some reason, clang-query returns a zero status even if clang failed to process the file. | ||
# This is not a big issue. If clang errors, we'll notice that when trying to compile with clang anyway. | ||
# We still try to catch this case by grepping also for "error:". | ||
echo "$output" | grep -qE "^Match #|error:" | ||
if [ $? -eq 0 ] | ||
then | ||
exit 1 | ||
fi | ||
|
||
echo | ||
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters