Skip to content

Commit 7c47a32

Browse files
nathanchanceZile995
authored andcommitted
tracing: Fix clang -Wint-in-bool-context warnings in IF_ASSIGN macro
After r372664 in clang, the IF_ASSIGN macro causes a couple hundred warnings along the lines of: kernel/trace/trace_output.c:1331:2: warning: converting the enum constant to a boolean [-Wint-in-bool-context] kernel/trace/trace.h:409:3: note: expanded from macro 'trace_assign_type' IF_ASSIGN(var, ent, struct ftrace_graph_ret_entry, ^ kernel/trace/trace.h:371:14: note: expanded from macro 'IF_ASSIGN' WARN_ON(id && (entry)->type != id); \ ^ 264 warnings generated. This warning can catch issues with constructs like: if (state == A || B) where the developer really meant: if (state == A || state == B) This is currently the only occurrence of the warning in the kernel tree across defconfig, allyesconfig, allmodconfig for arm32, arm64, and x86_64. Add the implicit '!= 0' to the WARN_ON statement to fix the warnings and find potential issues in the future. Link: llvm/llvm-project@28b38c2 Link: ClangBuiltLinux/linux#686 Link: http://lkml.kernel.org/r/20190926162258.466321-1-natechancellor@gmail.com Reviewed-by: Nick Desaulniers <ndesaulniers@google.com> Signed-off-by: Nathan Chancellor <natechancellor@gmail.com> Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org> Signed-off-by: Albert I <kras@raphielgang.org>
1 parent 7ca6e42 commit 7c47a32

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

kernel/trace/trace.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -265,11 +265,11 @@ static inline struct trace_array *top_trace_array(void)
265265
__builtin_types_compatible_p(typeof(var), type *)
266266

267267
#undef IF_ASSIGN
268-
#define IF_ASSIGN(var, entry, etype, id) \
269-
if (FTRACE_CMP_TYPE(var, etype)) { \
270-
var = (typeof(var))(entry); \
271-
WARN_ON(id && (entry)->type != id); \
272-
break; \
268+
#define IF_ASSIGN(var, entry, etype, id) \
269+
if (FTRACE_CMP_TYPE(var, etype)) { \
270+
var = (typeof(var))(entry); \
271+
WARN_ON(id != 0 && (entry)->type != id); \
272+
break; \
273273
}
274274

275275
/* Will cause compile errors if type is not found. */

0 commit comments

Comments
 (0)