Re: [PATCH] Simplify shift operations on constants

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

 



On Sun, 2019-03-03T00:20+0100, Luc Van Oostenryck wrote:
> On Sat, Mar 02, 2019 at 11:34:15PM +0100, Thomas Weißschuh wrote:
> > 
> > I'm actually not sure how to proceed.
> > Should I integrate Linus' fix, your description and my test and resend them, or
> > do you want to do it?
> 
> It's fine, thanks. I've taken Linus' version, adapted my description,
> renamed you test and added another test. I'm proposing to push the
> patch here under.

Thanks! Sounds good to me.

(A few minor notes below).

Thomas

> From 83cfb92761f4602bc08aa4be6fd9834a3b98d5e3 Mon Sep 17 00:00:00 2001
> 
> During the expansion of shifts, the variable 'conservative' is used
> to inhibit any possible diagnostics (for example, because he needed
Typo:                                                       ^^ the
> information is if the expression is a constant or not).

The explanation about 'conservative' would be nice as a comment in the source.
I misunderstood its meaning before.
(Probably because I looked at the place where it was used to actually change
behaviour)

> ---
>  expand.c                      | 23 ++++++++-----
>  validation/constexpr-shift.c  | 12 +++++++
>  validation/expand/bad-shift.c | 64 +++++++++++++++++++++++++++++++++++
>  3 files changed, 91 insertions(+), 8 deletions(-)
>  create mode 100644 validation/constexpr-shift.c
>  create mode 100644 validation/expand/bad-shift.c
> 
> diff --git a/expand.c b/expand.c
> index e8e50b080..95f9fda63 100644
> --- a/expand.c
> +++ b/expand.c
> @@ -158,19 +158,14 @@ Float:
>  	expr->type = EXPR_FVALUE;
>  }
>  
> -static void check_shift_count(struct expression *expr, struct expression *right)
> +static void warn_shift_count(struct expression *expr, struct symbol *ctype, long long count)

The 'struct symbol *ctype' could be 'const', after adapting the signatures of
the functions called with it.
If you want I can send a patch after this went in.

>  {
> -	struct symbol *ctype = expr->ctype;
> -	long long count = get_longlong(right);
> -
>  	if (count < 0) {
>  		if (!Wshift_count_negative)
>  			return;
>  		warning(expr->pos, "shift count is negative (%lld)", count);
>  		return;
>  	}
> -	if (count < ctype->bit_size)
> -		return;
>  	if (ctype->type == SYM_NODE)
>  		ctype = ctype->ctype.base_type;



[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