Skip to content

Commit 5b992ad

Browse files
committed
tools headers: Adopt verbatim copy of compiletime_assert() from kernel sources
Will be needed when syncing the linux/bits.h header, in the next cset. Cc: Adrian Hunter <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Namhyung Kim <[email protected]> Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent d8ed4d7 commit 5b992ad

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

tools/include/linux/compiler.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,32 @@
1010
# define __compiletime_error(message)
1111
#endif
1212

13+
#ifdef __OPTIMIZE__
14+
# define __compiletime_assert(condition, msg, prefix, suffix) \
15+
do { \
16+
extern void prefix ## suffix(void) __compiletime_error(msg); \
17+
if (!(condition)) \
18+
prefix ## suffix(); \
19+
} while (0)
20+
#else
21+
# define __compiletime_assert(condition, msg, prefix, suffix) do { } while (0)
22+
#endif
23+
24+
#define _compiletime_assert(condition, msg, prefix, suffix) \
25+
__compiletime_assert(condition, msg, prefix, suffix)
26+
27+
/**
28+
* compiletime_assert - break build and emit msg if condition is false
29+
* @condition: a compile-time constant condition to check
30+
* @msg: a message to emit if condition is false
31+
*
32+
* In tradition of POSIX assert, this macro will break the build if the
33+
* supplied condition is *false*, emitting the supplied error message if the
34+
* compiler has support to do so.
35+
*/
36+
#define compiletime_assert(condition, msg) \
37+
_compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
38+
1339
/* Optimization barrier */
1440
/* The "volatile" is due to gcc bugs */
1541
#define barrier() __asm__ __volatile__("": : :"memory")

0 commit comments

Comments
 (0)