struct_assignment: add copy_from_user()
[smatch.git] / smatch_param_bits_clear.c
blob9145a51b7f433e8b08ee32425d3dc7e02787225f
1 /*
2 * Copyright (C) 2021 Oracle
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, see http://www.gnu.org/copyleft/gpl.txt
18 #include "smatch.h"
19 #include "smatch_slist.h"
20 #include "smatch_extra.h"
22 static int my_id;
24 static struct smatch_state *unmatched_state(struct sm_state *sm)
26 return alloc_bstate(-1ULL, -1ULL);
29 static void match_assign(struct expression *expr)
31 sval_t sval;
33 if (expr->type != EXPR_ASSIGNMENT)
34 return;
36 if (expr->op != SPECIAL_AND_ASSIGN)
37 return;
39 if (!get_implied_value(expr->right, &sval))
40 return;
42 set_state_expr(my_id, expr->left, alloc_bstate(0, sval.uvalue));
45 static void return_info_callback(int return_id, char *return_ranges,
46 struct expression *returned_expr,
47 int param,
48 const char *printed_name,
49 struct sm_state *sm)
51 unsigned long long bits_clear;
52 char buffer[64];
53 struct smatch_state *estate;
54 struct bit_info *binfo;
55 sval_t sval;
57 estate = get_state(SMATCH_EXTRA, sm->name, sm->sym);
58 if (estate_get_single_value(estate, &sval))
59 return;
61 binfo = sm->state->data;
62 bits_clear = binfo->possible;
64 if (bits_clear == 0)
65 return;
67 sprintf(buffer, "0x%llx", bits_clear);
68 sql_insert_return_states(return_id, return_ranges, BIT_CLEAR, param, printed_name, buffer);
71 struct smatch_state *merge_bstates_clear(struct smatch_state *one_state,
72 struct smatch_state *two_state)
74 struct bit_info *one, *two;
76 one = one_state->data;
77 two = two_state->data;
79 if (binfo_equiv(one, two))
80 return one_state;
82 return alloc_bstate(0, one->possible | two->possible);
85 void register_param_bits_clear(int id)
87 my_id = id;
89 set_dynamic_states(my_id);
90 add_hook(&match_assign, ASSIGNMENT_HOOK);
91 add_unmatched_state_hook(my_id, &unmatched_state);
92 add_merge_hook(my_id, &merge_bstates);
94 add_return_info_callback(my_id, return_info_callback);