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