xref: /aosp_15_r20/external/bpftool/include/linux/build_bug.h (revision 858ea5e570667251cdc31d3fe7b846b591105938)
1 /* SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) */
2 
3 #ifndef _LINUX_BUILD_BUG_H
4 #define _LINUX_BUILD_BUG_H
5 
6 #include <linux/compiler.h>
7 
8 /*
9  * Force a compilation error if condition is true, but also produce a
10  * result (of value 0 and type int), so the expression can be used
11  * e.g. in a structure initializer (or where-ever else comma expressions
12  * aren't permitted).
13  */
14 #define BUILD_BUG_ON_ZERO(e) ((int)(sizeof(struct { int:(-!!(e)); })))
15 
16 /**
17  * BUILD_BUG_ON_MSG - break compile if a condition is true & emit supplied
18  *		      error message.
19  * @condition: the condition which the compiler should know is false.
20  *
21  * See BUILD_BUG_ON for description.
22  */
23 #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
24 
25 /**
26  * BUILD_BUG_ON - break compile if a condition is true.
27  * @condition: the condition which the compiler should know is false.
28  *
29  * If you have some code which relies on certain constants being equal, or
30  * some other compile-time-evaluated condition, you should use BUILD_BUG_ON to
31  * detect if someone changes it.
32  */
33 #define BUILD_BUG_ON(condition) \
34 	BUILD_BUG_ON_MSG(condition, "BUILD_BUG_ON failed: " #condition)
35 
36 /**
37  * BUILD_BUG - break compile if used.
38  *
39  * If you have some code that you expect the compiler to eliminate at
40  * build time, you should use BUILD_BUG to detect if it is
41  * unexpectedly used.
42  */
43 #define BUILD_BUG() BUILD_BUG_ON_MSG(1, "BUILD_BUG failed")
44 
45 #endif
46