On Tue, Sep 24, 2019 at 04:23:34PM -0700, Linus Torvalds wrote: > 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. Yes, I agree. Dan's patch is the obvious one solving the problem (expr->ctype adjusted too early) but yours should be equivalent since bit_size check is also done in cast_value(). I still need to run the tests tough. That being said, I think that using cast_value() is error-prone: expr's ctype should probably be changed there. but this will be in a separate patch anyway. > That simpler alternate patch attached, Thanks. -- Luc