Skip to content

Commit 7c00621

Browse files
committed
compiler_types: mark __compiletime_assert failure as __noreturn
`__compiletime_assert` declares a fake `extern` function which appears (to the compiler) to be called when the test fails. Therefore, compilers may emit possibly-uninitialized warnings in some cases, even if it will be an error anyway (for compilers supporting the `error` attribute, e.g. GCC and Clang >= 14) or a link failure (for those that do not, e.g. Clang < 14). Annotating the fake function as `__noreturn` gives them the information they need to avoid the warning, e.g. see https://godbolt.org/z/x1v69jjYY. Link: https://lore.kernel.org/llvm/202110100514.3h9CI4s0-lkp@intel.com/ Reported-by: kernel test robot <lkp@intel.com> Reviewed-by: Nathan Chancellor <nathan@kernel.org> Reviewed-by: Nick Desaulniers <ndesaulniers@google.com> Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
1 parent d08fd74 commit 7c00621

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

include/linux/compiler_types.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,13 @@ struct ftrace_likely_data {
298298
#ifdef __OPTIMIZE__
299299
# define __compiletime_assert(condition, msg, prefix, suffix) \
300300
do { \
301-
extern void prefix ## suffix(void) __compiletime_error(msg); \
301+
/* \
302+
* __noreturn is needed to give the compiler enough \
303+
* information to avoid certain possibly-uninitialized \
304+
* warnings (regardless of the build failing). \
305+
*/ \
306+
__noreturn extern void prefix ## suffix(void) \
307+
__compiletime_error(msg); \
302308
if (!(condition)) \
303309
prefix ## suffix(); \
304310
} while (0)

0 commit comments

Comments
 (0)