Skip to content

Commit d23222c

Browse files
committed
chore: Run static analysers in multiple variants.
Currently: 1) libsodium and 2) nacl. Note that the "nacl" variant is actually libsodium. We just want to make sure the static analysers see the `VANILLA_NACL` code paths.
1 parent dfa7a01 commit d23222c

File tree

15 files changed

+221
-159
lines changed

15 files changed

+221
-159
lines changed

.circleci/config.yml

Lines changed: 28 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ workflows:
1010
- tsan
1111
- msan
1212
# Static analysis
13+
- clang-analyze
1314
- clang-tidy
1415
- infer
1516
- static-analysis
@@ -21,21 +22,21 @@ jobs:
2122
- image: ubuntu
2223

2324
steps:
24-
- checkout
2525
- run: &apt_install
2626
apt-get update &&
2727
DEBIAN_FRONTEND=noninteractive
2828
apt-get install -y --no-install-recommends
2929
clang
3030
cmake
31+
git
3132
libconfig-dev
3233
libgtest-dev
3334
libopus-dev
3435
libsodium-dev
3536
libvpx-dev
36-
llvm-dev
3737
ninja-build
3838
pkg-config
39+
- checkout
3940
- run: CC=clang .circleci/cmake-asan
4041

4142
tsan:
@@ -44,8 +45,8 @@ jobs:
4445
- image: ubuntu
4546

4647
steps:
47-
- checkout
4848
- run: *apt_install
49+
- checkout
4950
- run: CC=clang .circleci/cmake-tsan
5051

5152
msan:
@@ -65,64 +66,52 @@ jobs:
6566
- image: toxchat/infer
6667

6768
steps:
68-
- run:
69-
apt-get update &&
70-
DEBIAN_FRONTEND=noninteractive
71-
apt-get install -y --no-install-recommends
72-
git
73-
libopus-dev
74-
libsodium-dev
75-
libvpx-dev
76-
pkg-config
69+
- run: *apt_install
7770
- checkout
78-
- run: infer --no-progress-bar -- cc toxav/*.c toxcore/*.c $(pkg-config --cflags opus vpx)
71+
- run: infer --no-progress-bar -- cc
72+
auto_tests/lossless_packet_test.c
73+
testing/misc_tools.c
74+
toxav/*.c
75+
toxcore/*.c
76+
toxencryptsave/*.c
77+
-lpthread
78+
$(pkg-config --cflags --libs libsodium opus vpx)
7979

8080
static-analysis:
8181
working_directory: ~/work
8282
docker:
8383
- image: ubuntu
8484

8585
steps:
86+
- run: *apt_install
87+
- run: apt-get install -y --no-install-recommends cppcheck g++ llvm-dev
8688
- checkout
87-
- run:
88-
apt-get update &&
89-
DEBIAN_FRONTEND=noninteractive
90-
apt-get install -y --no-install-recommends
91-
clang
92-
cppcheck
93-
g++
94-
libconfig-dev
95-
libgtest-dev
96-
libopus-dev
97-
libsodium-dev
98-
libvpx-dev
99-
llvm
10089
- run: other/analysis/check_logger_levels
10190
- run: other/analysis/run-check-recursion
10291
- run: other/analysis/run-clang
103-
- run: other/analysis/run-clang-analyze
10492
- run: other/analysis/run-cppcheck
10593
- run: other/analysis/run-gcc
10694

95+
clang-analyze:
96+
working_directory: ~/work
97+
docker:
98+
- image: ubuntu
99+
100+
steps:
101+
- run: *apt_install
102+
- checkout
103+
- run: other/analysis/run-clang-analyze
104+
107105
clang-tidy:
108106
working_directory: ~/work
109107
docker:
110108
- image: ubuntu
111109

112110
steps:
111+
- run: *apt_install
112+
- run: apt-get install -y --no-install-recommends clang-tidy-12
113113
- checkout
114-
- run:
115-
apt-get update &&
116-
DEBIAN_FRONTEND=noninteractive
117-
apt-get install -y --no-install-recommends
118-
build-essential
119-
clang-tidy-11
120-
cmake
121-
libconfig-dev
122-
libopus-dev
123-
libsodium-dev
124-
libvpx-dev
125-
- run: cmake . -B_build -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
114+
- run: cmake . -B_build -GNinja -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
126115
- run:
127116
other/analysis/run-clang-tidy ||
128117
other/analysis/run-clang-tidy ||

.cirrus.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ bazel-asan_task:
5050
//c-toxcore/...
5151
-//c-toxcore/auto_tests:tcp_relay_test # TODO(robinlinden): Why does this pass locally but not in Cirrus?
5252

53+
# TODO(iphydf): Remove "|| true" once this works properly.
5354
bazel-msan_task:
5455
container:
5556
image: toxchat/toktok-stack:0.0.31-msan

.github/settings.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ branches:
1414
contexts:
1515
- "bazel-asan"
1616
- "bazel-debug"
17+
- "bazel-msan"
1718
- "bazel-release"
1819
- "bazel-tsan"
1920
- "build-bootstrapd-docker"
@@ -26,6 +27,7 @@ branches:
2627
- "CodeFactor"
2728
- "coverage-linux"
2829
- "ci/circleci: asan"
30+
- "ci/circleci: clang-analyze"
2931
- "ci/circleci: clang-tidy"
3032
- "ci/circleci: infer"
3133
- "ci/circleci: static-analysis"

.restyled.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
---
22
exclude:
33
- "**/*.api.h"
4+
# shfmt doesn't support this file
5+
- "other/analysis/run-clang-tidy"
46

