From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:25146 "EHLO mx0b-00069f02.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230048AbhGVHrj (ORCPT ); Thu, 22 Jul 2021 03:47:39 -0400 Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 16M8PTBf022141 for ; Thu, 22 Jul 2021 08:28:14 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=date : from : to : cc : subject : message-id : references : content-type : in-reply-to : mime-version; s=corp-2021-07-09; bh=5db/KLObcwcooYk4H3zh04Uj/Av//MxjmjukLIWocvk=; b=xPsJ/E4Tt6lRJFlOue+ty/A8HtjOpw2bvPii/Fujm6RYSXLuAxsEsE4sdJnwo+gXw/Wz JTFEKRQKErsVkH+2/KqOjyKaU13G3FJldrVJnimF29Kjp3TuseCKQ9yQUJfT/6H5HwgN bNlqXIvI8ymFNR6gRbeLepYrhsDRLhBGy1KftGJD2AKPOW29WASlBXidaRqGelcBT74x ykfG3P84gtic4/VOXHoite4pRdKFCAxlPivBQSceTbIRi0hOKUbAYOGYEV60wFEpLFZ9 Q9LwId5H2M3Zg19s1PyPEttw2POFHI9XIO7Bmz0dUoJyxtpNhtdxgSZjJhD1hqe4lYRh BA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=date : from : to : cc : subject : message-id : references : content-type : in-reply-to : mime-version; s=corp-2020-01-29; bh=5db/KLObcwcooYk4H3zh04Uj/Av//MxjmjukLIWocvk=; b=oBAK1VS3Wu2Wd6oghRWot5JEyYtY63ZBQZVmW0aqCqO8aIl6kDtGz2y6lidPIT/chT1t ZYfa78uHLixUcerjOKjg69HtJvELX83gP+VsFpN3zXcDI3+bgO/vszzi4HGirD8k9syZ 4R7YHEMQ5QfjOr4PI8vKZZK0POSk1aTJ3Yo5Xum57f11FCkywIb/bjJAXwBF6e9Tzqrk 9YHzzk8xh1wZeMfBX+J9btfX6QHXQ8PRcLqHIBVL+5yIyz5e640740CDA7ImtlLLmyJY 0ztTOgbOMrS7Zj+Gh3xOvTvA5o4NicO4JGves3wwnZjg/1T1mw2WyNoD744mTRxPH389 xw== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by mx0b-00069f02.pphosted.com with ESMTP id 39xc6btyg5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 22 Jul 2021 08:28:14 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 16M8QRq9189505 for ; Thu, 22 Jul 2021 08:28:13 GMT Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2171.outbound.protection.outlook.com [104.47.56.171]) by userp3020.oracle.com with ESMTP id 39v9004fsn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 22 Jul 2021 08:28:13 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=5db/KLObcwcooYk4H3zh04Uj/Av//MxjmjukLIWocvk=; b=Q8rZqfMfppnjMrExzhkKiJAVUMpdR6YIZKrmxp2WqVJGthuALewwC+J01oUi4tLoTMhPEg7+8edqNs3SfcBbi3NR5Q11CONY+nGcBOQQNj4oWK0xBDmxBpqTlkfM2P8XsQe27ocnUmkaq5XiQnDVSBgzOpz92Dv4un+Lbq3HLL0= Date: Thu, 22 Jul 2021 11:27:53 +0300 From: Dan Carpenter Subject: Re: [PATCH] bits_clear and bits_set: Track bits cleared and set inside a function Message-ID: <20210722082753.GZ1931@kadam> References: <20210722081822.25454-1-harshvardhan.jha@oracle.com> Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210722081822.25454-1-harshvardhan.jha@oracle.com> MIME-Version: 1.0 List-ID: To: Harshvardhan Jha Cc: smatch@vger.kernel.org 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