From: Vladimír Čunát Date: Tue, 25 Nov 2025 09:27:35 +0000 (+0100) Subject: lib/kru + elsewhere nit: avoid message-less static_assert() X-Git-Tag: v6.0.17~2^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d908e2a4adf408a5ab7f461ca610c8fccce602cc;p=thirdparty%2Fknot-resolver.git lib/kru + elsewhere nit: avoid message-less static_assert() With clang they'd cause lots of complaints: warning: '_Static_assert' with no message is a C23 extension [-Wc23-extensions] --- diff --git a/lib/cache/top.c b/lib/cache/top.c index f9b7ace66..363ffb2fe 100644 --- a/lib/cache/top.c +++ b/lib/cache/top.c @@ -46,15 +46,15 @@ static inline uint32_t ticks_now(void) static inline bool first_access_ro(struct kr_cache_top_context *ctx, kru_hash_t hash) { // struct kr_cache_top_context { uint32_t bloom[32]; } - static_assert(sizeof(((struct kr_cache_top_context *)0)->bloom[0]) * 8 == 32); - static_assert(sizeof(((struct kr_cache_top_context *)0)->bloom) * 8 == 32 * 32); + static_assert(sizeof(((struct kr_cache_top_context *)0)->bloom[0]) * 8 == 32, ""); + static_assert(sizeof(((struct kr_cache_top_context *)0)->bloom) * 8 == 32 * 32, ""); // expected around 40 unique cache accesses per request context, possibly up to ~200; // prob. of collision of 50th unique access with the preceeding ones: ~0.1 %; // 75th: ~0.4 %; 100th: ~1.1 %; 150th: ~3.9 %; 200th: ~8.7 %; 300th: ~23 %; 400th: ~39 % // -> collision means not counting the cache access in KRU while it should be uint8_t *h = (uint8_t *)&hash; - static_assert(sizeof(kru_hash_t) >= 8); + static_assert(sizeof(kru_hash_t) >= 8, "bad size of kru_hash_t"); bool accessed = 1u & (ctx->bloom[h[0] % 32] >> (h[1] % 32)) & @@ -70,7 +70,7 @@ static inline bool first_access(struct kr_cache_top_context *ctx, kru_hash_t has if (!first_access_ro(ctx, hash)) return false; uint8_t *h = (uint8_t *)&hash; - static_assert(sizeof(kru_hash_t) >= 8); + static_assert(sizeof(kru_hash_t) >= 8, "bad size of kru_hash_t"); ctx->bloom[h[0] % 32] |= 1u << (h[1] % 32); ctx->bloom[h[2] % 32] |= 1u << (h[3] % 32); diff --git a/lib/kru.inc.c b/lib/kru.inc.c index 162b1ab6d..cf23516b5 100644 --- a/lib/kru.inc.c +++ b/lib/kru.inc.c @@ -268,7 +268,7 @@ static inline void kru_limited_prefetch(struct kru *kru, uint32_t time_now, uint { // Obtain hash of *buf. kru_hash_t hash; - static_assert(sizeof(kru_hash_t) * 8 <= 64); + static_assert(sizeof(kru_hash_t) * 8 <= 64, "bad size of kru_hash_t"); #if !USE_AES hash = SipHash(&kru->hash_key, SIPHASH_RC, SIPHASH_RF, key, 16); #else @@ -292,7 +292,7 @@ static inline void kru_limited_prefetch_prefix(struct kru *kru, uint32_t time_no { // Obtain hash of *buf. kru_hash_t hash; - static_assert(sizeof(kru_hash_t) * 8 <= 64); + static_assert(sizeof(kru_hash_t) * 8 <= 64, "bad size of kru_hash_t"); #if !USE_AES { @@ -354,10 +354,10 @@ static kru_hash_t kru_hash_bytes(struct kru *kru, uint8_t *key, size_t key_size) { // Obtain hash of *buf. kru_hash_t hash; - static_assert(sizeof(kru_hash_t) * 8 <= 64); + static_assert(sizeof(kru_hash_t) * 8 <= 64, "bad size of kru_hash_t"); // We use SipHash even for otherwise optimized KRU variant, which has diffent type of hash_key. - static_assert(sizeof(kru->hash_key) >= sizeof(SIPHASH_KEY)); + static_assert(sizeof(kru->hash_key) >= sizeof(SIPHASH_KEY), "bad size of kru::hash_key"); SIPHASH_KEY *hash_key = (void *)&kru->hash_key; hash = SipHash(hash_key, SIPHASH_RC, SIPHASH_RF, key, key_size); diff --git a/utils/cache_gc/categories.c b/utils/cache_gc/categories.c index 579320a2b..f54fc5d84 100644 --- a/utils/cache_gc/categories.c +++ b/utils/cache_gc/categories.c @@ -34,7 +34,7 @@ category_t kr_gc_categorize(struct kr_cache_top *top, gc_record_info_t * info, v // evict all expired before any non-expired (incl. RTT) res = res / 2 + 65; // 65..97 } - static_assert(CATEGORIES - 1 > 97); + static_assert(CATEGORIES - 1 > 97, "inssuficient CATEGORIES number"); if (!kr_log_is_debug(CACHE, NULL)) // skip these computations if not needed goto finish;