57
restylers:
68
- astyle:

auto_tests/encryptsave_test.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,8 @@
33
#include <string.h>
44
#include <sys/types.h>
55

6-
#ifdef VANILLA_NACL
7-
#include "../toxencryptsave/crypto_pwhash_scryptsalsa208sha256/crypto_pwhash_scryptsalsa208sha256.h"
8-
#else
6+
#ifndef VANILLA_NACL
97
#include <sodium.h>
10-
#endif
118

129
#include "../testing/misc_tools.h"
1310
#include "../toxcore/ccompat.h"
@@ -217,3 +214,9 @@ int main(void)
217214

218215
return 0;
219216
}
217+
#else // VANILLA_NACL
218+
int main(void)
219+
{
220+
return 0;
221+
}
222+
#endif

other/analysis/gen-file.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ FIND_QUERY="$FIND_QUERY -and -not -name trace.cc"
5858
FIND_QUERY="$FIND_QUERY -and -not -name version_test.c"
5959
FIND_QUERY="$FIND_QUERY -and -not -wholename './testing/fuzzing/*'"
6060

61+
if [ "$SKIP_GTEST" == 1 ]; then
62+
FIND_QUERY="$FIND_QUERY -and -not -name '*_test.cc'"
63+
fi
64+
6165
readarray -t FILES <<<"$(eval "$FIND_QUERY")"
6266

