Page MenuHomeFreeBSD

LinuxKPI: change BUILD_BUG_ON()
ClosedPublic

Authored by bz on May 24 2021, 6:42 PM.
Tags
None
Referenced Files
Unknown Object (File)
Fri, Oct 3, 11:44 PM
Unknown Object (File)
Thu, Sep 25, 2:01 PM
Unknown Object (File)
Fri, Sep 12, 11:01 AM
Unknown Object (File)
Aug 11 2025, 3:59 PM
Unknown Object (File)
Jul 19 2025, 6:00 AM
Unknown Object (File)
Jul 5 2025, 10:15 AM
Unknown Object (File)
Jun 25 2025, 12:21 PM
Unknown Object (File)
Jun 25 2025, 4:28 AM

Details

Summary

BUILD_BUG_ON() can be used inside functions where the definition to
CTASSERT() (_Static_assert()) seems to not work.
Go back to an old-style CTASSERT() implementation but also add a
variable dclaration to avoid "unsued typedef" errors and dummy-use
the variable to avoid "unusued variable" errors. Given it is all
self-contained in a block and not used outside this should be
optimised away.

Sponsored by: The FreeBSD Foundation
MFC after: 2 weeks
Reviewed by:
Differential Revision:

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 39400
Build 36289: arc lint + arc unit

Event Timeline

bz requested review of this revision.May 24 2021, 6:42 PM
hselasky added inline comments.
sys/compat/linuxkpi/common/include/linux/kernel.h
100

Should this be enclosed with while (0) and not "do { } while (0) "?

sys/compat/linuxkpi/common/include/linux/kernel.h
100

Would a while (0) { } be optimized out without ever entering the block because it can never happen?

sys/compat/linuxkpi/common/include/linux/kernel.h
100

Yes, with -O2, but after parsing the code. So I believe any asserts will trigger.

Switch to while (0) { } as suggested by @hselasky

This revision is now accepted and ready to land.May 25 2021, 9:42 AM
This revision was automatically updated to reflect the committed changes.