33CHECKS=" *"
44ERRORS=" *"
55
6+ # Can't fix this, because winsock has different HANDLE type than posix.
7+ # Still good to occasionally look at.
8+ ERRORS=" $ERRORS ,-google-readability-casting"
9+
610# Need to investigate or disable and document these.
711# =========================================================
812
913# TODO(iphydf): Fix these.
1014ERRORS=" $ERRORS ,-cert-err34-c"
1115ERRORS=" $ERRORS ,-readability-suspicious-call-argument"
16+ CHECKS=" $CHECKS ,-cppcoreguidelines-avoid-goto,-hicpp-avoid-goto"
17+ CHECKS=" $CHECKS ,-bugprone-incorrect-roundings"
1218
13- # TODO(iphydf): Fix once cimple 0.0.19 is released.
14- CHECKS=" $CHECKS ,-google-readability-casting"
15-
16- # TODO(iphydf): Fix these.
19+ # TODO(iphydf): Fix this by making more functions set error code enums.
1720CHECKS=" $CHECKS ,-bugprone-switch-missing-default-case"
1821
1922# TODO(iphydf): We might want some of these. For the ones we don't want, add a
@@ -30,17 +33,22 @@ CHECKS="$CHECKS,-misc-no-recursion"
3033CHECKS=" $CHECKS ,-cppcoreguidelines-avoid-non-const-global-variables"
3134
3235# TODO(iphydf): Probably fix these.
33- CHECKS=" $CHECKS ,-cert-err33-c"
34- CHECKS=" $CHECKS ,-cppcoreguidelines-avoid-magic-numbers"
35- CHECKS=" $CHECKS ,-readability-magic-numbers"
36-
37- # TODO(iphydf): We're using a lot of macros for constants. Should we convert
38- # all of them to enum?
39- CHECKS=" $CHECKS ,-modernize-macro-to-enum"
36+ CHECKS=" $CHECKS ,-cert-err33-c,-cppcoreguidelines-avoid-magic-numbers,-readability-magic-numbers"
4037
4138# Documented disabled checks. We don't want these for sure.
4239# =========================================================
4340
41+ # We want to decay many arrays to pointers. In C, we do that all the time.
42+ CHECKS=" $CHECKS ,-cppcoreguidelines-pro-bounds-array-to-pointer-decay,-hicpp-no-array-decay"
43+
44+ # enum{} breaks comparisons and arithmetic in C++.
45+ CHECKS=" $CHECKS ,-modernize-macro-to-enum"
46+
47+ # For most things, we do want this, but for some we want to ensure (with msan)
48+ # that struct members are actually initialised with useful non-zero values.
49+ # Initialising them by default takes away that validation.
50+ CHECKS=" $CHECKS ,-cppcoreguidelines-pro-type-member-init,-hicpp-member-init"
51+
4452# https://stackoverflow.com/questions/58672959/why-does-clang-tidy-say-vsnprintf-has-an-uninitialized-va-list-argument
4553CHECKS=" $CHECKS ,-clang-analyzer-valist.Uninitialized"
4654
@@ -115,8 +123,7 @@ CHECKS="$CHECKS,-readability-redundant-control-flow"
115123# ^
116124# Trip the checker, which is true, because of integer promotion, but also not
117125# very helpful as a diagnostic.
118- CHECKS=" $CHECKS ,-bugprone-narrowing-conversions"
119- CHECKS=" $CHECKS ,-cppcoreguidelines-narrowing-conversions"
126+ CHECKS=" $CHECKS ,-bugprone-narrowing-conversions,-cppcoreguidelines-narrowing-conversions"
120127
121128# Mistakenly thinks that
122129# const int a = 0, b = 1;
@@ -135,14 +142,52 @@ CHECKS="$CHECKS,-cppcoreguidelines-narrowing-conversions"
135142# - Turning 'a' and 'b' into pre-processor macros is the only option left, but
136143# #defines and #undefs in the middle of a function hurt the readability and
137144# are less idiomatic than simply using 'const int'.
138- CHECKS=" $CHECKS ,-cert-dcl03-c"
139- CHECKS=" $CHECKS ,-hicpp-static-assert"
140- CHECKS=" $CHECKS ,-misc-static-assert"
145+ CHECKS=" $CHECKS ,-cert-dcl03-c,-hicpp-static-assert,-misc-static-assert"
141146
142147# Doesn't consider use of preprocessor macros as needing a header, breaking
143148# struct definitions that depend on size macros from e.g. crypto_core.h.
144149CHECKS=" $CHECKS ,-misc-include-cleaner"
145150
151+ # A bunch of checks only valid for C++, we turn off for C.
152+ # =========================================================
153+
154+ # We don't use Google's int typedefs.
155+ CHECKS=" $CHECKS ,-google-runtime-int"
156+ # We write C code, so we use C arrays.
157+ CHECKS=" $CHECKS ,-cppcoreguidelines-avoid-c-arrays,-hicpp-avoid-c-arrays,-modernize-avoid-c-arrays"
158+ # C loops are ok. This one tells us to use range-for.
159+ CHECKS=" $CHECKS ,-modernize-loop-convert"
160+ # No auto in C.
161+ CHECKS=" $CHECKS ,-hicpp-use-auto,-modernize-use-auto"
162+ # Only C style casts in C.
163+ CHECKS=" $CHECKS ,-cppcoreguidelines-pro-type-cstyle-cast"
164+ # We use malloc (for now), and MISRA checks this too.
165+ CHECKS=" $CHECKS ,-cppcoreguidelines-no-malloc,-hicpp-no-malloc"
166+ # No owning_ptr<> in C.
167+ CHECKS=" $CHECKS ,-cppcoreguidelines-owning-memory"
168+ # void foo(void) is good in C.
169+ CHECKS=" $CHECKS ,-modernize-redundant-void-arg"
170+ # No using-typedefs in C.
171+ CHECKS=" $CHECKS ,-modernize-use-using"
172+ # No namespaces in C.
173+ CHECKS=" $CHECKS ,-misc-use-anonymous-namespace"
174+ # No trailing return type in C.
175+ CHECKS=" $CHECKS ,-modernize-use-trailing-return-type"
176+ # No <cstdint> and friends in C.
177+ CHECKS=" $CHECKS ,-hicpp-deprecated-headers,-modernize-deprecated-headers"
178+ # We use varargs for logging (we could reconsider, but right now we do).
179+ CHECKS=" $CHECKS ,-cppcoreguidelines-pro-type-vararg,-hicpp-vararg,-cert-dcl50-cpp"
180+ # We do want to use the array index operator, even when the index is non-constant.
181+ CHECKS=" $CHECKS ,-cppcoreguidelines-pro-bounds-constant-array-index"
182+ # We don't want to use pointer arithmetic, but this one includes array index
183+ # operators, which we do want to use.
184+ CHECKS=" $CHECKS ,-cppcoreguidelines-pro-bounds-pointer-arithmetic"
185+ # Can't use constexpr, yet. C will have it eventually, but it'll be years
186+ # until we can use it across all the compilers.
187+ CHECKS=" $CHECKS ,-cppcoreguidelines-macro-usage"
188+ # These are all very C++ and/or LLVM specific.
189+ CHECKS=" $CHECKS ,-llvmlibc-*"
190+
146191set -eux
147192
148193# TODO(iphydf): Add toxav.
@@ -188,5 +233,6 @@ run() {
188233}
189234
190235cmake . -B_build -GNinja -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
236+ sed -i -e ' s/-std=c11/-xc++/' _build/compile_commands.json
191237
192238. other/analysis/variants.sh
0 commit comments