6367
(for i in "${FILES[@]}"; do

other/analysis/run-check-recursion

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/bin/sh
22

3+
set -e
4+
35
cat toxav/*.c toxcore/*.c toxencryptsave/*.c |
46
clang "$(pkg-config --cflags libsodium opus vpx)" \
57
-Itoxav -Itoxcore -Itoxencryptsave -S -emit-llvm -xc - -o- |

other/analysis/run-clang

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,34 @@
22

33
. other/analysis/gen-file.sh
44

5-
echo "Running Clang compiler"
6-
clang++ -o /dev/null amalgamation.cc \
7-
"${CPPFLAGS[@]}" \
8-
"${LDFLAGS[@]}" \
9-
-std=c++11 \
10-
-Werror \
11-
-Weverything \
12-
-Wno-alloca \
13-
-Wno-c++98-compat-pedantic \
14-
-Wno-c99-extensions \
15-
-Wno-conversion \
16-
-Wno-covered-switch-default \
17-
-Wno-disabled-macro-expansion \
18-
-Wno-documentation-deprecated-sync \
19-
-Wno-global-constructors \
20-
-Wno-missing-braces \
21-
-Wno-missing-field-initializers \
22-
-Wno-old-style-cast \
23-
-Wno-padded \
24-
-Wno-sign-compare \
25-
-Wno-unreachable-code-return \
26-
-Wno-unused-parameter \
27-
-Wno-used-but-marked-unused \
28-
-Wno-source-uses-openmp
5+
set -e
6+
7+
run() {
8+
echo "Running Clang compiler in variant '$*'"
9+
clang++ -o /dev/null amalgamation.cc \
10+
"${CPPFLAGS[@]}" \
11+
"${LDFLAGS[@]}" \
12+
"$@" \
13+
-std=c++11 \
14+
-Werror \
15+
-Weverything \
16+
-Wno-alloca \
17+
-Wno-c++98-compat-pedantic \
18+
-Wno-c99-extensions \
19+
-Wno-conversion \
20+
-Wno-covered-switch-default \
21+
-Wno-disabled-macro-expansion \
22+
-Wno-documentation-deprecated-sync \
23+
-Wno-global-constructors \
24+
-Wno-missing-braces \
25+
-Wno-missing-field-initializers \
26+
-Wno-old-style-cast \
27+
-Wno-padded \
28+
-Wno-sign-compare \
29+
-Wno-unreachable-code-return \
30+
-Wno-unused-parameter \
31+
-Wno-used-but-marked-unused \
32+
-Wno-source-uses-openmp
33+
}
34+
35+
. other/analysis/variants.sh

other/analysis/run-clang-analyze

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,14 @@
22

33
. other/analysis/gen-file.sh
44

5-
echo "Running Clang static analyzer"
6-
clang++ --analyze amalgamation.cc \
7-
"${CPPFLAGS[@]}" \
8-
-std=c++11
5+
set -e
6+
7+
run() {
8+
echo "Running Clang static analyzer in variant '$*'"
9+
clang++ --analyze amalgamation.cc \
10+
"${CPPFLAGS[@]}" \
11+
"$@" \
12+
-std=c++11
13+
}
14+
15+
. other/analysis/variants.sh

other/analysis/run-clang-tidy

Lines changed: 46 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
#!/bin/sh
1+
#!/bin/bash
22

3+
# TODO(iphydf): We might want some of these. For the ones we don't want, add a
4+
# comment explaining why not.
35
CHECKS="*"
6+
CHECKS="$CHECKS,-altera-unroll-loops"
47
CHECKS="$CHECKS,-android-cloexec-accept"
58
CHECKS="$CHECKS,-android-cloexec-fopen"
69
CHECKS="$CHECKS,-bugprone-not-null-terminated-result"
@@ -18,24 +21,31 @@ CHECKS="$CHECKS,-llvmlibc-restrict-system-libc-headers"
1821
CHECKS="$CHECKS,-misc-redundant-expression"
1922
CHECKS="$CHECKS,-misc-unused-parameters"
2023
CHECKS="$CHECKS,-readability-else-after-return"
24+
CHECKS="$CHECKS,-readability-function-cognitive-complexity"
2125
CHECKS="$CHECKS,-readability-inconsistent-declaration-parameter-name"
2226
CHECKS="$CHECKS,-readability-magic-numbers"
2327
CHECKS="$CHECKS,-readability-redundant-control-flow"
2428

29+
# TODO(iphydf): Maybe fix these?
30+
CHECKS="$CHECKS,-altera-id-dependent-backward-branch"
31+
CHECKS="$CHECKS,-altera-struct-pack-align"
32+
CHECKS="$CHECKS,-bugprone-branch-clone"
33+
CHECKS="$CHECKS,-bugprone-easily-swappable-parameters"
34+
CHECKS="$CHECKS,-bugprone-implicit-widening-of-multiplication-result"
35+
CHECKS="$CHECKS,-bugprone-integer-division"
36+
CHECKS="$CHECKS,-bugprone-narrowing-conversions"
37+
CHECKS="$CHECKS,-clang-analyzer-core.NonNullParamChecker"
38+
CHECKS="$CHECKS,-clang-analyzer-core.NullDereference"
39+
CHECKS="$CHECKS,-clang-analyzer-optin.portability.UnixAPI"
40+
CHECKS="$CHECKS,-clang-analyzer-unix.Malloc"
41+
CHECKS="$CHECKS,-clang-analyzer-valist.Uninitialized"
42+
CHECKS="$CHECKS,-concurrency-mt-unsafe"
43+
CHECKS="$CHECKS,-cppcoreguidelines-avoid-non-const-global-variables"
44+
CHECKS="$CHECKS,-cppcoreguidelines-narrowing-conversions"
45+
CHECKS="$CHECKS,-google-readability-casting"
46+
CHECKS="$CHECKS,-misc-no-recursion"
47+
2548
ERRORS="*"
26-
# TODO(iphydf): Maybe fix these? Otherwise don't show them, if they are useless.
27-
ERRORS="$ERRORS,-bugprone-branch-clone"
28-
ERRORS="$ERRORS,-bugprone-integer-division"
29-
ERRORS="$ERRORS,-bugprone-narrowing-conversions"
30-
ERRORS="$ERRORS,-clang-analyzer-core.NonNullParamChecker"
31-
ERRORS="$ERRORS,-clang-analyzer-core.NullDereference"
32-
ERRORS="$ERRORS,-clang-analyzer-optin.portability.UnixAPI"
33-
ERRORS="$ERRORS,-clang-analyzer-unix.Malloc"
34-
ERRORS="$ERRORS,-clang-analyzer-valist.Uninitialized"
35-
ERRORS="$ERRORS,-cppcoreguidelines-avoid-non-const-global-variables"
36-
ERRORS="$ERRORS,-cppcoreguidelines-narrowing-conversions"
37-
ERRORS="$ERRORS,-google-readability-casting"
38-
ERRORS="$ERRORS,-misc-no-recursion"
3949

4050
# TODO(iphydf): Fix these.
4151
ERRORS="$ERRORS,-bugprone-macro-parentheses"
@@ -45,19 +55,29 @@ ERRORS="$ERRORS,-cert-err34-c"
4555
ERRORS="$ERRORS,-cert-str34-c"
4656
ERRORS="$ERRORS,-clang-analyzer-security.insecureAPI.strcpy"
4757
ERRORS="$ERRORS,-hicpp-uppercase-literal-suffix"
58+
ERRORS="$ERRORS,-readability-suspicious-call-argument"
4859
ERRORS="$ERRORS,-readability-uppercase-literal-suffix"
4960

5061
set -eux
5162

52-
clang-tidy-11 \
53-
-p=_build \
54-
--extra-arg=-DMIN_LOGGER_LEVEL=LOGGER_LEVEL_TRACE \
55-
--checks="$CHECKS" \
56-
--warnings-as-errors="$ERRORS" \
57-
--use-color \
58-
other/bootstrap_daemon/src/*.c \
59-
other/*.c \
60-
toxav/*.c \
61-
toxcore/*.c \
62-
toxencryptsave/*.c \
63-
"$@"
63+
run() {
64+
echo "Running clang-tidy in variant '$*'"
65+
EXTRA_ARGS=("$@")
66+
for i in "${!EXTRA_ARGS[@]}"; do
67+
EXTRA_ARGS[$i]="--extra-arg=${EXTRA_ARGS[$i]}"
68+
done
69+
clang-tidy-12 \
70+
-p=_build \
71+
--extra-arg=-DMIN_LOGGER_LEVEL=LOGGER_LEVEL_TRACE \
72+
"${EXTRA_ARGS[@]}" \
73+
--checks="$CHECKS" \
74+
--warnings-as-errors="$ERRORS" \
75+
--use-color \
76+
other/bootstrap_daemon/src/*.c \
77+
other/*.c \
78+
toxav/*.c \
79+
toxcore/*.c \
80+
toxencryptsave/*.c
81+
}
82+
83+
. other/analysis/variants.sh

0 commit comments

Comments
 (0)