| 1 | #ifndef _LTTNG_BUG_H |
| 2 | #define _LTTNG_BUG_H |
| 3 | |
| 4 | /* |
| 5 | * lib/bug.h |
| 6 | * |
| 7 | * (C) Copyright 2010-2011 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
| 8 | * |
| 9 | * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED |
| 10 | * OR IMPLIED. ANY USE IS AT YOUR OWN RISK. |
| 11 | * |
| 12 | * Permission is hereby granted to use or copy this program |
| 13 | * for any purpose, provided the above notices are retained on all copies. |
| 14 | * Permission to modify the code and to distribute modified code is granted, |
| 15 | * provided the above notices are retained, and a notice that the code was |
| 16 | * modified is included with the above copyright notice. |
| 17 | * |
| 18 | */ |
| 19 | |
| 20 | #define BUILD_BUG_ON(condition) \ |
| 21 | ((void) sizeof(char[-!!(condition)])) |
| 22 | |
| 23 | /** |
| 24 | * BUILD_RUNTIME_BUG_ON - check condition at build (if constant) or runtime |
| 25 | * @condition: the condition which should be false. |
| 26 | * |
| 27 | * If the condition is a constant and true, the compiler will generate a build |
| 28 | * error. If the condition is not constant, a BUG will be triggered at runtime |
| 29 | * if the condition is ever true. If the condition is constant and false, no |
| 30 | * code is emitted. |
| 31 | */ |
| 32 | #define BUILD_RUNTIME_BUG_ON(condition) \ |
| 33 | do { \ |
| 34 | if (__builtin_constant_p(condition)) \ |
| 35 | BUILD_BUG_ON(condition); \ |
| 36 | else \ |
| 37 | BUG_ON(condition); \ |
| 38 | } while (0) |
| 39 | |
| 40 | #endif |