Re: [PATCH] sparse: fix bogus shift too big warning when rhs is a variable

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

 



Still catching up my emails.

On Mon, Jun 16, 2014 at 10:10 AM, Sam Ravnborg <sam@xxxxxxxxxxxx> wrote:
> sparse warned about "shift too big" if the rhs was a variable.
> As sparse usually cannot deduct the value of a variable
> silence these warnings.

That is very strange. It should not happen.
>
> Before this patch following code snippet would generate a warning:
>
> static int doshift(int foo)
> {
>         return 1 << foo;
> }
>
> sparse did not know the value of 'foo' so reported a warning.
> Ignore the warning expect in the cases where the rhs of the shift
> is a constant.

That is strange. I can't duplicate the bug with your test case:
With tip of chrisl repository,
I get the following error with your test case:
./sparse /tmp/b.c
/tmp/b.c:3:18: warning: shift too big (1000) for type int
/tmp/b.c:8:22: warning: shift too big (1000) for type unsigned int


>
> diff --git a/expand.c b/expand.c
> index 0f6720c..ce955d3 100644
> --- a/expand.c
> +++ b/expand.c
> @@ -187,7 +187,7 @@ static int simplify_int_binop(struct expression *expr, struct symbol *ctype)
>                 return 0;
>         r = right->value;
>         if (expr->op == SPECIAL_LEFTSHIFT || expr->op == SPECIAL_RIGHTSHIFT) {
> -               if (r >= ctype->bit_size) {
> +               if (right->flags & Int_const_expr && r >= ctype->bit_size) {


This does not explain why it fix the bug. In simplify_int_binop()
There is the code check for this is constant expr on rhs. The non
constant value should just bail out early.

    if (right->type != EXPR_VALUE)
        return 0;

That is right before your change. Plus I can't duplicate the bug myself.

I suspect there is something else going on. Any way to help me reproduce
the bug?

I am using gcc 4.8.2 on x86_64.

Chris
--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[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