smatch.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: Harshvardhan Jha <harshvardhan.jha@oracle.com>
Cc: smatch@vger.kernel.org
Subject: Re: [PATCH] bits_clear and bits_set: Track bits cleared and set inside a function
Date: Thu, 22 Jul 2021 11:27:53 +0300	[thread overview]
Message-ID: <20210722082753.GZ1931@kadam> (raw)
In-Reply-To: <20210722081822.25454-1-harshvardhan.jha@oracle.com>

On Thu, Jul 22, 2021 at 01:48:22PM +0530, Harshvardhan Jha wrote:
> diff --git a/smatch.h b/smatch.h
> index 882e3927..bf88d887 100644
> --- a/smatch.h
> +++ b/smatch.h
> @@ -72,7 +72,7 @@ struct sm_state {
>  	unsigned short owner;
>  	unsigned short merged:1;
>  	unsigned int line;
> -  	struct smatch_state *state;
> +	struct smatch_state *state;
>  	struct stree *pool;
>  	struct sm_state *left;
>  	struct sm_state *right;
> @@ -302,8 +302,8 @@ do {                                                           \
>  		sm_printf("parse error: ");		       \
>  		sm_nr_errors++;				       \
>  	}						       \
> -        sm_printf(msg);                                        \
> -        sm_printf("\n");                                       \
> +	sm_printf(msg);					       \
> +	sm_printf("\n");				       \

These changes are correct but unrelated.

>  } while (0)
>  
>  #define sm_msg(msg...) do { sm_print_msg(0, msg); } while (0)
> @@ -848,6 +848,10 @@ enum info_type {
>  	FRESH_ALLOC	= 1044,
>  	ALLOCATOR	= 1045,
>  	FUNC_TIME	= 1047,
> +	BIT_SET		= 1051,
> +	BIT_CLEAR	= 1052,
> +	BIT_IS_SET	= 1053,
> +	BIT_IS_CLEAR	= 1054,
>  
>  	/* put random temporary stuff in the 7000-7999 range for testing */
>  	USER_DATA	= 8017,
> @@ -1317,6 +1321,15 @@ struct bit_info *alloc_bit_info(unsigned long long set, unsigned long long possi
>  struct smatch_state *alloc_bstate(unsigned long long set, unsigned long long possible);
>  struct smatch_state *merge_bstates(struct smatch_state *one_state, struct smatch_state *two_state);
>  
> +/* smatch_param_bits_set.c */
> +void __set_param_modified_helper(struct expression *expr, struct  smatch_state *state);
> +void __set_param_modified_helper_sym(const char *name, struct symbol *sym,
> +				     struct smatch_state *state);
> +
> +/* smatch_param_bits_clear.c */
> +void __set_param_modified_helper_clear(struct expression *expr, struct smatch_state *state);
> +void __set_param_modified_helper_sym_clear(const char *name, struct symbol *sym,
> +					   struct smatch_state *state);
>  
>  /* smatch_bit_info.c */
>  struct bit_info *rl_to_binfo(struct range_list *rl);
> diff --git a/smatch_bits.c b/smatch_bits.c
> index 2f92ecd7..555e2c14 100644
> --- a/smatch_bits.c
> +++ b/smatch_bits.c
> @@ -41,6 +41,17 @@ struct bit_info *alloc_bit_info(unsigned long long set, unsigned long long possi
>  	return bit_info;
>  }
>  
> +void set_bits_modified_expr(struct expression *expr, struct smatch_state *state)
> +{
> +	__set_param_modified_helper(expr, state);
> +	set_state_expr(my_id, expr, state);
> +}
> +
> +void set_bits_modified_expr_sym(const char *name, struct symbol *sym, struct smatch_state *state)
> +{
> +	__set_param_modified_helper_sym(name, sym, state);
> +	set_state(my_id, name, sym, state);
> +}
>  struct smatch_state *alloc_bstate(unsigned long long set, unsigned long long possible)
>  {
>  	struct smatch_state *state;
> @@ -151,7 +162,8 @@ static void match_modify(struct sm_state *sm, struct expression *mod_expr)
>  
>  	if (handled_by_assign_hook(mod_expr))
>  		return;
> -	set_state(my_id, sm->name, sm->sym, alloc_bstate(0, -1ULL));
> +
> +	set_bits_modified_expr_sym(sm->name, sm->sym, alloc_bstate(0, -1ULL));
>  }
>  
>  int binfo_equiv(struct bit_info *one, struct bit_info *two)
> @@ -247,9 +259,9 @@ struct bit_info *get_bit_info(struct expression *expr)
>  	sval_t known;
>  
>  	expr = strip_parens(expr);
> -
> -	if (get_implied_value(expr, &known))
> +	if (get_implied_value(expr, &known)) {
>  		return alloc_bit_info(known.value, known.value);
> +	}

Extra curly braces.

>  
>  	if (expr->type == EXPR_BINOP) {
>  		if (expr->op == '&')
> @@ -334,15 +346,17 @@ static void match_assign(struct expression *expr)
>  		if (is_unknown_binfo(get_type(expr->left), binfo))
>  			return;
>  
> -		set_state_expr(my_id, expr->left, alloc_bstate(binfo->set, binfo->possible));
> +		set_bits_modified_expr(expr->left, alloc_bstate(binfo->set, binfo->possible));
>  	} else if (expr->op == SPECIAL_OR_ASSIGN) {
>  		start = get_bit_info(expr->left);
>  		new = alloc_bstate(start->set | binfo->set, start->possible | binfo->possible);
> -		set_state_expr(my_id, expr->left, new);
> +		set_bits_modified_expr(expr->left, new);
> +
>  	} else if (expr->op == SPECIAL_AND_ASSIGN) {
>  		start = get_bit_info(expr->left);
>  		new = alloc_bstate(start->set & binfo->set, start->possible & binfo->possible);
> -		set_state_expr(my_id, expr->left, new);
> +		set_bits_modified_expr(expr->left, new);
> +
>  	}

No blank line before a curly brace.

>  }
>  
> @@ -369,7 +383,6 @@ static void match_condition(struct expression *expr)
>  
>  	true_info.possible &= right.uvalue;
>  	false_info.possible &= ~right.uvalue;
> -

Unrelated.

>  	set_true_false_states_expr(my_id, expr->left,
>  				   alloc_bstate(true_info.set, true_info.possible),
>  				   alloc_bstate(false_info.set, false_info.possible));
> @@ -454,7 +467,42 @@ static void set_param_bits(const char *name, struct symbol *sym, char *key, char

Just fix those few small things and resend.

regards,
dan carpenter

  reply	other threads:[~2021-07-22  7:47 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-22  8:18 [PATCH] bits_clear and bits_set: Track bits cleared and set inside a function Harshvardhan Jha
2021-07-22  8:27 ` Dan Carpenter [this message]
  -- strict thread matches above, loose matches on Subject: below --
2021-07-22  8:55 Harshvardhan Jha
2021-07-22  8:47 Harshvardhan Jha
2021-07-22  8:34 Harshvardhan Jha
2021-07-22  8:57 ` Dan Carpenter
2021-07-21 11:25 Harshvardhan Jha
2021-07-21 11:14 Harshvardhan Jha
2021-07-21 11:21 ` 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=20210722082753.GZ1931@kadam \
    --to=dan.carpenter@oracle.com \
    --cc=harshvardhan.jha@oracle.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).