build_bug.h: remove negative-array fallback for BUILD_BUG_ON()
[linux-2.6-microblaze.git] / include / linux / build_bug.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _LINUX_BUILD_BUG_H
3 #define _LINUX_BUILD_BUG_H
4
5 #include <linux/compiler.h>
6
7 #ifdef __CHECKER__
8 #define __BUILD_BUG_ON_NOT_POWER_OF_2(n) (0)
9 #define BUILD_BUG_ON_NOT_POWER_OF_2(n) (0)
10 #define BUILD_BUG_ON_ZERO(e) (0)
11 #define BUILD_BUG_ON_INVALID(e) (0)
12 #define BUILD_BUG_ON_MSG(cond, msg) (0)
13 #define BUILD_BUG_ON(condition) (0)
14 #define BUILD_BUG() (0)
15 #else /* __CHECKER__ */
16
17 /* Force a compilation error if a constant expression is not a power of 2 */
18 #define __BUILD_BUG_ON_NOT_POWER_OF_2(n)        \
19         BUILD_BUG_ON(((n) & ((n) - 1)) != 0)
20 #define BUILD_BUG_ON_NOT_POWER_OF_2(n)                  \
21         BUILD_BUG_ON((n) == 0 || (((n) & ((n) - 1)) != 0))
22
23 /*
24  * Force a compilation error if condition is true, but also produce a
25  * result (of value 0 and type size_t), so the expression can be used
26  * e.g. in a structure initializer (or where-ever else comma expressions
27  * aren't permitted).
28  */
29 #define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:(-!!(e)); }))
30
31 /*
32  * BUILD_BUG_ON_INVALID() permits the compiler to check the validity of the
33  * expression but avoids the generation of any code, even if that expression
34  * has side-effects.
35  */
36 #define BUILD_BUG_ON_INVALID(e) ((void)(sizeof((__force long)(e))))
37
38 /**
39  * BUILD_BUG_ON_MSG - break compile if a condition is true & emit supplied
40  *                    error message.
41  * @condition: the condition which the compiler should know is false.
42  *
43  * See BUILD_BUG_ON for description.
44  */
45 #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
46
47 /**
48  * BUILD_BUG_ON - break compile if a condition is true.
49  * @condition: the condition which the compiler should know is false.
50  *
51  * If you have some code which relies on certain constants being equal, or
52  * some other compile-time-evaluated condition, you should use BUILD_BUG_ON to
53  * detect if someone changes it.
54  */
55 #define BUILD_BUG_ON(condition) \
56         BUILD_BUG_ON_MSG(condition, "BUILD_BUG_ON failed: " #condition)
57
58 /**
59  * BUILD_BUG - break compile if used.
60  *
61  * If you have some code that you expect the compiler to eliminate at
62  * build time, you should use BUILD_BUG to detect if it is
63  * unexpectedly used.
64  */
65 #define BUILD_BUG() BUILD_BUG_ON_MSG(1, "BUILD_BUG failed")
66
67 #endif  /* __CHECKER__ */
68
69 #endif  /* _LINUX_BUILD_BUG_H */