public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] compiler.h: don't use temporary variable in __compiletime_assert()
@ 2014-05-08  6:31 Johannes Berg
  2014-05-08  6:54 ` Luca Coelho
                   ` (3 more replies)
  0 siblings, 4 replies; 11+ messages in thread
From: Johannes Berg @ 2014-05-08  6:31 UTC (permalink / raw)
  To: Andrew Morton, linux-kernel, Peter Zijlstra, Daniel Santos
  Cc: Paul E. McKenney

From: Johannes Berg <johannes.berg@intel.com>

Usually, BUG_ON and friends aren't even evaluated in sparse, but
recently compiletime_assert_atomic_type() was added, and that now
results in a sparse warning every time it is used.

The reason turns out to be the temporary variable, after it sparse
no longer considers the value to be a constant, and results in a
warning and an error. The error is the more annoying part of this
as it suppresses any further warnings in the same file, hiding
other problems.

Since this is all about compile time and the condition should be
side-effect free to start with, there's no downside (apart maybe
from a slight compilation time penalty?) to just duplicating it,
leaving sparse able to evaluate it at check time, getting rid of
the warning and error.

Signed-off-by: Johannes Berg <johannes.berg@intel.com>
---
 include/linux/compiler.h | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/include/linux/compiler.h b/include/linux/compiler.h
index 2472740d7ab2..38c0e00ddef8 100644
--- a/include/linux/compiler.h
+++ b/include/linux/compiler.h
@@ -324,11 +324,10 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
 
 #define __compiletime_assert(condition, msg, prefix, suffix)		\
 	do {								\
-		bool __cond = !(condition);				\
 		extern void prefix ## suffix(void) __compiletime_error(msg); \
-		if (__cond)						\
+		if (!(condition))					\
 			prefix ## suffix();				\
-		__compiletime_error_fallback(__cond);			\
+		__compiletime_error_fallback(!(condition));		\
 	} while (0)
 
 #define _compiletime_assert(condition, msg, prefix, suffix) \
-- 
2.0.0.rc0


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

end of thread, other threads:[~2014-05-13  9:27 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-05-08  6:31 [PATCH] compiler.h: don't use temporary variable in __compiletime_assert() Johannes Berg
2014-05-08  6:54 ` Luca Coelho
2014-05-08  6:56 ` Peter Zijlstra
2014-05-08 13:18 ` Paul E. McKenney
2014-05-12 13:42 ` James Hogan
2014-05-12 14:38   ` Johannes Berg
2014-05-12 14:56     ` James Hogan
2014-05-12 21:16   ` Andrew Morton
2014-05-13  7:31     ` Johannes Berg
2014-05-13  8:53       ` James Hogan
2014-05-13  9:26         ` Johannes Berg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox