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
20 #include "smatch_slist.h"
21 #include "smatch_extra.h"
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
)
34 if (expr
->type
!= EXPR_ASSIGNMENT
)
37 if (expr
->op
!= SPECIAL_AND_ASSIGN
)
40 if (!get_implied_value(expr
->right
, &sval
))
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
,
49 const char *printed_name
,
52 unsigned long long bits_clear
;
54 struct smatch_state
*estate
;
55 struct bit_info
*binfo
;
58 estate
= get_state(SMATCH_EXTRA
, sm
->name
, sm
->sym
);
59 if (estate_get_single_value(estate
, &sval
))
62 binfo
= sm
->state
->data
;
63 bits_clear
= binfo
->possible
;
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
))
83 return alloc_bstate(0, one
->possible
| two
->possible
);
86 void register_param_bits_clear(int 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
);