2016-11-17 09:39:15

by Christopher Li

[permalink] [raw]
Subject: Re: [PATCH] implement constant-folding in __builtin_bswap*()

On Thu, Aug 11, 2016 at 6:39 PM, Johannes Berg
<[email protected]> wrote:
> Since gcc does this, it's apparently valid to write
>
> switch (x) {
> case __builtin_bswap16(12):
> break;
> }
>
> but sparse will flag it as an error today.
>
> The constant folding used to be done in the kernel's htons() and
> friends, but due to gcc bugs that isn't done anymore since
> commit 7322dd755e7d ("byteswap: try to avoid __builtin_constant_p
> gcc bug").
>
> To get rid of the sparse errors on every such instance now, just
> add constant folding to __builtin_bswap*() in sparse.

Sorry for the really late review.

This looks good. I would like to apply it. Can you please add some
test case for the function prototype you introduced, just like the way
kernel use it?

Thanks

Chris