linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: josh@joshtriplett.org
To: Dan Carpenter <dan.carpenter@oracle.com>
Cc: Hartley Sweeten <HartleyS@visionengravers.com>,
	"Marcos A. Di Pietro" <marcosadp@gmail.com>,
	"devel@driverdev.osuosl.org" <devel@driverdev.osuosl.org>,
	linux-sparse@vger.kernel.org
Subject: Re: [PATCH] Staging/comedi: Fixes static analysis warning raised by sparse
Date: Wed, 11 Jun 2014 14:45:29 -0700	[thread overview]
Message-ID: <20140611214529.GB16940@cloud> (raw)
In-Reply-To: <20140611212425.GW5015@mwanda>

On Thu, Jun 12, 2014 at 12:24:25AM +0300, Dan Carpenter wrote:
> Let's forward this to the Sparse mailing list.
> 
> We're seeing a Sparse false positive testing
> drivers/staging/comedi/drivers/ni_pcimio.c.
> 
>   CHECK   drivers/staging/comedi/drivers/ni_pcimio.c
> drivers/staging/comedi/drivers/ni_stc.h:720:26: warning: shift too big (4294967295) for type int
> drivers/staging/comedi/drivers/ni_stc.h:720:26: warning: shift too big (4294967295) for type int
> drivers/staging/comedi/drivers/ni_stc.h:720:26: warning: shift too big (4294967295) for type int
> drivers/staging/comedi/drivers/ni_stc.h:720:26: warning: shift too big (4294967295) for type int
> 
> I have created some test code to demonstrate the problem (attached).
> 
> The check_shift_count() warning is only supposed to be printed for
> number literals but because of the way inline functions are expanded it
> still complains even though channel is a variable.

Thanks for the test case; this definitely makes no sense.  I don't think
Sparse will suddenly develop enough range analysis or reachability
analysis to handle this case; I think the right answer is to avoid
giving such warnings for shifts with a non-constant RHS.

> #include <stdio.h>
> #include <limits.h>
> #include <string.h>
> 
> static inline unsigned ni_stc_dma_channel_select_bitfield(unsigned channel)
> {
> 	if (channel < 4)
> 		return 1 << channel;
> 	return 0;
> }
> 
> static inline void filter(int channel)
> {
> 	if (channel < 0)
> 		return;
> 	ni_stc_dma_channel_select_bitfield(channel);
> }
> 
> int main(void)
> {
> 	filter(-1);
> 
> 	return 0;
> }


  reply	other threads:[~2014-06-11 21:45 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <53965E53.5080504@gmail.com>
     [not found] ` <20140610054741.GE5500@mwanda>
     [not found]   ` <DC148C5AA1CEBA4E87973D432B1C2D8825E9AE6A@P3PWEX4MB008.ex4.secureserver.net>
     [not found]     ` <20140611065612.GQ5015@mwanda>
     [not found]       ` <DC148C5AA1CEBA4E87973D432B1C2D8825E9CBD6@P3PWEX4MB008.ex4.secureserver.net>
2014-06-11 21:24         ` [PATCH] Staging/comedi: Fixes static analysis warning raised by sparse Dan Carpenter
2014-06-11 21:45           ` josh [this message]
2014-06-15 19:32             ` Sam Ravnborg
2014-06-16  7:40               ` Dan Carpenter
2014-06-16  8:06                 ` Sam Ravnborg
2014-06-28 18:07             ` Christopher Li
2014-06-28 19:20               ` Josh Triplett
2014-06-29  3:09                 ` Christopher Li
2014-06-30 17:49                   ` Christopher Li
2014-06-30 18:32                     ` Christopher Li

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=20140611214529.GB16940@cloud \
    --to=josh@joshtriplett.org \
    --cc=HartleyS@visionengravers.com \
    --cc=dan.carpenter@oracle.com \
    --cc=devel@driverdev.osuosl.org \
    --cc=linux-sparse@vger.kernel.org \
    --cc=marcosadp@gmail.com \
    /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).