Re: [PATCH -mm] -funsigned-char, x86: make struct p4_event_bind::cntr signed array

From: Alexey Dobriyan
Date: Fri Oct 21 2022 - 01:59:55 EST


On Thu, Oct 20, 2022 at 10:14:54AM -0700, Linus Torvalds wrote:
> On Thu, Oct 20, 2022 at 9:28 AM Jason A. Donenfeld <Jason@xxxxxxxxx> wrote:
> >
> > Nice catch.
> >
> > Reviewed-by: Jason A. Donenfeld <Jason@xxxxxxxxx>
>
> Can we please try to collect these all in one place?
>
> I see that Andrew picked up the original one for -mm, but I think it
> would be better if we had one specific place for all of this (one
> branch) to collect it all.
>
> I'm actually trying to do a "make allyesconfig" build on x86-64 with
> both signed and unsigned char, and trying to see if I can script
> something sane to show differences.

It is very entertaining, i've given up and started patching sparse
but it needs more because char constants are ints:


diff --git a/evaluate.c b/evaluate.c
index 61f59ee3..ab607581 100644
--- a/evaluate.c
+++ b/evaluate.c
@@ -321,6 +321,10 @@ static struct expression * cast_to(struct expression *old, struct symbol *type)
if (old->ctype != &null_ctype && is_same_type(old, type))
return old;

+ if (is_char_type(old->ctype)) {
+ sparse_error(old->pos, "XXX char");
+ }
+
expr = alloc_expression(old->pos, EXPR_IMPLIED_CAST);
expr->ctype = type;
expr->cast_type = type;
diff --git a/symbol.h b/symbol.h
index 5270fcd7..8e62aca2 100644
--- a/symbol.h
+++ b/symbol.h
@@ -455,6 +455,14 @@ static inline int is_byte_type(struct symbol *type)
return type->bit_size == bits_in_char && type->type != SYM_BITFIELD;
}

+static inline int is_char_type(const struct symbol *type)
+{
+ if (type->type == SYM_NODE) {
+ type = type->ctype.base_type;
+ }
+ return type == &char_ctype;
+}
+
static inline int is_wchar_type(struct symbol *type)
{
if (type->type == SYM_NODE)