Print this page
11506 smatch resync
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/tools/smatch/src/smatch_real_absolute.c
+++ new/usr/src/tools/smatch/src/smatch_real_absolute.c
1 1 /*
2 2 * Copyright (C) 2015 Oracle.
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 * Say we have a line like:
20 20 * foo = bar / 8;
21 21 * Assume we don't know anything about bar. Well, now we know that foo is less
22 22 * than UINT_MAX / 8. Which might be useful, but it probably is misleading
23 23 * useless knowledge. Up to now we have ignored those but now we have said to
24 24 * store them.
25 25 *
26 26 * It also works if you have something like "foo = (int)(char)unknown_var;".
27 27 *
28 28 * I feel like this data doesn't have to be perfect, it just has to be better
29 29 * than nothing and that will help eliminate some false positives.
30 30 *
31 31 */
32 32
33 33 #include "smatch.h"
34 34 #include "smatch_slist.h"
35 35 #include "smatch_extra.h"
36 36
37 37 static int my_id;
38 38
39 39 static void pre_merge_hook(struct sm_state *sm)
40 40 {
41 41 struct smatch_state *abs;
42 42 struct smatch_state *extra;
43 43 struct range_list *rl;
44 44
45 45 extra = get_state(SMATCH_EXTRA, sm->name, sm->sym);
46 46 if (!extra || !estate_rl(extra))
47 47 return;
48 48 abs = get_state(my_id, sm->name, sm->sym);
49 49 if (!abs || !estate_rl(abs)) {
50 50 set_state(my_id, sm->name, sm->sym, clone_estate(extra));
51 51 return;
52 52 }
53 53 rl = rl_intersection(estate_rl(abs), estate_rl(extra));
54 54 set_state(my_id, sm->name, sm->sym, alloc_estate_rl(clone_rl(rl)));
55 55 }
56 56
57 57 static struct smatch_state *empty_state(struct sm_state *sm)
58 58 {
59 59 return alloc_estate_empty();
60 60 }
61 61
62 62 static void reset(struct sm_state *sm, struct expression *mod_expr)
63 63 {
64 64 set_state(my_id, sm->name, sm->sym, alloc_estate_whole(estate_type(sm->state)));
65 65 }
66 66
67 67 static int in_iterator_pre_statement(void)
68 68 {
69 69 struct statement *stmt;
70 70
71 71 /*
72 72 * we can't use __cur_stmt because that isn't set for
73 73 * iterator_pre_statement. Kind of a mess.
74 74 *
75 75 */
76 76
77 77 stmt = last_ptr_list((struct ptr_list *)big_statement_stack);
78 78
79 79 if (!stmt || !stmt->parent)
80 80 return 0;
81 81 if (stmt->parent->type != STMT_ITERATOR)
82 82 return 0;
83 83 if (stmt->parent->iterator_pre_statement != stmt)
84 84 return 0;
85 85 return 1;
86 86 }
87 87
88 88 static void match_assign(struct expression *expr)
89 89 {
90 90 struct range_list *rl;
91 91 struct symbol *type;
92 92 sval_t sval;
93 93
94 94 if (expr->op != '=')
95 95 return;
↓ open down ↓ |
95 lines elided |
↑ open up ↑ |
96 96 if (is_fake_call(expr->right))
97 97 return;
98 98 if (in_iterator_pre_statement())
99 99 return;
100 100
101 101 get_real_absolute_rl(expr->right, &rl);
102 102
103 103 type = get_type(expr->left);
104 104 if (!type)
105 105 return;
106 + if (type->type != SYM_PTR && type->type != SYM_BASETYPE &&
107 + type->type != SYM_ENUM)
108 + return;
106 109
107 110 rl = cast_rl(type, rl);
108 111 if (is_whole_rl(rl) && !get_state_expr(my_id, expr->left))
109 112 return;
110 113 /* These are handled by smatch_extra.c */
111 114 if (rl_to_sval(rl, &sval) && !get_state_expr(my_id, expr->left))
112 115 return;
113 116
114 117 set_state_expr(my_id, expr->left, alloc_estate_rl(clone_rl(rl)));
115 118 }
116 119
117 120 struct smatch_state *get_real_absolute_state(struct expression *expr)
118 121 {
119 122 return get_state_expr(my_id, expr);
120 123 }
↓ open down ↓ |
5 lines elided |
↑ open up ↑ |
121 124
122 125 struct smatch_state *get_real_absolute_state_var_sym(const char *name, struct symbol *sym)
123 126 {
124 127 return get_state(my_id, name, sym);
125 128 }
126 129
127 130 void register_real_absolute(int id)
128 131 {
129 132 my_id = id;
130 133
134 + set_dynamic_states(my_id);
131 135 add_pre_merge_hook(my_id, &pre_merge_hook);
132 136 add_unmatched_state_hook(my_id, &empty_state);
133 137 add_merge_hook(my_id, &merge_estates);
134 138 add_modification_hook(my_id, &reset);
135 139
136 140 add_hook(&match_assign, ASSIGNMENT_HOOK);
137 141 }
138 142
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX