linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] compiler_types: mark __compiletime_assert failure as __noreturn
@ 2021-10-14 13:23 Miguel Ojeda
  2021-10-14 15:01 ` Peter Zijlstra
                   ` (4 more replies)
  0 siblings, 5 replies; 15+ messages in thread
From: Miguel Ojeda @ 2021-10-14 13:23 UTC (permalink / raw)
  To: Nathan Chancellor, Nick Desaulniers
  Cc: Kees Cook, Peter Zijlstra, Miguel Ojeda, linux-kernel, llvm

`__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>
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
---
 include/linux/compiler_types.h | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/include/linux/compiler_types.h b/include/linux/compiler_types.h
index b6ff83a714ca..ca1a66b8cd2f 100644
--- a/include/linux/compiler_types.h
+++ b/include/linux/compiler_types.h
@@ -298,7 +298,13 @@ struct ftrace_likely_data {
 #ifdef __OPTIMIZE__
 # define __compiletime_assert(condition, msg, prefix, suffix)		\
 	do {								\
-		extern void prefix ## suffix(void) __compiletime_error(msg); \
+		/*							\
+		 * __noreturn is needed to give the compiler enough	\
+		 * information to avoid certain possibly-uninitialized	\
+		 * warnings (regardless of the build failing).		\
+		 */							\
+		__noreturn extern void prefix ## suffix(void)		\
+			__compiletime_error(msg);			\
 		if (!(condition))					\
 			prefix ## suffix();				\
 	} while (0)
-- 
2.33.1


^ permalink raw reply related	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2021-12-02  6:27 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-14 13:23 [PATCH] compiler_types: mark __compiletime_assert failure as __noreturn Miguel Ojeda
2021-10-14 15:01 ` Peter Zijlstra
2021-10-14 17:48   ` Nick Desaulniers
2021-10-14 18:33     ` Miguel Ojeda
2021-10-14 18:41       ` Miguel Ojeda
2021-10-14 18:55         ` Nick Desaulniers
2021-10-14 19:33           ` Miguel Ojeda
2021-10-15  7:55           ` Rasmus Villemoes
2021-10-15  8:11     ` Rasmus Villemoes
2021-10-15 12:36       ` Miguel Ojeda
2021-10-14 17:26 ` Nathan Chancellor
2021-10-14 17:36 ` Nick Desaulniers
2021-10-21 23:20 ` Miguel Ojeda
2021-12-02  6:12 ` Dan Carpenter
2021-12-02  6:24   ` Dan Carpenter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).