git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 1/2] bloom: silence CHECK_ASSERTION_SIDE_EFFECTS false positive

From
Jeff King <peff@peff.net>
Date
Jul 26, 2026, 08:37 UTC
Message-ID
<20260726083727.GA3529069@coredump.intra.peff.net>
In-Reply-To
<20260726083254.GA3528497@coredump.intra.peff.net>

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>
---
Building with clang or with "gcc -flto" seems to also silence the false
positive. We might consider using those for the static-analysis job.
But since in this instance we can both silence it and (IMHO) make the
code nicer to read, I think it's reasonable to do so. We can leave
tinkering with the assert() magic as a separate topic for anyone
interested.
 bloom.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/bloom.c b/bloom.c
index c98d1672ad..caf22f9831 100644
--- a/bloom.c
+++ b/bloom.c
@@ -610,10 +610,10 @@ int bloom_filter_contains_vec(const struct bloom_filter *filter,
 uint32_t test_bloom_murmur3_seeded(uint32_t seed, const char *data, size_t len,
 				   int version)
 {
-	assert(version == 1 || version == 2);
-
 	if (version == 2)
 		return murmur3_seeded_v2(seed, data, len);
-	else
+	else if (version == 1)
 		return murmur3_seeded_v1(seed, data, len);
+	else
+		BUG("unexpected bloom version: %d", version);
 }
-- 
2.55.0.742.gf2bff09aa6
Previous: Jeff KingNext: Jeff King
Message 2 of 13 in “bump static-analysis ci image version”
  1. 0/2 bump static-analysis ci image versionJeff King, Jul 26, 2026
  2. 1/2 bloom: silence CHECK_ASSERTION_SIDE_EFFECTS false positiveJeff King, Jul 26, 2026
  3. 2/2 ci: bump ubuntu image version for static-analysis jobJeff King, Jul 26, 2026
  4. Patrick SteinhardtAug 7, 2026
  5. Junio C HamanoAug 7, 2026
  6. Patrick SteinhardtAug 10, 2026
  7. Junio C HamanoAug 10, 2026
  8. Patrick SteinhardtAug 11, 2026
  9. Jeff KingSep 5, 2026
  10. Elijah NewrenAug 7, 2026
  11. SZEDER GáborAug 8, 2026
  12. Jeff KingSep 5, 2026
  13. Junio C HamanoJul 26, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.