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
19 #include "smatch_slist.h"
20 #include "smatch_extra.h"
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
)
33 if (expr
->type
!= EXPR_ASSIGNMENT
)
36 if (expr
->op
!= SPECIAL_AND_ASSIGN
)
39 if (!get_implied_value(expr
->right
, &sval
))
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
,
48 const char *printed_name
,
51 unsigned long long bits_clear
;
53 struct smatch_state
*estate
;
54 struct bit_info
*binfo
;
57 estate
= get_state(SMATCH_EXTRA
, sm
->name
, sm
->sym
);
58 if (estate_get_single_value(estate
, &sval
))
61 binfo
= sm
->state
->data
;
62 bits_clear
= binfo
->possible
;
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
))
82 return alloc_bstate(0, one
->possible
| two
->possible
);
85 void register_param_bits_clear(int 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
);