Re: [PATCH v7 1/4] bitops: Introduce the the for_each_set_clump macro

Andy Shevchenko
2020-06-03T08:49:56Z

On Tue, Jun 2, 2020 at 10:01 PM Rikard Falkeborn
<rikard.falkeborn@gmail.com> wrote:
> On Mon, Jun 01, 2020 at 11:33:30AM +0300, Andy Shevchenko wrote:
> > On Mon, Jun 01, 2020 at 12:37:16AM +0200, Rikard Falkeborn wrote:
> > > On Sun, May 31, 2020 at 02:00:45PM +0300, Andy Shevchenko wrote:

...

> > > If we cast to int, we don't need to worry about the signedness. If
> > > someone enters a value that can't be cast to int, there will still
> > > be a compiler warning about shift out of range.
> >
> > If the argument unsigned long long will it be the warning (it should not)?
>
> No, there should be no warning there.
>
> The inputs to GENMASK() needs to be between 0 and 31 (or 63 depending on the
> size of unsigned long). For any other values, there will be undefined behaviour,
> since the operands to the shifts in __GENMASK will be too large (or negative).

What I'm implying here that argument may be not constant, and compiler
can't know their values at hand.
So, in the following snippet

foo(unsigned long long x)
{
u32 y;
y = GENMASK(x, 0);
}

when you cast x to int wouldn't be a warning of possible value
reduction (even if we know that it won't be higher than 63/31)?

--
With Best Regards,
Andy Shevchenko