param_key: fix container of when no struct member is referenced
[smatch.git] / smatch_param_bits_clear.c
blob6632df81b1c6237b864d6303c075a23645b6a66c
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 "scope.h"
19 #include "smatch.h"
20 #include "smatch_slist.h"
21 #include "smatch_extra.h"
23 static int my_id;
25 static struct smatch_state *unmatched_state(struct sm_state *sm)
27 return alloc_bstate(-1ULL, -1ULL);
30 static void match_assign(struct expression *expr)
32 sval_t sval;
34 if (expr->type != EXPR_ASSIGNMENT)
35 return;
37 if (expr->op != SPECIAL_AND_ASSIGN)
38 return;
40 if (!get_implied_value(expr->right, &sval))
41 return;
43 set_state_expr(my_id, expr->left, alloc_bstate(0, sval.uvalue));
46 static void return_info_callback(int return_id, char *return_ranges,
47 struct expression *returned_expr,
48 int param,
49 const char *printed_name,
50 struct sm_state *sm)
52 unsigned long long bits_clear;
53 char buffer[64];
54 struct smatch_state *estate;
55 struct bit_info *binfo;
56 sval_t sval;
58 estate = get_state(SMATCH_EXTRA, sm->name, sm->sym);
59 if (estate_get_single_value(estate, &sval))
60 return;
62 binfo = sm->state->data;
63 bits_clear = binfo->possible;
65 if (bits_clear == 0)
66 return;
68 sprintf(buffer, "0x%llx", bits_clear);
69 sql_insert_return_states(return_id, return_ranges, BIT_CLEAR, param, printed_name, buffer);
72 struct smatch_state *merge_bstates_clear(struct smatch_state *one_state,
73 struct smatch_state *two_state)
75 struct bit_info *one, *two;
77 one = one_state->data;
78 two = two_state->data;
80 if (binfo_equiv(one, two))
81 return one_state;
83 return alloc_bstate(0, one->possible | two->possible);
86 void register_param_bits_clear(int id)
88 my_id = id;
90 set_dynamic_states(my_id);
91 add_hook(&match_assign, ASSIGNMENT_HOOK);
92 add_unmatched_state_hook(my_id, &unmatched_state);
93 add_merge_hook(my_id, &merge_bstates);
95 add_return_info_callback(my_id, return_info_callback);