All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: Toomas Soome <tsoome@me.com>
Cc: smatch@vger.kernel.org
Subject: Re: smatch: misreported 'mask and shift to zero'
Date: Tue, 11 Feb 2020 17:46:02 +0300	[thread overview]
Message-ID: <20200211144602.GH1778@kadam> (raw)
In-Reply-To: <D0BDD9FD-1792-4334-8EF7-55E296D55214@me.com>



On Wed, Feb 05, 2020 at 08:52:16AM +0200, Toomas Soome wrote:
> hi!
> 
> The smatch check with illumos code has warning:
> 
> /code/illumos-gate/usr/src/tools/proto/root_sparc-nd/opt/onbld/bin/sparc/smatch: /code/illumos-gate/usr/src/common/bignum/bignumimpl.c:1410 big_mul_add_vec() warn: mask and shift to zero
> 
> The code itself is perfectly legal:
> 
> http://src.illumos.org/source/xref/illumos-gate/usr/src/common/bignum/bignumimpl.c#1410
> 

The problem is that Smatch doesn't handle loops correctly.  The test is
looking for places which do:

	y = (y & 0xff) >> 8;
                 ^^^^     ^

It only cares about these two values.

The problem is that Smatch only parses loops one time.  The canonical
loops are handled so it knows that inside the loop i is in the range
"0 to len - 1".  But it doesn't know that cy1 is changed.  Smatch is
correct that "(cy1 >> (BIG_CHUNK_SIZE / 2))" is going to be zero on the
first iteration but on the second iteration that's not true so it
shouldn't print a warning.

One way to fix this is to use the diff below.  The difference is that
get_value() only considers literals and get_implied_value() looks at
variables as well.  I think in real life the mask value is always a
literal.

regards,
dan carpenter

diff --git a/check_shift_to_zero.c b/check_shift_to_zero.c
index 019b06fb..3552fe87 100644
--- a/check_shift_to_zero.c
+++ b/check_shift_to_zero.c
@@ -58,7 +58,7 @@ static void match_binop2(struct expression *expr)
 
 	if (!get_implied_value(expr->right, &shift))
 		return;
-	if (!get_implied_value(left->right, &mask))
+	if (!get_value(left->right, &mask))
 		return;
 
 	if (mask.uvalue >> shift.uvalue)

      reply	other threads:[~2020-02-11 14:46 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-05  6:52 smatch: misreported 'mask and shift to zero' Toomas Soome
2020-02-11 14:46 ` Dan Carpenter [this message]

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=20200211144602.GH1778@kadam \
    --to=dan.carpenter@oracle.com \
    --cc=smatch@vger.kernel.org \
    --cc=tsoome@me.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.