94 struct bit_info *p;
95
96 estate = get_state(SMATCH_EXTRA, sm->name, sm->sym);
97 if (estate_rl(estate)) {
98 p = rl_to_binfo(estate_rl(estate));
99 return alloc_bstate(p->set, p->possible);
100 }
101
102 type = estate_type(estate);
103 if (!type)
104 return alloc_bstate(0, -1ULL);
105
106 if (type_bits(type) == 64)
107 possible = -1ULL;
108 else
109 possible = (1ULL << type_bits(type)) - 1;
110
111 return alloc_bstate(0, possible);
112 }
113
114 static void match_modify(struct sm_state *sm, struct expression *mod_expr)
115 {
116 // FIXME: we really need to store the type
117
118 set_state(my_id, sm->name, sm->sym, alloc_bstate(0, -1ULL));
119 }
120
121 static int binfo_equiv(struct bit_info *one, struct bit_info *two)
122 {
123 if (one->set == two->set &&
124 one->possible == two->possible)
125 return 1;
126 return 0;
127 }
128
129 static struct smatch_state *merge_bstates(struct smatch_state *one_state, struct smatch_state *two_state)
130 {
131 struct bit_info *one, *two;
132
133 one = one_state->data;
134 two = two_state->data;
135
136 if (binfo_equiv(one, two))
137 return one_state;
266 }
267
268 static void match_compare(struct expression *expr)
269 {
270 sval_t val;
271
272 if (expr->type != EXPR_COMPARE)
273 return;
274 if (expr->op != SPECIAL_EQUAL &&
275 expr->op != SPECIAL_NOTEQUAL)
276 return;
277
278 if (!get_implied_value(expr->right, &val))
279 return;
280
281 set_true_false_states_expr(my_id, expr->left,
282 (expr->op == SPECIAL_EQUAL) ? alloc_bstate(val.uvalue, val.uvalue) : NULL,
283 (expr->op == SPECIAL_EQUAL) ? NULL : alloc_bstate(val.uvalue, val.uvalue));
284 }
285
286 static bool is_loop_iterator(struct expression *expr)
287 {
288 struct statement *pre_stmt, *loop_stmt;
289
290 pre_stmt = expr_get_parent_stmt(expr);
291 if (!pre_stmt || pre_stmt->type != STMT_EXPRESSION)
292 return false;
293
294 loop_stmt = stmt_get_parent_stmt(pre_stmt);
295 if (!loop_stmt || loop_stmt->type != STMT_ITERATOR)
296 return false;
297 if (loop_stmt->iterator_pre_statement != pre_stmt)
298 return false;
299
300 return true;
301 }
302
303 static void match_assign(struct expression *expr)
304 {
305 struct bit_info *binfo;
306
307 if (expr->op != '=')
308 return;
309 if (__in_fake_assign)
310 return;
311 if (is_loop_iterator(expr))
312 return;
313
314 binfo = get_bit_info(expr->right);
315 if (!binfo)
316 return;
317 if (is_unknown_binfo(get_type(expr->left), binfo))
318 return;
319 set_state_expr(my_id, expr->left, alloc_bstate(binfo->set, binfo->possible));
320 }
321
322 static void match_condition(struct expression *expr)
323 {
324 struct bit_info *orig;
325 struct bit_info true_info;
326 struct bit_info false_info;
327 sval_t right;
328
329 if (expr->type != EXPR_BINOP ||
330 expr->op != '&')
331 return;
332
333 if (!get_value(expr->right, &right))
334 return;
335
336 orig = get_bit_info(expr->left);
337 true_info = *orig;
338 false_info = *orig;
339
|
94 struct bit_info *p;
95
96 estate = get_state(SMATCH_EXTRA, sm->name, sm->sym);
97 if (estate_rl(estate)) {
98 p = rl_to_binfo(estate_rl(estate));
99 return alloc_bstate(p->set, p->possible);
100 }
101
102 type = estate_type(estate);
103 if (!type)
104 return alloc_bstate(0, -1ULL);
105
106 if (type_bits(type) == 64)
107 possible = -1ULL;
108 else
109 possible = (1ULL << type_bits(type)) - 1;
110
111 return alloc_bstate(0, possible);
112 }
113
114 static bool is_loop_iterator(struct expression *expr)
115 {
116 struct statement *pre_stmt, *loop_stmt;
117
118 pre_stmt = expr_get_parent_stmt(expr);
119 if (!pre_stmt || pre_stmt->type != STMT_EXPRESSION)
120 return false;
121
122 loop_stmt = stmt_get_parent_stmt(pre_stmt);
123 if (!loop_stmt || loop_stmt->type != STMT_ITERATOR)
124 return false;
125 if (loop_stmt->iterator_pre_statement != pre_stmt)
126 return false;
127
128 return true;
129 }
130
131 static bool handled_by_assign_hook(struct expression *expr)
132 {
133 if (!expr || expr->type != EXPR_ASSIGNMENT)
134 return false;
135 if (__in_fake_assign)
136 return false;
137 if (is_loop_iterator(expr))
138 return false;
139
140 if (expr->op == '=' ||
141 expr->op == SPECIAL_OR_ASSIGN ||
142 expr->op == SPECIAL_AND_ASSIGN)
143 return true;
144
145 return false;
146 }
147
148 static void match_modify(struct sm_state *sm, struct expression *mod_expr)
149 {
150 // FIXME: we really need to store the type
151
152 if (handled_by_assign_hook(mod_expr))
153 return;
154 set_state(my_id, sm->name, sm->sym, alloc_bstate(0, -1ULL));
155 }
156
157 static int binfo_equiv(struct bit_info *one, struct bit_info *two)
158 {
159 if (one->set == two->set &&
160 one->possible == two->possible)
161 return 1;
162 return 0;
163 }
164
165 static struct smatch_state *merge_bstates(struct smatch_state *one_state, struct smatch_state *two_state)
166 {
167 struct bit_info *one, *two;
168
169 one = one_state->data;
170 two = two_state->data;
171
172 if (binfo_equiv(one, two))
173 return one_state;
302 }
303
304 static void match_compare(struct expression *expr)
305 {
306 sval_t val;
307
308 if (expr->type != EXPR_COMPARE)
309 return;
310 if (expr->op != SPECIAL_EQUAL &&
311 expr->op != SPECIAL_NOTEQUAL)
312 return;
313
314 if (!get_implied_value(expr->right, &val))
315 return;
316
317 set_true_false_states_expr(my_id, expr->left,
318 (expr->op == SPECIAL_EQUAL) ? alloc_bstate(val.uvalue, val.uvalue) : NULL,
319 (expr->op == SPECIAL_EQUAL) ? NULL : alloc_bstate(val.uvalue, val.uvalue));
320 }
321
322 static void match_assign(struct expression *expr)
323 {
324 struct bit_info *start, *binfo;
325 struct smatch_state *new;
326
327 if (!handled_by_assign_hook(expr))
328 return;
329
330 binfo = get_bit_info(expr->right);
331 if (!binfo)
332 return;
333 if (expr->op == '=') {
334 if (is_unknown_binfo(get_type(expr->left), binfo))
335 return;
336
337 set_state_expr(my_id, expr->left, alloc_bstate(binfo->set, binfo->possible));
338 } else if (expr->op == SPECIAL_OR_ASSIGN) {
339 start = get_bit_info(expr->left);
340 new = alloc_bstate(start->set | binfo->set, start->possible | binfo->possible);
341 set_state_expr(my_id, expr->left, new);
342 } else if (expr->op == SPECIAL_AND_ASSIGN) {
343 start = get_bit_info(expr->left);
344 new = alloc_bstate(start->set & binfo->set, start->possible & binfo->possible);
345 set_state_expr(my_id, expr->left, new);
346 }
347 }
348
349 static void match_condition(struct expression *expr)
350 {
351 struct bit_info *orig;
352 struct bit_info true_info;
353 struct bit_info false_info;
354 sval_t right;
355
356 if (expr->type != EXPR_BINOP ||
357 expr->op != '&')
358 return;
359
360 if (!get_value(expr->right, &right))
361 return;
362
363 orig = get_bit_info(expr->left);
364 true_info = *orig;
365 false_info = *orig;
366
|