Skip to content

Commit e6428c3

Browse files
committed
tools headers compiler: Pick the const_true() define from the kernel sources
The sync of include/linux/bits.h with the kernel sources will make use of this define, so add it to the tools/include/linux/compiler. variant used to build tools/ living code. Acked-by: Vincent Mailhol <[email protected]> Acked-by: Yury Norov [NVIDIA] <[email protected]> Cc: Adrian Hunter <[email protected]> Cc: Ian Rogers <[email protected]> Cc: James Clark <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Kan Liang <[email protected]> Cc: Namhyung Kim <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent fa7a1e8 commit e6428c3

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

tools/include/linux/compiler.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,28 @@
8181
#define __is_constexpr(x) \
8282
(sizeof(int) == sizeof(*(8 ? ((void *)((long)(x) * 0l)) : (int *)8)))
8383

84+
/*
85+
* Similar to statically_true() but produces a constant expression
86+
*
87+
* To be used in conjunction with macros, such as BUILD_BUG_ON_ZERO(),
88+
* which require their input to be a constant expression and for which
89+
* statically_true() would otherwise fail.
90+
*
91+
* This is a trade-off: const_true() requires all its operands to be
92+
* compile time constants. Else, it would always returns false even on
93+
* the most trivial cases like:
94+
*
95+
* true || non_const_var
96+
*
97+
* On the opposite, statically_true() is able to fold more complex
98+
* tautologies and will return true on expressions such as:
99+
*
100+
* !(non_const_var * 8 % 4)
101+
*
102+
* For the general case, statically_true() is better.
103+
*/
104+
#define const_true(x) __builtin_choose_expr(__is_constexpr(x), x, false)
105+
84106
#ifdef __ANDROID__
85107
/*
86108
* FIXME: Big hammer to get rid of tons of:

0 commit comments

Comments
 (0)