]> git.ipfire.org Git - thirdparty/git.git/commit
bloom: silence CHECK_ASSERTION_SIDE_EFFECTS false positive
authorJeff King <peff@peff.net>
Sun, 26 Jul 2026 08:37:27 +0000 (04:37 -0400)
committerJunio C Hamano <gitster@pobox.com>
Sun, 26 Jul 2026 16:36:17 +0000 (09:36 -0700)
commitae0780def7353ec713a96ef498d10e4ef70692a2
tree52b256213cb581cf5d8dc6a614dccb9b98a3dd0b
parente9019fcafe0040228b8631c30f97ae1adb61bcdc
bloom: silence CHECK_ASSERTION_SIDE_EFFECTS false positive

Using gcc 15, compiling with CHECK_ASSERTION_SIDE_EFFECTS=1 causes a
complaint about this line in bloom.c having a side effect:

assert(version == 1 || version == 2);

I think this is pretty clearly a false positive, as those comparisons
should not have side effects. The side-effect checker uses a magic
definition of assert() that relies on the compiler's optimizer to drop a
reference to an otherwise unused variable. And for whatever reason, gcc
chooses not to do so here under -O2 (side note: if you have -O0 in your
CFLAGS, that naturally creates many more false positives!).

This code has been around for a while, but nobody seems to have noticed
because we use an older version of the compiler in our static-analysis
ci job, and it does not complain. Presumably very few people run this
check locally on their more modern compilers.

Let's silence the false positive to avoid confusion for anyone running
locally, and to make it possible to upgrade the image we use for our
static-analysis job.

We could just switch to our custom ASSERT() here, but I think we can
improve the code by integrating the assertion into the if/else cascade.
That avoids repeating the logic about which versions are acceptable.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
bloom.c