Linux: -Wint-in-bool-context in kernel/trace/trace_output.c

Created on 24 Sep 2019  路  8Comments  路  Source: ClangBuiltLinux/linux

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.

Should be fixed with:

diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
index 26b0a08f3c7d..f801d154ff6a 100644
--- a/kernel/trace/trace.h
+++ b/kernel/trace/trace.h
@@ -365,11 +365,11 @@ static inline struct trace_array *top_trace_array(void)
        __builtin_types_compatible_p(typeof(var), type *)

 #undef IF_ASSIGN
-#define IF_ASSIGN(var, entry, etype, id)               \
-       if (FTRACE_CMP_TYPE(var, etype)) {              \
-               var = (typeof(var))(entry);             \
-               WARN_ON(id && (entry)->type != id);     \
-               break;                                  \
+#define IF_ASSIGN(var, entry, etype, id)                       \
+       if (FTRACE_CMP_TYPE(var, etype)) {                      \
+               var = (typeof(var))(entry);                     \
+               WARN_ON(id != 0 && (entry)->type != id);        \
+               break;                                          \
        }

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

Wonder why GCC doesn't warn about this though.

-Wint-in-bool-context [BUG] linux [FIXED][LINUX] 5.4

Most helpful comment

All 8 comments

My bad, I was looking at old GCC's implementation of this warning :D

https://reviews.llvm.org/rL372708

I still see this warning after https://reviews.llvm.org/rL372708, is that intentional?

Yeah, gcc does not warn in this case, but g++ does.. probably just gcc's bug.

Aaron Ballman: "I think it's just a bug in GCC (they use separate frontends for C and C++, so these sort of differences crop up sometimes). I think this should be safe to diagnose the same in C and C++."
(https://reviews.llvm.org/D63082#1603952)

I will prepare that patch then.

Thanks

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nathanchance picture nathanchance  路  3Comments

tpgxyz picture tpgxyz  路  4Comments

tpimh picture tpimh  路  3Comments

tpimh picture tpimh  路  5Comments

nickdesaulniers picture nickdesaulniers  路  5Comments