From: Toomas Soome <tsoome@me.com>
To: smatch@vger.kernel.org
Subject: smatch: misreported 'mask and shift to zero'
Date: Wed, 5 Feb 2020 08:52:16 +0200 [thread overview]
Message-ID: <D0BDD9FD-1792-4334-8EF7-55E296D55214@me.com> (raw)
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
Investigating the issue, I think, I have found the issue:
match_binop2() is testing expressions having the form: (mask & value) >> shift
and the failure case is 'variable >> shift’.
What does happen is, we get incoming expression set to: '(mask & ) >> shift’
and the mask value is not correct.
In our specific error case we do have 64-bit lhs for >> operator, and we do shift 32 bits; the mask value is set to 0xFFFFFFFF, and shifting it by 32 bits, we do end up with match_binop2() reporting the warning.
Since this incoming expression is missing rhs for & expression, the fix is also obvious - add check to make sure we do have both hands for & expression.
diff --git a/usr/src/tools/smatch/src/check_shift_to_zero.c b/usr/src/tools/smatch/src/check_shift_to_zero.c
index 019b06fb75..14cfdc2258 100644
--- a/usr/src/tools/smatch/src/check_shift_to_zero.c
+++ b/usr/src/tools/smatch/src/check_shift_to_zero.c
@@ -44,7 +44,7 @@ static void match_binop2(struct expression *expr)
{
struct expression *left;
struct expression *tmp;
- sval_t mask, shift;
+ sval_t value, mask, shift;
if (expr->op != SPECIAL_RIGHTSHIFT)
return;
@@ -58,6 +58,13 @@ static void match_binop2(struct expression *expr)
if (!get_implied_value(expr->right, &shift))
return;
+ /*
+ * The LHS for expr is assumed to be (mask & value), make sure
+ * we do have both hands.
+ */
+ if (!get_implied_value(left->left, &value))
+ return;
+
if (!get_implied_value(left->right, &mask))
return;
thanks,
toomas
next reply other threads:[~2020-02-05 6:52 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-05 6:52 Toomas Soome [this message]
2020-02-11 14:46 ` smatch: misreported 'mask and shift to zero' Dan Carpenter
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=D0BDD9FD-1792-4334-8EF7-55E296D55214@me.com \
--to=tsoome@me.com \
--cc=smatch@vger.kernel.org \
/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 read-only IMAP folder(s) and NNTP newsgroup(s).