Print this page
11506 smatch resync
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/tools/smatch/src/smatch_mtag_map.c
+++ new/usr/src/tools/smatch/src/smatch_mtag_map.c
1 1 /*
2 2 * Copyright (C) 2017 Oracle. All rights reserved.
3 3 *
4 4 * This program is free software; you can redistribute it and/or
5 5 * modify it under the terms of the GNU General Public License
6 6 * as published by the Free Software Foundation; either version 2
7 7 * of the License, or (at your option) any later version.
8 8 *
9 9 * This program is distributed in the hope that it will be useful,
10 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 * GNU General Public License for more details.
13 13 *
14 14 * You should have received a copy of the GNU General Public License
15 15 * along with this program; if not, see http://www.gnu.org/copyleft/gpl.txt
16 16 */
17 17
18 18 /*
19 19 * This basically stores when a pointer is stored as a struct member.
20 20 *
21 21 */
↓ open down ↓ |
21 lines elided |
↑ open up ↑ |
22 22
23 23 #include "smatch.h"
24 24 #include "smatch_slist.h"
25 25 #include "smatch_extra.h"
26 26
27 27 static int my_id;
28 28
29 29 static void match_assign(struct expression *expr)
30 30 {
31 31 struct expression *left, *right;
32 - mtag_t left_tag, right_tag;
32 + mtag_t left_tag;
33 33 int offset;
34 + sval_t sval;
34 35
35 36 if (expr->op != '=')
36 37 return;
37 38
38 39 left = strip_expr(expr->left);
39 40 right = strip_expr(expr->right);
40 41
41 - if (left->type != EXPR_DEREF)
42 + if (!type_is_ptr(get_type(right)))
42 43 return;
43 -
44 - offset = get_member_offset_from_deref(left);
45 - if (offset < 0)
44 + if (!get_implied_value(right, &sval))
46 45 return;
47 -
48 - if (!get_mtag(left->deref, &left_tag))
46 + if (sval_cmp(sval, valid_ptr_min_sval) < 0 ||
47 + sval_cmp(sval, valid_ptr_max_sval) > 0)
49 48 return;
50 - if (!get_mtag(right, &right_tag))
49 + if (sval.uvalue & MTAG_OFFSET_MASK)
51 50 return;
52 51
53 - sql_insert_mtag_map(right_tag, -offset, left_tag);
52 + if (!expr_to_mtag_offset(left, &left_tag, &offset))
53 + return;
54 +
55 + sql_insert_mtag_map(sval.uvalue, -offset, left_tag);
54 56 }
55 57
56 58 void register_mtag_map(int id)
57 59 {
58 60 my_id = id;
59 61
60 62 add_hook(&match_assign, ASSIGNMENT_HOOK);
61 63 add_hook(&match_assign, GLOBAL_ASSIGNMENT_HOOK);
62 64 }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX