Re: [PATCH v1 09/48] perf tests: Silence -Wshorten-64-to-32 warnings

From: David Laight
Date: Wed Apr 02 2025 - 18:01:38 EST


On Wed, 2 Apr 2025 17:38:07 +0100
Leo Yan <leo.yan@xxxxxxx> wrote:

> Hi Ian,
...
> If we use casts just to silence warnings, we also lose the opportunity
> to improve code quality. The changes in this series that fix type
> mismatches are good, but I think the use of casts is not particularly
> helpful - we're simply switching from implicit compiler casts to
> explicit ones.

It is certainly my experience (a lot of years) that casts between
integers of different sizes just make code harder to read and possibly
even more buggy.

If the compiler really knew the valid range of the value (rather than
just the type) then perhaps a warning that significant bits were being
discarded might be more reasonable.
But even then you don't want anything for code like:
hi_32 = val_64 >> 32;
lo_32 = val_64;

David