From: Ramsay Jones <ramsay@ramsayjones.plus.com>
To: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>,
linux-sparse@vger.kernel.org
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
Bart Van Assche <bvanassche@acm.org>
Subject: Re: [PATCH 2/5] bitwise: accept all ones as non-restricted value
Date: Tue, 28 Jun 2022 00:32:02 +0100 [thread overview]
Message-ID: <1be25b6f-5065-f448-b6f0-9e6eaf077264@ramsayjones.plus.com> (raw)
In-Reply-To: <20220627190540.13358-3-luc.vanoostenryck@gmail.com>
On 27/06/2022 20:05, Luc Van Oostenryck wrote:
> Currently, the only value bitwise types can act on is 0
> because the this value is anyway invariant for all bitwise
s/the this/this/
s/anyway//
ATB,
Ramsay Jones
> operations and endianness conversions.
>
> But, a bit-pattern of all ones has the same properties and
> is also very often used.
>
> So, accept all ones as a valid value for bitwise operations.
>
> Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
> ---
> evaluate.c | 2 +-
> validation/bitwise-cast.c | 13 +++++++++++++
> 2 files changed, 14 insertions(+), 1 deletion(-)
>
> diff --git a/evaluate.c b/evaluate.c
> index 61f59ee3908e..bcbcdf1ef0cc 100644
> --- a/evaluate.c
> +++ b/evaluate.c
> @@ -417,7 +417,7 @@ static int restricted_value(struct expression *v, struct symbol *type)
> {
> if (v->type != EXPR_VALUE)
> return 1;
> - if (v->value != 0)
> + if (v->value != 0 && v->value != bits_mask(type->bit_size))
> return 1;
> return 0;
> }
> diff --git a/validation/bitwise-cast.c b/validation/bitwise-cast.c
> index 0583461cb745..1075a3e9410c 100644
> --- a/validation/bitwise-cast.c
> +++ b/validation/bitwise-cast.c
> @@ -35,6 +35,19 @@ static __be32 quuy(void)
> return (__attribute__((force)) __be32) 1730;
> }
>
> +/* Implicit casts of all ones, legal */
> +static __be32 foo1(void)
> +{
> + __be32 x = 0xffffffff;
> + return x;
> +}
> +
> +/* Explicit cast of all ones, legal */
> +static __be32 bar1(void)
> +{
> + return (__be32)0xffffffff;
> +}
> +
> /*
> * check-name: conversions to bitwise types
> * check-command: sparse -Wbitwise $file
next prev parent reply other threads:[~2022-06-27 23:35 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20220623180528.3595304-1-bvanassche@acm.org>
[not found] ` <20220623180528.3595304-52-bvanassche@acm.org>
[not found] ` <20220624045613.GA4505@lst.de>
[not found] ` <aa044f61-46f0-5f21-9b17-a1bb1ff9c471@acm.org>
[not found] ` <20220625092349.GA23530@lst.de>
[not found] ` <3eed7994-8de2-324d-c373-b6f4289a2734@acm.org>
2022-06-26 9:58 ` [PATCH 51/51] fs/zonefs: Fix sparse warnings in tracing code Luc Van Oostenryck
2022-06-26 15:42 ` Bart Van Assche
2022-06-26 16:24 ` Luc Van Oostenryck
2022-06-26 16:33 ` Linus Torvalds
2022-06-26 16:50 ` Linus Torvalds
2022-06-26 20:10 ` Luc Van Oostenryck
2022-06-26 19:44 ` Luc Van Oostenryck
2022-06-27 19:05 ` [PATCH 0/5] allow -1 and compares in bitwise types Luc Van Oostenryck
2022-06-27 19:05 ` [PATCH 1/5] bitwise: add testcases Luc Van Oostenryck
2022-06-27 19:05 ` [PATCH 2/5] bitwise: accept all ones as non-restricted value Luc Van Oostenryck
2022-06-27 23:32 ` Ramsay Jones [this message]
2022-06-27 19:05 ` [PATCH 3/5] bitwise: allow compares for bitwise types Luc Van Oostenryck
2022-06-27 19:20 ` Linus Torvalds
2022-06-27 23:34 ` Ramsay Jones
2022-06-27 19:05 ` [PATCH 4/5] bitwise: do not remove the signedness of " Luc Van Oostenryck
2022-06-27 19:05 ` [PATCH 5/5] bitwise: early expansion of simple constants Luc Van Oostenryck
2022-06-27 19:14 ` [PATCH 0/5] allow -1 and compares in bitwise types Linus Torvalds
2022-06-27 19:15 ` Bart Van Assche
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1be25b6f-5065-f448-b6f0-9e6eaf077264@ramsayjones.plus.com \
--to=ramsay@ramsayjones.plus.com \
--cc=bvanassche@acm.org \
--cc=linux-sparse@vger.kernel.org \
--cc=luc.vanoostenryck@gmail.com \
--cc=torvalds@linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).