diff --git a/.gitignore b/.gitignore index ccdef02b29..fe067824b2 100644 --- a/.gitignore +++ b/.gitignore @@ -33,6 +33,8 @@ libtool *~ *.log *.trs +compile_commands.commands.json +compile_commands.json src/libsecp256k1-config.h src/libsecp256k1-config.h.in src/ecmult_static_context.h diff --git a/.travis.yml b/.travis.yml index bcc8c210f5..c5befc4bfb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,6 +12,7 @@ addons: - libgmp-dev - valgrind - libtool-bin + - bear compiler: - clang - gcc @@ -47,6 +48,7 @@ matrix: - libgmp-dev:i386 - valgrind - libtool-bin + - bear - libc6-dbg:i386 - compiler: clang env: HOST=i686-linux-gnu @@ -57,6 +59,7 @@ matrix: - gcc-multilib - valgrind - libtool-bin + - bear - libc6-dbg:i386 - compiler: gcc env: HOST=i686-linux-gnu @@ -104,5 +107,6 @@ after_script: - cat ./exhaustive_tests.log - cat ./valgrind_ctime_test.log - cat ./bench.log + - cat ./compile_commands.json - $CC --version - valgrind --version diff --git a/clang-query.sh b/clang-query.sh new file mode 100755 index 0000000000..4ecc0cbcb9 --- /dev/null +++ b/clang-query.sh @@ -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 diff --git a/contrib/travis.sh b/contrib/travis.sh index 24cc9315cb..2ee6aa6c88 100755 --- a/contrib/travis.sh +++ b/contrib/travis.sh @@ -23,7 +23,14 @@ fi if [ -n "$BUILD" ] then - make -j2 "$BUILD" + if [ "$TRAVIS_COMPILER" = "clang" ] + then + # Use bear to generate compile_commands.json + # This needs to be the first make command because otherwise make does not invoke the compiler because the files are up to date. + # This needs to be a separate make command because bear does not seem to like our "make check". + bear -- make -j2 + fi + make -j2 "$BUILD" fi if [ "$RUN_VALGRIND" = "yes" ] then @@ -66,3 +73,9 @@ if [ "$CTIMETEST" = "yes" ] then ./libtool --mode=execute valgrind --error-exitcode=42 ./valgrind_ctime_test > valgrind_ctime_test.log 2>&1 fi + +# This would also run on gcc builds but there's no need to run it for both compilers. +if [ "$TRAVIS_COMPILER" = "clang" ] +then + ./clang-query.sh +fi