[PATCH v2] tracing: Make is_signed_type() compatible with sparse
From: Bart Van Assche
Date: Fri Aug 07 2026 - 13:01:23 EST
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/20220717151047.19220-1-bvanassche@xxxxxxx/
Cc: Christoph Hellwig <hch@xxxxxx>
Cc: Rasmus Villemoes <linux@xxxxxxxxxxxxxxxxxx>
Cc: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx>
Cc: Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx>
Signed-off-by: Bart Van Assche <bvanassche@xxxxxxx>
---
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))
/*