Page MenuHomeFreeBSD

LinuxKPI: avoid -Werror=unused-value in sort() from BUILD_BUG_ON_ZERO()
AbandonedPublic

Authored by bz on Feb 27 2026, 4:56 AM.
Tags
None
Referenced Files
Unknown Object (File)
Wed, Apr 1, 5:35 AM
Unknown Object (File)
Wed, Apr 1, 5:35 AM
Unknown Object (File)
Tue, Mar 24, 7:18 AM
Unknown Object (File)
Mon, Mar 23, 1:52 AM
Unknown Object (File)
Thu, Mar 19, 9:16 PM
Unknown Object (File)
Sat, Mar 14, 12:10 AM
Unknown Object (File)
Fri, Mar 13, 1:47 AM
Unknown Object (File)
Fri, Mar 13, 1:46 AM
Subscribers

Details

Reviewers
jhb
emaste
Group Reviewers
linuxkpi
Summary

The BUILD_BUG_ON_ZERO() macro returns an (int)0 if it does not fail
at build time. LinuxKPI sort() has it as a guard for an unsupported
argument but ignores the return value.
This leads to gcc complaining:
error: statement with no effect [-Werror=unused-value]
Cast the result to (void) to silence the error as we are not interested
in it.

Reported by: CI
Sponsored by: The FreeBSD Foundation
MFC after: 3 days

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 71053
Build 67936: arc lint + arc unit

Event Timeline

bz requested review of this revision.Feb 27 2026, 4:56 AM
This revision is now accepted and ready to land.Feb 27 2026, 7:54 PM
siva added a subscriber: siva.

Ah sorry, I accidentally submitted a review for a similar thing, but I think BUILD_BUG_ON(swap) is cleaner?

Ah sorry, I accidentally submitted a review for a similar thing, but I think BUILD_BUG_ON(swap) is cleaner?

Yeah. I need to push it. I also tried to fix BUILD_BUG_ON_ZERO() but in the end I traded one GNU-extension warning for another. Still pondering if it would be cleaner ..

-#define        BUILD_BUG_ON_ZERO(x)    ((int)sizeof(struct { int:-((x) != 0); }))
+
+/*
+ * Doing the maths avoids -Wgnu-empty-struct;
+ * still -Wno-gnu-folding-constant for NULL input.
+ */
+#define        BUILD_BUG_ON_ZERO(x)                                    \
+    (int)(4 - sizeof(struct {                                  \
+        _Static_assert(!(x), #x " not false");                 \
+        uint32_t ________z;                                    \
+    }))

I think the (void) here is preferable; I believe Linux's BUILD_BUG_ON_ZERO will behave the same way.

Ah, BUILD_BUG_ON as @siva did in D55634 seems cleanest?

Ah, BUILD_BUG_ON as @siva did in D55634 seems cleanest?

Hmm, for our implementation of BUILD_BUG_ON that is probably true though the ; @siva can you commit yours (maybe mention the warning in the commit message?)?

Sounds good, I'll commit mine and show the warning in the commit message.