diff options
Diffstat (limited to 'include/linux/compiler.h')
-rw-r--r-- | include/linux/compiler.h | 32 |
1 files changed, 29 insertions, 3 deletions
diff --git a/include/linux/compiler.h b/include/linux/compiler.h index dd852b73b286..10b8f23fab0f 100644 --- a/include/linux/compiler.h +++ b/include/linux/compiler.h | |||
@@ -307,10 +307,36 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect); | |||
307 | #endif | 307 | #endif |
308 | #ifndef __compiletime_error | 308 | #ifndef __compiletime_error |
309 | # define __compiletime_error(message) | 309 | # define __compiletime_error(message) |
310 | # define __compiletime_error_fallback(condition) \ | ||
311 | do { ((void)sizeof(char[1 - 2 * condition])); } while (0) | ||
312 | #else | ||
313 | # define __compiletime_error_fallback(condition) do { } while (0) | ||
310 | #endif | 314 | #endif |
311 | #ifndef __linktime_error | 315 | |
312 | # define __linktime_error(message) | 316 | #define __compiletime_assert(condition, msg, prefix, suffix) \ |
313 | #endif | 317 | do { \ |
318 | bool __cond = !(condition); \ | ||
319 | extern void prefix ## suffix(void) __compiletime_error(msg); \ | ||
320 | if (__cond) \ | ||
321 | prefix ## suffix(); \ | ||
322 | __compiletime_error_fallback(__cond); \ | ||
323 | } while (0) | ||
324 | |||
325 | #define _compiletime_assert(condition, msg, prefix, suffix) \ | ||
326 | __compiletime_assert(condition, msg, prefix, suffix) | ||
327 | |||
328 | /** | ||
329 | * compiletime_assert - break build and emit msg if condition is false | ||
330 | * @condition: a compile-time constant condition to check | ||
331 | * @msg: a message to emit if condition is false | ||
332 | * | ||
333 | * In tradition of POSIX assert, this macro will break the build if the | ||
334 | * supplied condition is *false*, emitting the supplied error message if the | ||
335 | * compiler has support to do so. | ||
336 | */ | ||
337 | #define compiletime_assert(condition, msg) \ | ||
338 | _compiletime_assert(condition, msg, __compiletime_assert_, __LINE__) | ||
339 | |||
314 | /* | 340 | /* |
315 | * Prevent the compiler from merging or refetching accesses. The compiler | 341 | * Prevent the compiler from merging or refetching accesses. The compiler |
316 | * is also forbidden from reordering successive instances of ACCESS_ONCE(), | 342 | * is also forbidden from reordering successive instances of ACCESS_ONCE(), |