Re: [PATCH v2] tracing: Make is_signed_type() compatible with sparse

From: David Laight

Date: Mon Aug 31 2026 - 17:18:11 EST


On Fri, 7 Aug 2026 10:00:56 -0700
Bart Van Assche <bvanassche@xxxxxxx> wrote:

> 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.

Does adding __force to the LH cast remove the warning?
Is so that would be a much better fix.

David

>
> 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))
>
> /*
>