On Tue, Sep 24, 2019 at 12:09 AM Dan Carpenter <dan.carpenter@xxxxxxxxxx> wrote: > > The problem is the sign isn't extended properly when this casts an int > to a long. The expr->ctype has to be the original int ctype for the > cast_value() call so that the "value = get_longlong(old);" expansion > works correctly. What happens if you just remove the if (ctype->bit_size == base_type->bit_size) { expr->ctype = base_type; continue; } part entirely? IOW, leave just cast_value(expr, base_type, expr, ctype); expr->ctype = base_type; in place unconditionally? I _think- that should be the simpler correct fix, but I'll leave it to Luc to think about it more. That simpler alternate patch attached, Linus
parse.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/parse.c b/parse.c index f291e247..b01c876e 100644 --- a/parse.c +++ b/parse.c @@ -897,10 +897,8 @@ static void cast_enum_list(struct symbol_list *list, struct symbol *base_type) expr->ctype = &int_ctype; continue; } - expr->ctype = base_type; - if (ctype->bit_size == base_type->bit_size) - continue; cast_value(expr, base_type, expr, ctype); + expr->ctype = base_type; } END_FOR_EACH_PTR(sym); }