From patchwork Sun Jun 15 19:32:27 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Ravnborg X-Patchwork-Id: 4354781 Return-Path: X-Original-To: patchwork-linux-sparse@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 38F93BEEAA for ; Sun, 15 Jun 2014 19:41:09 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0E212201D3 for ; Sun, 15 Jun 2014 19:41:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 17571201C8 for ; Sun, 15 Jun 2014 19:41:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751176AbaFOTlF (ORCPT ); Sun, 15 Jun 2014 15:41:05 -0400 Received: from asavdk3.altibox.net ([109.247.116.14]:44946 "EHLO asavdk3.altibox.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750993AbaFOTlE (ORCPT ); Sun, 15 Jun 2014 15:41:04 -0400 X-Greylist: delayed 511 seconds by postgrey-1.27 at vger.kernel.org; Sun, 15 Jun 2014 15:41:04 EDT Received: from localhost (localhost [127.0.0.1]) by asavdk3.altibox.net (Postfix) with ESMTP id 1FBBC20023; Sun, 15 Jun 2014 21:32:30 +0200 (CEST) Received: from asavdk3.altibox.net ([127.0.0.1]) by localhost (asavdk3.lysetele.net [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 6jdR5EN7_cUX; Sun, 15 Jun 2014 21:32:29 +0200 (CEST) Received: from ravnborg.org (unknown [188.228.89.252]) (using TLSv1.2 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) by asavdk3.altibox.net (Postfix) with ESMTPS id 2556D20022; Sun, 15 Jun 2014 21:32:29 +0200 (CEST) Date: Sun, 15 Jun 2014 21:32:27 +0200 From: Sam Ravnborg To: josh@joshtriplett.org Cc: Dan Carpenter , Hartley Sweeten , "Marcos A. Di Pietro" , "devel@driverdev.osuosl.org" , linux-sparse@vger.kernel.org Subject: Re: [PATCH] Staging/comedi: Fixes static analysis warning raised by sparse Message-ID: <20140615193227.GA24515@ravnborg.org> References: <53965E53.5080504@gmail.com> <20140610054741.GE5500@mwanda> <20140611065612.GQ5015@mwanda> <20140611212425.GW5015@mwanda> <20140611214529.GB16940@cloud> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20140611214529.GB16940@cloud> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Hi Josh. On Wed, Jun 11, 2014 at 02:45:29PM -0700, josh@joshtriplett.org wrote: > 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. Something like the appended? It seems to work for me - and it cured a lot of warnings in math-emu.c on sparc. If it looks OK I will do a proper patch submission. Sam --- To unsubscribe from this list: send the line "unsubscribe linux-sparse" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/expand.c b/expand.c index 0f6720c..4a96de4 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 (expr->flags & Int_const_expr && r >= ctype->bit_size) { if (conservative) return 0; r = check_shift_count(expr, ctype, r);