Re: [PATCH 2/5] bitwise: accept all ones as non-restricted value

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




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@xxxxxxxxx>
> ---
>  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



[Index of Archives]     [Newbies FAQ]     [LKML]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Trinity Fuzzer Tool]

  Powered by Linux