Re: [for-linus][PATCH 01/10] tracing: Suppress sparse warnings triggered by is_signed_type()

From: Rasmus Villemoes
Date: Thu Aug 25 2022 - 03:57:35 EST


On 25/08/2022 02.40, Linus Torvalds wrote:
> On Wed, Aug 24, 2022 at 5:30 PM Linus Torvalds
> <torvalds@xxxxxxxxxxxxxxxxxxxx> wrote:
>>
>> Let me think about this.
>
> Actually, thinking about it, that was simple enough.
>
> -#define is_signed_type(type) (((type)(-1)) < (type)1)
> +#define is_signed_type(type) (((type)(-1)) < (__force type)1)
>
> should work.
>
> It looks a bit odd, because we only force one side.

One can also make the RHS not be a null pointer constant with something like

(((t)(-1)) <= (1 ? (t)0 : (t)0))

In either case, we're a good way into "this needs a comment explaining
why it's written precisely the way it is" territory.

Rasmus