[PATCH v2] tracing: Make is_signed_type() compatible with sparse
Bart Van Assche <[email protected]>
| Newsgroups | gmane.linux.kernel |
|---|---|
| Message-ID | <bde573c1a758505339239f08be28788a34dfcb73.1786121949.git.bvanassche@acm.org> |
Using a __bitwise type in a tracing __field() definition triggers four sparse warnings in stage 4 of expanding the TRACE_EVENT() macro. These warnings are triggered by the is_signed_type() macro implementation. Fix this by using _Generic() in the is_signed_type() implementation instead of an integer comparison. An earlier attempt to fix this issue is available here: https://lore.kernel.org/all/[email protected]/ Cc: Christoph Hellwig <[email protected]> Cc: Rasmus Villemoes <[email protected]> Cc: Luc Van Oostenryck <[email protected]> Cc: Linus Torvalds <[email protected]> Signed-off-by: Bart Van Assche <[email protected]> --- Changes compared to v1: removed #ifdef __CHECKER__. include/linux/compiler.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/include/linux/compiler.h b/include/linux/compiler.h index cb2f6050bdf7..ba9c7e16802d 100644 --- a/include/linux/compiler.h +++ b/include/linux/compiler.h @@ -326,7 +326,14 @@ static inline void *offset_to_ptr(const int *off) * Whether 'type' is a signed type or an unsigned type. Supports scalar types, * bool and also pointer types. */ -#define is_signed_type(type) (((type)(-1)) < (__force type)1) +#define is_signed_type(type) _Generic((type)0, \ + signed char: true, \ + signed short: true, \ + signed int: true, \ + signed long: true, \ + signed long long: true, \ + char: ((char)-1 < (char)1), \ + default: false) #define is_unsigned_type(type) (!is_signed_type(type)) /*