12 * GNU General Public License for more details.
13 *
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
16 */
17
18 /*
19 * This basically stores when a pointer is stored as a struct member.
20 *
21 */
22
23 #include "smatch.h"
24 #include "smatch_slist.h"
25 #include "smatch_extra.h"
26
27 static int my_id;
28
29 static void match_assign(struct expression *expr)
30 {
31 struct expression *left, *right;
32 mtag_t left_tag, right_tag;
33 int offset;
34
35 if (expr->op != '=')
36 return;
37
38 left = strip_expr(expr->left);
39 right = strip_expr(expr->right);
40
41 if (left->type != EXPR_DEREF)
42 return;
43
44 offset = get_member_offset_from_deref(left);
45 if (offset < 0)
46 return;
47
48 if (!get_mtag(left->deref, &left_tag))
49 return;
50 if (!get_mtag(right, &right_tag))
51 return;
52
53 sql_insert_mtag_map(right_tag, -offset, left_tag);
54 }
55
56 void register_mtag_map(int id)
57 {
58 my_id = id;
59
60 add_hook(&match_assign, ASSIGNMENT_HOOK);
61 add_hook(&match_assign, GLOBAL_ASSIGNMENT_HOOK);
62 }
|
12 * GNU General Public License for more details.
13 *
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
16 */
17
18 /*
19 * This basically stores when a pointer is stored as a struct member.
20 *
21 */
22
23 #include "smatch.h"
24 #include "smatch_slist.h"
25 #include "smatch_extra.h"
26
27 static int my_id;
28
29 static void match_assign(struct expression *expr)
30 {
31 struct expression *left, *right;
32 mtag_t left_tag;
33 int offset;
34 sval_t sval;
35
36 if (expr->op != '=')
37 return;
38
39 left = strip_expr(expr->left);
40 right = strip_expr(expr->right);
41
42 if (!type_is_ptr(get_type(right)))
43 return;
44 if (!get_implied_value(right, &sval))
45 return;
46 if (sval_cmp(sval, valid_ptr_min_sval) < 0 ||
47 sval_cmp(sval, valid_ptr_max_sval) > 0)
48 return;
49 if (sval.uvalue & MTAG_OFFSET_MASK)
50 return;
51
52 if (!expr_to_mtag_offset(left, &left_tag, &offset))
53 return;
54
55 sql_insert_mtag_map(sval.uvalue, -offset, left_tag);
56 }
57
58 void register_mtag_map(int id)
59 {
60 my_id = id;
61
62 add_hook(&match_assign, ASSIGNMENT_HOOK);
63 add_hook(&match_assign, GLOBAL_ASSIGNMENT_HOOK);
64 }
|