public inbox for smatch@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] extra: Fixed handle_bit_test so that null set condition is taken care of
@ 2021-07-10 21:09 Harshvardhan Jha
  2021-07-12  6:21 ` Dan Carpenter
  0 siblings, 1 reply; 3+ messages in thread
From: Harshvardhan Jha @ 2021-07-10 21:09 UTC (permalink / raw)
  To: smatch; +Cc: dan.carpenter, Harshvardhan Jha

The handle_bit_test condition wasn't setting a false range_list for the
false state and hence the implied rl was coming out to be false. The
false and true rls have been calculating using rl_intersection and
rl_filter commands.

Signed-off-by: Harshvardhan Jha <harshvardhan.jha@oracle.com>
---
 smatch_extra.c        | 17 +++++++++--------
 validation/sm_bits2.c | 28 ++++++++++++++++++++++++++++
 2 files changed, 37 insertions(+), 8 deletions(-)
 create mode 100644 validation/sm_bits2.c

diff --git a/smatch_extra.c b/smatch_extra.c
index e864646a..27bf5a02 100644
--- a/smatch_extra.c
+++ b/smatch_extra.c
@@ -2061,7 +2061,7 @@ static void match_comparison(struct expression *expr)
 
 static bool handle_bit_test(struct expression *expr)
 {
-	struct range_list *orig_rl, *rl;
+	struct range_list *orig_rl, *rl, *true_rl, *false_rl;
 	struct expression *shift, *mask, *var;
 	struct bit_info *bit_info;
 	sval_t sval;
@@ -2083,23 +2083,24 @@ static bool handle_bit_test(struct expression *expr)
 	bit_info = get_bit_info(mask);
 	if (!bit_info)
 		return false;
-	if (!bit_info->possible)
+	if (!bit_info->possible){
+		set_true_false_states_expr(my_id, var, alloc_estate_empty(), NULL);
 		return false;
+	}
 
 	get_absolute_rl(var, &orig_rl);
 	if (sval_is_negative(rl_min(orig_rl)) ||
 	    rl_max(orig_rl).uvalue > type_bits(get_type(shift->left)))
 		return false;
 
-	low.value = ffsll(bit_info->possible);
-	high.value = sm_fls64(bit_info->possible);
+	low.value = ffsll(bit_info->possible) - 1;
+	high.value = sm_fls64(bit_info->possible) - 1;
 	rl = alloc_rl(low, high);
 	rl = cast_rl(get_type(var), rl);
-	rl = rl_intersection(orig_rl, rl);
-	if (!rl)
-		return false;
+	true_rl = rl_intersection(orig_rl, rl);
+	false_rl = rl_filter(orig_rl, rl);
 
-	set_extra_expr_true_false(shift->right, alloc_estate_rl(rl), NULL);
+	set_extra_expr_true_false(shift->right, alloc_estate_rl(true_rl), alloc_estate_rl(false_rl));
 
 	return true;
 }
diff --git a/validation/sm_bits2.c b/validation/sm_bits2.c
new file mode 100644
index 00000000..1a43538a
--- /dev/null
+++ b/validation/sm_bits2.c
@@ -0,0 +1,28 @@
+#include "../check_debug.h"
+
+unsigned int frob();
+
+void test(void)
+{
+	unsigned int mask = 0xff0;
+        unsigned int x = frob();
+
+	if (x < 4 || x > 11)
+		return;
+
+        if ((1 << x) & mask) {
+		__smatch_implied(x);
+                return;
+	}
+        __smatch_implied(x);
+}
+
+/*
+ * check-name: smatch bits 2
+ * check-command: smatch sm_bits2.c
+ *
+ * check-output-start
+sm_bits2.c:14 test() implied: x = '4-11'
+sm_bits2.c:17 test() implied: x = ''
+ * check-output-end
+ */
-- 
2.32.0

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] extra: Fixed handle_bit_test so that null set condition is taken care of
  2021-07-10 21:09 [PATCH] extra: Fixed handle_bit_test so that null set condition is taken care of Harshvardhan Jha
@ 2021-07-12  6:21 ` Dan Carpenter
  2021-07-12  6:36   ` Dan Carpenter
  0 siblings, 1 reply; 3+ messages in thread
From: Dan Carpenter @ 2021-07-12  6:21 UTC (permalink / raw)
  To: Harshvardhan Jha; +Cc: smatch

On Sun, Jul 11, 2021 at 02:39:49AM +0530, Harshvardhan Jha wrote:
> The handle_bit_test condition wasn't setting a false range_list for the
> false state and hence the implied rl was coming out to be false. The
> false and true rls have been calculating using rl_intersection and
> rl_filter commands.
> 

Also it fixes that off by one.  Thanks.

cat ../tmp/harshvardhan.jha | git am -s
Applying: extra: Fixed false output of handle_AND_op and handle_AND_condition
.git/rebase-apply/patch:125: trailing whitespace.
                return; 
warning: 1 line adds whitespace errors.
Applying: extra: Fixed handle_bit_test so that null set condition is taken care of

regards,
dan carpenter

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] extra: Fixed handle_bit_test so that null set condition is taken care of
  2021-07-12  6:21 ` Dan Carpenter
@ 2021-07-12  6:36   ` Dan Carpenter
  0 siblings, 0 replies; 3+ messages in thread
From: Dan Carpenter @ 2021-07-12  6:36 UTC (permalink / raw)
  To: Harshvardhan Jha; +Cc: smatch

On Mon, Jul 12, 2021 at 09:21:02AM +0300, Dan Carpenter wrote:
> On Sun, Jul 11, 2021 at 02:39:49AM +0530, Harshvardhan Jha wrote:
> > The handle_bit_test condition wasn't setting a false range_list for the
> > false state and hence the implied rl was coming out to be false. The
> > false and true rls have been calculating using rl_intersection and
> > rl_filter commands.
> > 
> 
> Also it fixes that off by one.  Thanks.
> 
> cat ../tmp/harshvardhan.jha | git am -s
> Applying: extra: Fixed false output of handle_AND_op and handle_AND_condition
> .git/rebase-apply/patch:125: trailing whitespace.
>                 return; 
> warning: 1 line adds whitespace errors.
> Applying: extra: Fixed handle_bit_test so that null set condition is taken care of

Sorry, when I read my sent message then it occured to me that this
email was kind of ambiguous.  I applied the patch so no need to resend.
The whitespace issue was in the testcase and it doesn't really matter.

regards,
dan carpenter

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-07-12  6:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-07-10 21:09 [PATCH] extra: Fixed handle_bit_test so that null set condition is taken care of Harshvardhan Jha
2021-07-12  6:21 ` Dan Carpenter
2021-07-12  6:36   ` Dan Carpenter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox