Re: [for-linus][PATCH 01/10] tracing: Suppress sparse warnings triggered by is_signed_type()
From: Linus Torvalds
Date: Wed Aug 24 2022 - 20:40:40 EST
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.
But we only need to force one side, because the '-1' doesn't have any
issues with bitwise types, the same way 0 doesn't.
So only '1' needs to be force-cast to avoid a warning about casting an
integer to a bitwise type.
And since that -1 counts as an unrestricted value after a cast, now
the ordered comparison doesn't warn either.
Now, admittedly I think sparse should also allow a forced cast of an
unrestricted value to be unrestricted, so I think I should do this
static int restricted_value(struct expression *v, struct symbol *type)
{
- if (v->type == EXPR_CAST)
+ if (v->type == EXPR_CAST || v->type = EXPR_FORCE_CAST)
v = v->cast_expression;
in sparse, but even without that the above "is_signed_type()" macro
should make sparse happy (with that current tree of mine).
And since we don't now need to cast 0, gcc won't complain about that
NULL pointer comparison.
Does that solve things for you?
Linus