1 1.1 christos #!/usr/bin/env bash 2 1.1 christos set -euo pipefail 3 1.1 christos 4 1.1 christos git clean -Xfd 5 1.1 christos 6 1.1 christos export CC='clang' 7 1.1 christos export CXX='clang++' 8 1.1 christos compile_time_malloc_conf='background_thread:true,'\ 9 1.1 christos 'metadata_thp:auto,'\ 10 1.1 christos 'abort_conf:true,'\ 11 1.1 christos 'muzzy_decay_ms:0,'\ 12 1.1 christos 'zero_realloc:free,'\ 13 1.1 christos 'prof_unbias:false,'\ 14 1.1 christos 'prof_time_resolution:high' 15 1.1 christos extra_flags=( 16 1.1 christos -Wmissing-prototypes 17 1.1 christos -Wmissing-variable-declarations 18 1.1 christos -Wstrict-prototypes 19 1.1 christos -Wunreachable-code 20 1.1 christos -Wunreachable-code-aggressive 21 1.1 christos -Wunused-macros 22 1.1 christos ) 23 1.1 christos 24 1.1 christos EXTRA_CFLAGS="${extra_flags[*]}" EXTRA_CXXFLAGS="${extra_flags[*]}" ./autogen.sh \ 25 1.1 christos --with-private-namespace=jemalloc_ \ 26 1.1 christos --disable-cache-oblivious \ 27 1.1 christos --enable-prof \ 28 1.1 christos --enable-prof-libunwind \ 29 1.1 christos --with-malloc-conf="$compile_time_malloc_conf" \ 30 1.1 christos --enable-readlinkat \ 31 1.1 christos --enable-opt-safety-checks \ 32 1.1 christos --enable-uaf-detection \ 33 1.1 christos --enable-force-getenv \ 34 1.1 christos --enable-debug # Enabling debug for static analysis is important, 35 1.1 christos # otherwise you'll get tons of warnings for things 36 1.1 christos # that are already covered by `assert`s. 37 1.1 christos 38 1.1 christos bear -- make -s -j "$(nproc)" 39 1.1 christos # We end up with lots of duplicate entries in the compilation database, one for 40 1.1 christos # each output file type (e.g. .o, .d, .sym, etc.). There must be exactly one 41 1.1 christos # entry for each file in the compilation database in order for 42 1.1 christos # cross-translation-unit analysis to work, so we deduplicate the database here. 43 1.1 christos jq '[.[] | select(.output | test("/[^./]*\\.o$"))]' compile_commands.json > compile_commands.json.tmp 44 1.1 christos mv compile_commands.json.tmp compile_commands.json 45 1.1 christos 46 1.1 christos # CodeChecker has a bug where it freaks out if you supply the skipfile via process substitution, 47 1.1 christos # so we resort to manually creating a temporary file 48 1.1 christos skipfile=$(mktemp) 49 1.1 christos # The single-quotes are deliberate here, you want `$skipfile` to be evaluated upon exit 50 1.1 christos trap 'rm -f $skipfile' EXIT 51 1.1 christos echo '-**/stdlib.h' > "$skipfile" 52 1.1 christos CC_ANALYZERS_FROM_PATH=1 CodeChecker analyze compile_commands.json --jobs "$(nproc)" \ 53 1.1 christos --ctu --compile-uniqueing strict --output static_analysis_raw_results \ 54 1.1 christos --analyzers clangsa clang-tidy --skip "$skipfile" \ 55 1.1 christos --enable readability-inconsistent-declaration-parameter-name \ 56 1.1 christos --enable performance-no-int-to-ptr \ 57 1.1 christos --disable clang-diagnostic-reserved-macro-identifier 58 1.1 christos # `--enable` is additive, the vast majority of the checks we want are 59 1.1 christos # enabled by default. 60 1.1 christos 61 1.1 christos html_output_dir="${1:-static_analysis_results}" 62 1.1 christos result=${2:-/dev/null} 63 1.1 christos # We're echoing a value because we want to indicate whether or not any errors 64 1.1 christos # were found, but we always want the script to have a successful exit code so 65 1.1 christos # that we actually reach the step in the GitHub action where we upload the results. 66 1.1 christos if CodeChecker parse --export html --output "$html_output_dir" static_analysis_raw_results 67 1.1 christos then 68 1.1 christos echo "HAS_STATIC_ANALYSIS_RESULTS=0" >> "$result" 69 1.1 christos else 70 1.1 christos echo "HAS_STATIC_ANALYSIS_RESULTS=1" >> "$result" 71 1.1 christos fi 72