2 * Copyright (C) 2008 Dan Carpenter.
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 * smatch_extra.c is supposed to track the value of every variable.
34 #include "smatch_slist.h"
35 #include "smatch_extra.h"
40 static void match_link_modify(struct sm_state
*sm
, struct expression
*mod_expr
);
42 struct string_list
*__ignored_macros
= NULL
;
43 static int in_warn_on_macro(void)
45 struct statement
*stmt
;
49 stmt
= get_current_statement();
52 macro
= get_macro_name(stmt
->pos
);
56 FOR_EACH_PTR(__ignored_macros
, tmp
) {
57 if (!strcmp(tmp
, macro
))
59 } END_FOR_EACH_PTR(tmp
);
63 typedef void (mod_hook
)(const char *name
, struct symbol
*sym
, struct smatch_state
*state
);
64 DECLARE_PTR_LIST(void_fn_list
, mod_hook
*);
65 static struct void_fn_list
*extra_mod_hooks
;
66 void add_extra_mod_hook(mod_hook
*fn
)
68 mod_hook
**p
= malloc(sizeof(mod_hook
*));
70 add_ptr_list(&extra_mod_hooks
, p
);
73 void call_extra_mod_hooks(const char *name
, struct symbol
*sym
, struct smatch_state
*state
)
77 FOR_EACH_PTR(extra_mod_hooks
, fn
) {
78 (*fn
)(name
, sym
, state
);
79 } END_FOR_EACH_PTR(fn
);
82 static bool in_param_set
;
83 static void set_extra_mod_helper(const char *name
, struct symbol
*sym
, struct smatch_state
*state
)
85 remove_from_equiv(name
, sym
);
86 call_extra_mod_hooks(name
, sym
, state
);
87 if ((__in_fake_assign
|| in_param_set
) &&
88 estate_is_unknown(state
) && !get_state(SMATCH_EXTRA
, name
, sym
))
90 set_state(SMATCH_EXTRA
, name
, sym
, state
);
93 static char *get_pointed_at(const char *name
, struct symbol
*sym
, struct symbol
**new_sym
)
95 struct expression
*assigned
;
99 if (strcmp(name
+ 1, sym
->ident
->name
) != 0)
102 assigned
= get_assigned_expr_name_sym(sym
->ident
->name
, sym
);
105 assigned
= strip_parens(assigned
);
106 if (assigned
->type
!= EXPR_PREOP
|| assigned
->op
!= '&')
109 return expr_to_var_sym(assigned
->unop
, new_sym
);
112 char *get_other_name_sym(const char *name
, struct symbol
*sym
, struct symbol
**new_sym
)
114 struct expression
*assigned
;
115 char *orig_name
= NULL
;
122 if (!sym
|| !sym
->ident
)
125 ret
= get_pointed_at(name
, sym
, new_sym
);
129 skip
= strlen(sym
->ident
->name
);
130 if (name
[skip
] != '-' || name
[skip
+ 1] != '>')
134 assigned
= get_assigned_expr_name_sym(sym
->ident
->name
, sym
);
137 if (assigned
->type
== EXPR_CALL
)
138 return map_call_to_other_name_sym(name
, sym
, new_sym
);
139 if (assigned
->type
== EXPR_PREOP
|| assigned
->op
== '&') {
141 orig_name
= expr_to_var_sym(assigned
, new_sym
);
142 if (!orig_name
|| !*new_sym
)
145 snprintf(buf
, sizeof(buf
), "%s.%s", orig_name
+ 1, name
+ skip
);
146 ret
= alloc_string(buf
);
147 free_string(orig_name
);
151 if (assigned
->type
!= EXPR_DEREF
)
154 orig_name
= expr_to_var_sym(assigned
, new_sym
);
155 if (!orig_name
|| !*new_sym
)
158 snprintf(buf
, sizeof(buf
), "%s->%s", orig_name
, name
+ skip
);
159 ret
= alloc_string(buf
);
160 free_string(orig_name
);
164 free_string(orig_name
);
168 void set_extra_mod(const char *name
, struct symbol
*sym
, struct smatch_state
*state
)
171 struct symbol
*new_sym
;
173 set_extra_mod_helper(name
, sym
, state
);
174 new_name
= get_other_name_sym(name
, sym
, &new_sym
);
175 if (new_name
&& new_sym
)
176 set_extra_mod_helper(new_name
, new_sym
, state
);
177 free_string(new_name
);
180 static void clear_array_states(struct expression
*array
)
184 sm
= get_sm_state_expr(link_id
, array
);
186 match_link_modify(sm
, NULL
);
189 static void set_extra_array_mod(struct expression
*expr
, struct smatch_state
*state
)
191 struct expression
*array
;
192 struct var_sym_list
*vsl
;
197 array
= get_array_base(expr
);
199 name
= expr_to_chunk_sym_vsl(expr
, &sym
, &vsl
);
201 clear_array_states(array
);
205 FOR_EACH_PTR(vsl
, vs
) {
206 store_link(link_id
, vs
->var
, vs
->sym
, name
, sym
);
207 } END_FOR_EACH_PTR(vs
);
209 call_extra_mod_hooks(name
, sym
, state
);
210 set_state(SMATCH_EXTRA
, name
, sym
, state
);
215 void set_extra_expr_mod(struct expression
*expr
, struct smatch_state
*state
)
220 if (is_array(expr
)) {
221 set_extra_array_mod(expr
, state
);
225 expr
= strip_expr(expr
);
226 name
= expr_to_var_sym(expr
, &sym
);
229 set_extra_mod(name
, sym
, state
);
234 void set_extra_nomod(const char *name
, struct symbol
*sym
, struct smatch_state
*state
)
237 struct symbol
*new_sym
;
238 struct relation
*rel
;
239 struct smatch_state
*orig_state
;
241 orig_state
= get_state(SMATCH_EXTRA
, name
, sym
);
243 /* don't save unknown states if leaving it blank is the same */
244 if (!orig_state
&& estate_is_unknown(state
))
247 new_name
= get_other_name_sym(name
, sym
, &new_sym
);
248 if (new_name
&& new_sym
)
249 set_state(SMATCH_EXTRA
, new_name
, new_sym
, state
);
250 free_string(new_name
);
252 if (!estate_related(orig_state
)) {
253 set_state(SMATCH_EXTRA
, name
, sym
, state
);
257 set_related(state
, estate_related(orig_state
));
258 FOR_EACH_PTR(estate_related(orig_state
), rel
) {
259 struct smatch_state
*estate
;
261 if (option_debug_related
)
262 sm_msg("%s updating related %s to %s", name
, rel
->name
, state
->name
);
263 estate
= get_state(SMATCH_EXTRA
, rel
->name
, rel
->sym
);
266 set_state(SMATCH_EXTRA
, rel
->name
, rel
->sym
, clone_estate_cast(estate_type(estate
), state
));
267 } END_FOR_EACH_PTR(rel
);
270 void set_extra_nomod_vsl(const char *name
, struct symbol
*sym
, struct var_sym_list
*vsl
, struct smatch_state
*state
)
274 FOR_EACH_PTR(vsl
, vs
) {
275 store_link(link_id
, vs
->var
, vs
->sym
, name
, sym
);
276 } END_FOR_EACH_PTR(vs
);
278 set_extra_nomod(name
, sym
, state
);
282 * This is for return_implies_state() hooks which modify a SMATCH_EXTRA state
284 void set_extra_expr_nomod(struct expression
*expr
, struct smatch_state
*state
)
286 struct var_sym_list
*vsl
;
291 name
= expr_to_chunk_sym_vsl(expr
, &sym
, &vsl
);
294 FOR_EACH_PTR(vsl
, vs
) {
295 store_link(link_id
, vs
->var
, vs
->sym
, name
, sym
);
296 } END_FOR_EACH_PTR(vs
);
298 set_extra_nomod(name
, sym
, state
);
303 static void set_extra_true_false(const char *name
, struct symbol
*sym
,
304 struct smatch_state
*true_state
,
305 struct smatch_state
*false_state
)
308 struct symbol
*new_sym
;
309 struct relation
*rel
;
310 struct smatch_state
*orig_state
;
312 if (!true_state
&& !false_state
)
315 if (in_warn_on_macro())
318 new_name
= get_other_name_sym(name
, sym
, &new_sym
);
319 if (new_name
&& new_sym
)
320 set_true_false_states(SMATCH_EXTRA
, new_name
, new_sym
, true_state
, false_state
);
321 free_string(new_name
);
323 orig_state
= get_state(SMATCH_EXTRA
, name
, sym
);
325 if (!estate_related(orig_state
)) {
326 set_true_false_states(SMATCH_EXTRA
, name
, sym
, true_state
, false_state
);
331 set_related(true_state
, estate_related(orig_state
));
333 set_related(false_state
, estate_related(orig_state
));
335 FOR_EACH_PTR(estate_related(orig_state
), rel
) {
336 set_true_false_states(SMATCH_EXTRA
, rel
->name
, rel
->sym
,
337 true_state
, false_state
);
338 } END_FOR_EACH_PTR(rel
);
341 static void set_extra_chunk_true_false(struct expression
*expr
,
342 struct smatch_state
*true_state
,
343 struct smatch_state
*false_state
)
345 struct var_sym_list
*vsl
;
351 if (in_warn_on_macro())
354 type
= get_type(expr
);
358 name
= expr_to_chunk_sym_vsl(expr
, &sym
, &vsl
);
361 FOR_EACH_PTR(vsl
, vs
) {
362 store_link(link_id
, vs
->var
, vs
->sym
, name
, sym
);
363 } END_FOR_EACH_PTR(vs
);
365 set_true_false_states(SMATCH_EXTRA
, name
, sym
,
366 clone_estate(true_state
),
367 clone_estate(false_state
));
372 static void set_extra_expr_true_false(struct expression
*expr
,
373 struct smatch_state
*true_state
,
374 struct smatch_state
*false_state
)
380 if (!true_state
&& !false_state
)
383 if (get_value(expr
, &sval
))
386 expr
= strip_expr(expr
);
387 name
= expr_to_var_sym(expr
, &sym
);
390 set_extra_chunk_true_false(expr
, true_state
, false_state
);
393 set_extra_true_false(name
, sym
, true_state
, false_state
);
397 static struct sm_state
*handle_canonical_while_count_down(struct statement
*loop
)
399 struct expression
*iter_var
;
400 struct expression
*condition
;
402 struct smatch_state
*estate
;
405 condition
= strip_expr(loop
->iterator_pre_condition
);
408 if (condition
->type
!= EXPR_PREOP
&& condition
->type
!= EXPR_POSTOP
)
410 if (condition
->op
!= SPECIAL_DECREMENT
)
413 iter_var
= condition
->unop
;
414 sm
= get_sm_state_expr(SMATCH_EXTRA
, iter_var
);
417 if (sval_cmp_val(estate_min(sm
->state
), 0) < 0)
419 start
= estate_max(sm
->state
);
420 if (sval_cmp_val(start
, 0) <= 0)
422 if (!sval_is_max(start
))
425 if (condition
->type
== EXPR_PREOP
) {
426 estate
= alloc_estate_range(sval_type_val(start
.type
, 1), start
);
427 if (estate_has_hard_max(sm
->state
))
428 estate_set_hard_max(estate
);
429 estate_copy_fuzzy_max(estate
, sm
->state
);
430 set_extra_expr_mod(iter_var
, estate
);
432 if (condition
->type
== EXPR_POSTOP
) {
433 estate
= alloc_estate_range(sval_type_val(start
.type
, 0), start
);
434 if (estate_has_hard_max(sm
->state
))
435 estate_set_hard_max(estate
);
436 estate_copy_fuzzy_max(estate
, sm
->state
);
437 set_extra_expr_mod(iter_var
, estate
);
439 return get_sm_state_expr(SMATCH_EXTRA
, iter_var
);
442 static struct sm_state
*handle_canonical_for_inc(struct expression
*iter_expr
,
443 struct expression
*condition
)
445 struct expression
*iter_var
;
447 struct smatch_state
*estate
;
448 sval_t start
, end
, max
;
450 iter_var
= iter_expr
->unop
;
451 sm
= get_sm_state_expr(SMATCH_EXTRA
, iter_var
);
454 if (!estate_get_single_value(sm
->state
, &start
))
456 if (get_implied_max(condition
->right
, &end
))
457 end
= sval_cast(get_type(iter_var
), end
);
459 end
= sval_type_max(get_type(iter_var
));
461 if (get_sm_state_expr(SMATCH_EXTRA
, condition
->left
) != sm
)
464 switch (condition
->op
) {
465 case SPECIAL_UNSIGNED_LT
:
466 case SPECIAL_NOTEQUAL
:
468 if (!sval_is_min(end
))
471 case SPECIAL_UNSIGNED_LTE
:
477 if (sval_cmp(end
, start
) < 0)
479 estate
= alloc_estate_range(start
, end
);
480 if (get_hard_max(condition
->right
, &max
)) {
481 estate_set_hard_max(estate
);
482 if (condition
->op
== '<' ||
483 condition
->op
== SPECIAL_UNSIGNED_LT
||
484 condition
->op
== SPECIAL_NOTEQUAL
)
486 estate_set_fuzzy_max(estate
, max
);
488 set_extra_expr_mod(iter_var
, estate
);
489 return get_sm_state_expr(SMATCH_EXTRA
, iter_var
);
492 static struct sm_state
*handle_canonical_for_dec(struct expression
*iter_expr
,
493 struct expression
*condition
)
495 struct expression
*iter_var
;
497 struct smatch_state
*estate
;
500 iter_var
= iter_expr
->unop
;
501 sm
= get_sm_state_expr(SMATCH_EXTRA
, iter_var
);
504 if (!estate_get_single_value(sm
->state
, &start
))
506 if (!get_implied_min(condition
->right
, &end
))
507 end
= sval_type_min(get_type(iter_var
));
508 if (get_sm_state_expr(SMATCH_EXTRA
, condition
->left
) != sm
)
511 switch (condition
->op
) {
512 case SPECIAL_NOTEQUAL
:
514 if (!sval_is_min(end
) && !sval_is_max(end
))
522 if (sval_cmp(end
, start
) > 0)
524 estate
= alloc_estate_range(end
, start
);
525 estate_set_hard_max(estate
);
526 estate_set_fuzzy_max(estate
, estate_get_fuzzy_max(estate
));
527 set_extra_expr_mod(iter_var
, estate
);
528 return get_sm_state_expr(SMATCH_EXTRA
, iter_var
);
531 static struct sm_state
*handle_canonical_for_loops(struct statement
*loop
)
533 struct expression
*iter_expr
;
534 struct expression
*condition
;
536 if (!loop
->iterator_post_statement
)
538 if (loop
->iterator_post_statement
->type
!= STMT_EXPRESSION
)
540 iter_expr
= loop
->iterator_post_statement
->expression
;
541 if (!loop
->iterator_pre_condition
)
543 if (loop
->iterator_pre_condition
->type
!= EXPR_COMPARE
)
545 condition
= loop
->iterator_pre_condition
;
547 if (iter_expr
->op
== SPECIAL_INCREMENT
)
548 return handle_canonical_for_inc(iter_expr
, condition
);
549 if (iter_expr
->op
== SPECIAL_DECREMENT
)
550 return handle_canonical_for_dec(iter_expr
, condition
);
554 struct sm_state
*__extra_handle_canonical_loops(struct statement
*loop
, struct stree
**stree
)
556 struct sm_state
*ret
;
558 __push_fake_cur_stree();
559 if (!loop
->iterator_post_statement
)
560 ret
= handle_canonical_while_count_down(loop
);
562 ret
= handle_canonical_for_loops(loop
);
563 *stree
= __pop_fake_cur_stree();
567 int __iterator_unchanged(struct sm_state
*sm
)
571 if (get_sm_state(my_id
, sm
->name
, sm
->sym
) == sm
)
576 static void while_count_down_after(struct sm_state
*sm
, struct expression
*condition
)
580 /* paranoid checking. prolly not needed */
581 condition
= strip_expr(condition
);
584 if (condition
->type
!= EXPR_PREOP
&& condition
->type
!= EXPR_POSTOP
)
586 if (condition
->op
!= SPECIAL_DECREMENT
)
588 after_value
= estate_min(sm
->state
);
590 set_extra_mod(sm
->name
, sm
->sym
, alloc_estate_sval(after_value
));
593 void __extra_pre_loop_hook_after(struct sm_state
*sm
,
594 struct statement
*iterator
,
595 struct expression
*condition
)
597 struct expression
*iter_expr
;
599 struct smatch_state
*state
;
602 while_count_down_after(sm
, condition
);
606 iter_expr
= iterator
->expression
;
608 if (condition
->type
!= EXPR_COMPARE
)
610 if (iter_expr
->op
== SPECIAL_INCREMENT
) {
611 limit
= sval_binop(estate_max(sm
->state
), '+',
612 sval_type_val(estate_type(sm
->state
), 1));
614 limit
= sval_binop(estate_min(sm
->state
), '-',
615 sval_type_val(estate_type(sm
->state
), 1));
617 if (!estate_has_hard_max(sm
->state
) && !__has_breaks()) {
618 if (iter_expr
->op
== SPECIAL_INCREMENT
)
619 state
= alloc_estate_range(estate_min(sm
->state
), limit
);
621 state
= alloc_estate_range(limit
, estate_max(sm
->state
));
623 state
= alloc_estate_sval(limit
);
625 if (!estate_has_hard_max(sm
->state
)) {
626 estate_clear_hard_max(state
);
628 if (estate_has_fuzzy_max(sm
->state
)) {
629 sval_t hmax
= estate_get_fuzzy_max(sm
->state
);
630 sval_t max
= estate_max(sm
->state
);
632 if (sval_cmp(hmax
, max
) != 0)
633 estate_clear_fuzzy_max(state
);
634 } else if (!estate_has_fuzzy_max(sm
->state
)) {
635 estate_clear_fuzzy_max(state
);
638 set_extra_mod(sm
->name
, sm
->sym
, state
);
641 static struct stree
*unmatched_stree
;
642 static struct smatch_state
*unmatched_state(struct sm_state
*sm
)
644 struct smatch_state
*state
;
646 if (unmatched_stree
) {
647 state
= get_state_stree(unmatched_stree
, SMATCH_EXTRA
, sm
->name
, sm
->sym
);
651 if (parent_is_gone_var_sym(sm
->name
, sm
->sym
))
652 return alloc_estate_empty();
653 return alloc_estate_whole(estate_type(sm
->state
));
656 static void clear_the_pointed_at(struct expression
*expr
)
661 struct sm_state
*tmp
;
663 name
= expr_to_var_sym(expr
, &sym
);
667 stree
= __get_cur_stree();
668 FOR_EACH_MY_SM(SMATCH_EXTRA
, stree
, tmp
) {
669 if (tmp
->name
[0] != '*')
673 if (strcmp(tmp
->name
+ 1, name
) != 0)
675 set_extra_mod(tmp
->name
, tmp
->sym
, alloc_estate_whole(estate_type(tmp
->state
)));
676 } END_FOR_EACH_SM(tmp
);
682 static void match_function_call(struct expression
*expr
)
684 struct expression
*arg
;
685 struct expression
*tmp
;
687 /* if we have the db this is handled in smatch_function_hooks.c */
690 if (inlinable(expr
->fn
))
693 FOR_EACH_PTR(expr
->args
, arg
) {
694 tmp
= strip_expr(arg
);
695 if (tmp
->type
== EXPR_PREOP
&& tmp
->op
== '&')
696 set_extra_expr_mod(tmp
->unop
, alloc_estate_whole(get_type(tmp
->unop
)));
698 clear_the_pointed_at(tmp
);
699 } END_FOR_EACH_PTR(arg
);
702 static int values_fit_type(struct expression
*left
, struct expression
*right
)
704 struct range_list
*rl
;
707 type
= get_type(left
);
710 get_absolute_rl(right
, &rl
);
711 if (type_unsigned(type
) && sval_is_negative(rl_min(rl
)))
713 if (sval_cmp(sval_type_min(type
), rl_min(rl
)) > 0)
715 if (sval_cmp(sval_type_max(type
), rl_max(rl
)) < 0)
720 static void save_chunk_info(struct expression
*left
, struct expression
*right
)
722 struct var_sym_list
*vsl
;
724 struct expression
*add_expr
;
730 if (right
->type
!= EXPR_BINOP
|| right
->op
!= '-')
732 if (!get_value(right
->left
, &sval
))
734 if (!expr_to_sym(right
->right
))
737 add_expr
= binop_expression(left
, '+', right
->right
);
738 type
= get_type(add_expr
);
741 name
= expr_to_chunk_sym_vsl(add_expr
, &sym
, &vsl
);
744 FOR_EACH_PTR(vsl
, vs
) {
745 store_link(link_id
, vs
->var
, vs
->sym
, name
, sym
);
746 } END_FOR_EACH_PTR(vs
);
748 set_state(SMATCH_EXTRA
, name
, sym
, alloc_estate_sval(sval_cast(type
, sval
)));
753 static void do_array_assign(struct expression
*left
, int op
, struct expression
*right
)
755 struct range_list
*rl
;
758 get_absolute_rl(right
, &rl
);
759 rl
= cast_rl(get_type(left
), rl
);
761 rl
= alloc_whole_rl(get_type(left
));
764 set_extra_array_mod(left
, alloc_estate_rl(rl
));
767 static void match_untracked_array(struct expression
*call
, int param
)
769 struct expression
*arg
;
771 arg
= get_argument_from_call_expr(call
->args
, param
);
772 arg
= strip_expr(arg
);
774 clear_array_states(arg
);
777 static void match_vanilla_assign(struct expression
*left
, struct expression
*right
)
779 struct range_list
*orig_rl
= NULL
;
780 struct range_list
*rl
= NULL
;
781 struct symbol
*right_sym
;
782 struct symbol
*left_type
;
783 struct symbol
*right_type
;
784 char *right_name
= NULL
;
788 struct smatch_state
*state
;
794 save_chunk_info(left
, right
);
796 name
= expr_to_var_sym(left
, &sym
);
799 do_array_assign(left
, '=', right
);
803 left_type
= get_type(left
);
804 right_type
= get_type(right
);
806 right_name
= expr_to_var_sym(right
, &right_sym
);
808 if (!__in_fake_assign
&&
809 !(right
->type
== EXPR_PREOP
&& right
->op
== '&') &&
810 right_name
&& right_sym
&&
811 values_fit_type(left
, right
) &&
812 !has_symbol(right
, sym
)) {
813 set_equiv(left
, right
);
817 if (is_pointer(right
) && get_address_rl(right
, &rl
)) {
818 state
= alloc_estate_rl(rl
);
822 if (__in_fake_assign
) {
823 struct smatch_state
*right_state
;
826 if (get_value(right
, &sval
)) {
827 sval
= sval_cast(left_type
, sval
);
828 state
= alloc_estate_sval(sval
);
832 right_state
= get_state(SMATCH_EXTRA
, right_name
, right_sym
);
834 /* simple assignment */
835 state
= clone_estate(right_state
);
839 state
= alloc_estate_rl(alloc_whole_rl(left_type
));
843 comparison
= get_comparison(left
, right
);
845 comparison
= flip_comparison(comparison
);
846 get_implied_rl(left
, &orig_rl
);
849 if (get_implied_rl(right
, &rl
)) {
850 rl
= cast_rl(left_type
, rl
);
852 filter_by_comparison(&rl
, comparison
, orig_rl
);
853 state
= alloc_estate_rl(rl
);
854 if (get_hard_max(right
, &max
)) {
855 estate_set_hard_max(state
);
856 estate_set_fuzzy_max(state
, max
);
859 rl
= alloc_whole_rl(right_type
);
860 rl
= cast_rl(left_type
, rl
);
862 filter_by_comparison(&rl
, comparison
, orig_rl
);
863 state
= alloc_estate_rl(rl
);
867 set_extra_mod(name
, sym
, state
);
869 free_string(right_name
);
872 static int op_remove_assign(int op
)
875 case SPECIAL_ADD_ASSIGN
:
877 case SPECIAL_SUB_ASSIGN
:
879 case SPECIAL_MUL_ASSIGN
:
881 case SPECIAL_DIV_ASSIGN
:
883 case SPECIAL_MOD_ASSIGN
:
885 case SPECIAL_AND_ASSIGN
:
887 case SPECIAL_OR_ASSIGN
:
889 case SPECIAL_XOR_ASSIGN
:
891 case SPECIAL_SHL_ASSIGN
:
892 return SPECIAL_LEFTSHIFT
;
893 case SPECIAL_SHR_ASSIGN
:
894 return SPECIAL_RIGHTSHIFT
;
900 static void match_assign(struct expression
*expr
)
902 struct range_list
*rl
= NULL
;
903 struct expression
*left
;
904 struct expression
*right
;
905 struct expression
*binop_expr
;
906 struct symbol
*left_type
;
909 sval_t left_min
, left_max
;
910 sval_t right_min
, right_max
;
911 sval_t res_min
, res_max
;
913 left
= strip_expr(expr
->left
);
915 right
= strip_parens(expr
->right
);
916 if (right
->type
== EXPR_CALL
&& sym_name_is("__builtin_expect", right
->fn
))
917 right
= get_argument_from_call_expr(right
->args
, 0);
918 while (right
->type
== EXPR_ASSIGNMENT
&& right
->op
== '=')
919 right
= strip_parens(right
->left
);
921 if (expr
->op
== '=' && is_condition(expr
->right
))
922 return; /* handled in smatch_condition.c */
923 if (expr
->op
== '=' && right
->type
== EXPR_CALL
)
924 return; /* handled in smatch_function_hooks.c */
925 if (expr
->op
== '=') {
926 match_vanilla_assign(left
, right
);
930 name
= expr_to_var_sym(left
, &sym
);
934 left_type
= get_type(left
);
936 res_min
= sval_type_min(left_type
);
937 res_max
= sval_type_max(left_type
);
940 case SPECIAL_ADD_ASSIGN
:
941 get_absolute_max(left
, &left_max
);
942 get_absolute_max(right
, &right_max
);
943 if (sval_binop_overflows(left_max
, '+', sval_cast(left_type
, right_max
)))
945 if (get_implied_min(left
, &left_min
) &&
946 !sval_is_negative_min(left_min
) &&
947 get_implied_min(right
, &right_min
) &&
948 !sval_is_negative_min(right_min
)) {
949 res_min
= sval_binop(left_min
, '+', right_min
);
950 res_min
= sval_cast(left_type
, res_min
);
952 if (inside_loop()) /* we are assuming loops don't lead to wrapping */
954 res_max
= sval_binop(left_max
, '+', right_max
);
955 res_max
= sval_cast(left_type
, res_max
);
957 case SPECIAL_SUB_ASSIGN
:
958 if (get_implied_max(left
, &left_max
) &&
959 !sval_is_max(left_max
) &&
960 get_implied_min(right
, &right_min
) &&
961 !sval_is_min(right_min
)) {
962 res_max
= sval_binop(left_max
, '-', right_min
);
963 res_max
= sval_cast(left_type
, res_max
);
967 if (get_implied_min(left
, &left_min
) &&
968 !sval_is_min(left_min
) &&
969 get_implied_max(right
, &right_max
) &&
970 !sval_is_max(right_max
) &&
971 sval_cmp(left_min
, right_max
) > 0) {
972 res_min
= sval_binop(left_min
, '-', right_max
);
973 res_min
= sval_cast(left_type
, res_min
);
976 case SPECIAL_AND_ASSIGN
:
977 case SPECIAL_MOD_ASSIGN
:
978 case SPECIAL_SHL_ASSIGN
:
979 case SPECIAL_SHR_ASSIGN
:
980 case SPECIAL_OR_ASSIGN
:
981 case SPECIAL_XOR_ASSIGN
:
982 case SPECIAL_MUL_ASSIGN
:
983 case SPECIAL_DIV_ASSIGN
:
984 binop_expr
= binop_expression(expr
->left
,
985 op_remove_assign(expr
->op
),
987 if (get_absolute_rl(binop_expr
, &rl
)) {
988 rl
= cast_rl(left_type
, rl
);
989 set_extra_mod(name
, sym
, alloc_estate_rl(rl
));
994 rl
= cast_rl(left_type
, alloc_rl(res_min
, res_max
));
995 set_extra_mod(name
, sym
, alloc_estate_rl(rl
));
1000 static struct smatch_state
*increment_state(struct smatch_state
*state
)
1002 sval_t min
= estate_min(state
);
1003 sval_t max
= estate_max(state
);
1005 if (!estate_rl(state
))
1009 max
= sval_type_max(max
.type
);
1011 if (!sval_is_min(min
) && !sval_is_max(min
))
1013 if (!sval_is_min(max
) && !sval_is_max(max
))
1015 return alloc_estate_range(min
, max
);
1018 static struct smatch_state
*decrement_state(struct smatch_state
*state
)
1020 sval_t min
= estate_min(state
);
1021 sval_t max
= estate_max(state
);
1023 if (!estate_rl(state
))
1027 min
= sval_type_min(min
.type
);
1029 if (!sval_is_min(min
) && !sval_is_max(min
))
1031 if (!sval_is_min(max
) && !sval_is_max(max
))
1033 return alloc_estate_range(min
, max
);
1036 static void clear_pointed_at_state(struct expression
*expr
)
1038 struct symbol
*type
;
1041 * ALERT: This is sort of a mess. If it's is a struct assigment like
1042 * "foo = bar;", then that's handled by smatch_struct_assignment.c.
1043 * the same thing for p++ where "p" is a struct. Most modifications
1044 * are handled by the assignment hook or the db. Smatch_extra.c doesn't
1045 * use smatch_modification.c because we have to get the ordering right
1046 * or something. So if you have p++ where p is a pointer to a standard
1047 * c type then we handle that here. What a mess.
1050 type
= get_type(expr
);
1051 if (!type
|| type
->type
!= SYM_PTR
)
1053 type
= get_real_base_type(type
);
1054 if (!type
|| type
->type
!= SYM_BASETYPE
)
1056 set_extra_expr_mod(deref_expression(expr
), alloc_estate_whole(type
));
1059 static void unop_expr(struct expression
*expr
)
1061 struct smatch_state
*state
;
1063 if (expr
->smatch_flags
& Handled
)
1067 case SPECIAL_INCREMENT
:
1068 state
= get_state_expr(SMATCH_EXTRA
, expr
->unop
);
1069 state
= increment_state(state
);
1071 state
= alloc_estate_whole(get_type(expr
));
1072 set_extra_expr_mod(expr
->unop
, state
);
1073 clear_pointed_at_state(expr
->unop
);
1075 case SPECIAL_DECREMENT
:
1076 state
= get_state_expr(SMATCH_EXTRA
, expr
->unop
);
1077 state
= decrement_state(state
);
1079 state
= alloc_estate_whole(get_type(expr
));
1080 set_extra_expr_mod(expr
->unop
, state
);
1081 clear_pointed_at_state(expr
->unop
);
1088 static void asm_expr(struct statement
*stmt
)
1091 struct expression
*expr
;
1092 struct symbol
*type
;
1095 FOR_EACH_PTR(stmt
->asm_outputs
, expr
) {
1097 case 0: /* identifier */
1098 case 1: /* constraint */
1101 case 2: /* expression */
1103 type
= get_type(strip_expr(expr
));
1104 set_extra_expr_mod(expr
, alloc_estate_whole(type
));
1107 } END_FOR_EACH_PTR(expr
);
1110 static void check_dereference(struct expression
*expr
)
1112 if (__in_fake_assign
)
1114 if (outside_of_function())
1116 if (implied_not_equal(expr
, 0))
1118 set_extra_expr_nomod(expr
, alloc_estate_range(valid_ptr_min_sval
, valid_ptr_max_sval
));
1121 static void match_dereferences(struct expression
*expr
)
1123 if (expr
->type
!= EXPR_PREOP
)
1125 /* it's saying that foo[1] = bar dereferences foo[1] */
1128 check_dereference(expr
->unop
);
1131 static void match_pointer_as_array(struct expression
*expr
)
1133 if (!is_array(expr
))
1135 check_dereference(get_array_base(expr
));
1138 static void find_dereferences(struct expression
*expr
)
1140 while (expr
->type
== EXPR_PREOP
) {
1141 if (expr
->op
== '*')
1142 check_dereference(expr
->unop
);
1143 expr
= strip_expr(expr
->unop
);
1147 static void set_param_dereferenced(struct expression
*arg
, char *key
, char *unused
)
1152 name
= get_variable_from_key(arg
, key
, &sym
);
1154 set_extra_nomod(name
, sym
, alloc_estate_range(valid_ptr_min_sval
, valid_ptr_max_sval
));
1157 find_dereferences(arg
);
1160 static sval_t
add_one(sval_t sval
)
1166 static int handle_postop_inc(struct expression
*left
, int op
, struct expression
*right
)
1168 struct statement
*stmt
;
1169 struct expression
*cond
;
1170 struct smatch_state
*true_state
, *false_state
;
1175 * If we're decrementing here then that's a canonical while count down
1176 * so it's handled already. We're only handling loops like:
1178 * do { ... } while (i++ < 3);
1181 if (left
->type
!= EXPR_POSTOP
|| left
->op
!= SPECIAL_INCREMENT
)
1184 stmt
= __cur_stmt
->parent
;
1187 if (stmt
->type
== STMT_COMPOUND
)
1188 stmt
= stmt
->parent
;
1189 if (!stmt
|| stmt
->type
!= STMT_ITERATOR
|| !stmt
->iterator_post_condition
)
1192 cond
= strip_expr(stmt
->iterator_post_condition
);
1193 if (cond
->type
!= EXPR_COMPARE
|| cond
->op
!= op
)
1195 if (left
!= strip_expr(cond
->left
) || right
!= strip_expr(cond
->right
))
1198 if (!get_implied_value(left
->unop
, &start
))
1200 if (!get_implied_value(right
, &limit
))
1203 if (sval_cmp(start
, limit
) > 0)
1208 case SPECIAL_UNSIGNED_LT
:
1211 case SPECIAL_UNSIGNED_LTE
:
1212 limit
= add_one(limit
);
1218 true_state
= alloc_estate_range(add_one(start
), limit
);
1219 false_state
= alloc_estate_range(add_one(limit
), add_one(limit
));
1221 /* Currently we just discard the false state but when two passes is
1222 * implimented correctly then it will use it.
1225 set_extra_expr_true_false(left
->unop
, true_state
, false_state
);
1230 static void handle_comparison(struct symbol
*type
, struct expression
*left
, int op
, struct expression
*right
)
1232 struct range_list
*left_orig
;
1233 struct range_list
*left_true
;
1234 struct range_list
*left_false
;
1235 struct range_list
*right_orig
;
1236 struct range_list
*right_true
;
1237 struct range_list
*right_false
;
1238 struct smatch_state
*left_true_state
;
1239 struct smatch_state
*left_false_state
;
1240 struct smatch_state
*right_true_state
;
1241 struct smatch_state
*right_false_state
;
1242 sval_t dummy
, hard_max
;
1243 int left_postop
= 0;
1244 int right_postop
= 0;
1246 if (left
->op
== SPECIAL_INCREMENT
|| left
->op
== SPECIAL_DECREMENT
) {
1247 if (left
->type
== EXPR_POSTOP
) {
1248 left
->smatch_flags
|= Handled
;
1249 left_postop
= left
->op
;
1250 if (handle_postop_inc(left
, op
, right
))
1253 left
= strip_parens(left
->unop
);
1255 while (left
->type
== EXPR_ASSIGNMENT
)
1256 left
= strip_parens(left
->left
);
1258 if (right
->op
== SPECIAL_INCREMENT
|| right
->op
== SPECIAL_DECREMENT
) {
1259 if (right
->type
== EXPR_POSTOP
) {
1260 right
->smatch_flags
|= Handled
;
1261 right_postop
= right
->op
;
1263 right
= strip_parens(right
->unop
);
1266 get_real_absolute_rl(left
, &left_orig
);
1267 left_orig
= cast_rl(type
, left_orig
);
1269 get_real_absolute_rl(right
, &right_orig
);
1270 right_orig
= cast_rl(type
, right_orig
);
1272 split_comparison_rl(left_orig
, op
, right_orig
, &left_true
, &left_false
, &right_true
, &right_false
);
1274 left_true
= rl_truncate_cast(get_type(strip_expr(left
)), left_true
);
1275 left_false
= rl_truncate_cast(get_type(strip_expr(left
)), left_false
);
1276 right_true
= rl_truncate_cast(get_type(strip_expr(right
)), right_true
);
1277 right_false
= rl_truncate_cast(get_type(strip_expr(right
)), right_false
);
1279 if (!left_true
|| !left_false
) {
1280 struct range_list
*tmp_true
, *tmp_false
;
1282 split_comparison_rl(alloc_whole_rl(type
), op
, right_orig
, &tmp_true
, &tmp_false
, NULL
, NULL
);
1283 tmp_true
= rl_truncate_cast(get_type(strip_expr(left
)), tmp_true
);
1284 tmp_false
= rl_truncate_cast(get_type(strip_expr(left
)), tmp_false
);
1285 if (tmp_true
&& tmp_false
)
1286 __save_imaginary_state(left
, tmp_true
, tmp_false
);
1289 if (!right_true
|| !right_false
) {
1290 struct range_list
*tmp_true
, *tmp_false
;
1292 split_comparison_rl(alloc_whole_rl(type
), op
, right_orig
, NULL
, NULL
, &tmp_true
, &tmp_false
);
1293 tmp_true
= rl_truncate_cast(get_type(strip_expr(right
)), tmp_true
);
1294 tmp_false
= rl_truncate_cast(get_type(strip_expr(right
)), tmp_false
);
1295 if (tmp_true
&& tmp_false
)
1296 __save_imaginary_state(right
, tmp_true
, tmp_false
);
1299 left_true_state
= alloc_estate_rl(left_true
);
1300 left_false_state
= alloc_estate_rl(left_false
);
1301 right_true_state
= alloc_estate_rl(right_true
);
1302 right_false_state
= alloc_estate_rl(right_false
);
1306 case SPECIAL_UNSIGNED_LT
:
1307 case SPECIAL_UNSIGNED_LTE
:
1309 if (get_hard_max(right
, &dummy
))
1310 estate_set_hard_max(left_true_state
);
1311 if (get_hard_max(left
, &dummy
))
1312 estate_set_hard_max(right_false_state
);
1315 case SPECIAL_UNSIGNED_GT
:
1316 case SPECIAL_UNSIGNED_GTE
:
1318 if (get_hard_max(left
, &dummy
))
1319 estate_set_hard_max(right_true_state
);
1320 if (get_hard_max(right
, &dummy
))
1321 estate_set_hard_max(left_false_state
);
1327 case SPECIAL_UNSIGNED_LT
:
1328 case SPECIAL_UNSIGNED_LTE
:
1330 if (get_hard_max(right
, &hard_max
)) {
1331 if (op
== '<' || op
== SPECIAL_UNSIGNED_LT
)
1333 estate_set_fuzzy_max(left_true_state
, hard_max
);
1335 if (get_implied_value(right
, &hard_max
)) {
1336 if (op
== SPECIAL_UNSIGNED_LTE
||
1339 estate_set_fuzzy_max(left_false_state
, hard_max
);
1341 if (get_hard_max(left
, &hard_max
)) {
1342 if (op
== SPECIAL_UNSIGNED_LTE
||
1345 estate_set_fuzzy_max(right_false_state
, hard_max
);
1347 if (get_implied_value(left
, &hard_max
)) {
1348 if (op
== '<' || op
== SPECIAL_UNSIGNED_LT
)
1350 estate_set_fuzzy_max(right_true_state
, hard_max
);
1354 case SPECIAL_UNSIGNED_GT
:
1355 case SPECIAL_UNSIGNED_GTE
:
1357 if (get_hard_max(left
, &hard_max
)) {
1358 if (op
== '>' || op
== SPECIAL_UNSIGNED_GT
)
1360 estate_set_fuzzy_max(right_true_state
, hard_max
);
1362 if (get_implied_value(left
, &hard_max
)) {
1363 if (op
== SPECIAL_UNSIGNED_GTE
||
1366 estate_set_fuzzy_max(right_false_state
, hard_max
);
1368 if (get_hard_max(right
, &hard_max
)) {
1369 if (op
== SPECIAL_UNSIGNED_LTE
||
1372 estate_set_fuzzy_max(left_false_state
, hard_max
);
1374 if (get_implied_value(right
, &hard_max
)) {
1376 op
== SPECIAL_UNSIGNED_GT
)
1378 estate_set_fuzzy_max(left_true_state
, hard_max
);
1382 if (get_hard_max(left
, &hard_max
))
1383 estate_set_fuzzy_max(right_true_state
, hard_max
);
1384 if (get_hard_max(right
, &hard_max
))
1385 estate_set_fuzzy_max(left_true_state
, hard_max
);
1389 if (get_hard_max(left
, &hard_max
)) {
1390 estate_set_hard_max(left_true_state
);
1391 estate_set_hard_max(left_false_state
);
1393 if (get_hard_max(right
, &hard_max
)) {
1394 estate_set_hard_max(right_true_state
);
1395 estate_set_hard_max(right_false_state
);
1398 if (left_postop
== SPECIAL_INCREMENT
) {
1399 left_true_state
= increment_state(left_true_state
);
1400 left_false_state
= increment_state(left_false_state
);
1402 if (left_postop
== SPECIAL_DECREMENT
) {
1403 left_true_state
= decrement_state(left_true_state
);
1404 left_false_state
= decrement_state(left_false_state
);
1406 if (right_postop
== SPECIAL_INCREMENT
) {
1407 right_true_state
= increment_state(right_true_state
);
1408 right_false_state
= increment_state(right_false_state
);
1410 if (right_postop
== SPECIAL_DECREMENT
) {
1411 right_true_state
= decrement_state(right_true_state
);
1412 right_false_state
= decrement_state(right_false_state
);
1415 if (estate_rl(left_true_state
) && estates_equiv(left_true_state
, left_false_state
)) {
1416 left_true_state
= NULL
;
1417 left_false_state
= NULL
;
1420 if (estate_rl(right_true_state
) && estates_equiv(right_true_state
, right_false_state
)) {
1421 right_true_state
= NULL
;
1422 right_false_state
= NULL
;
1425 set_extra_expr_true_false(left
, left_true_state
, left_false_state
);
1426 set_extra_expr_true_false(right
, right_true_state
, right_false_state
);
1429 static int is_simple_math(struct expression
*expr
)
1433 if (expr
->type
!= EXPR_BINOP
)
1444 static void move_known_values(struct expression
**left_p
, struct expression
**right_p
)
1446 struct expression
*left
= *left_p
;
1447 struct expression
*right
= *right_p
;
1450 if (get_implied_value(left
, &sval
)) {
1451 if (!is_simple_math(right
))
1453 if (get_implied_value(right
, &dummy
))
1455 if (right
->op
== '*') {
1458 if (!get_value(right
->right
, &divisor
))
1460 if (divisor
.value
== 0 && sval
.value
% divisor
.value
)
1462 *left_p
= binop_expression(left
, invert_op(right
->op
), right
->right
);
1463 *right_p
= right
->left
;
1466 if (right
->op
== '+' && get_value(right
->left
, &sval
)) {
1467 *left_p
= binop_expression(left
, invert_op(right
->op
), right
->left
);
1468 *right_p
= right
->right
;
1471 if (get_value(right
->right
, &sval
)) {
1472 *left_p
= binop_expression(left
, invert_op(right
->op
), right
->right
);
1473 *right_p
= right
->left
;
1478 if (get_implied_value(right
, &sval
)) {
1479 if (!is_simple_math(left
))
1481 if (get_implied_value(left
, &dummy
))
1483 if (left
->op
== '*') {
1486 if (!get_value(left
->right
, &divisor
))
1488 if (divisor
.value
== 0 && sval
.value
% divisor
.value
)
1490 *right_p
= binop_expression(right
, invert_op(left
->op
), left
->right
);
1491 *left_p
= left
->left
;
1494 if (left
->op
== '+' && get_value(left
->left
, &sval
)) {
1495 *right_p
= binop_expression(right
, invert_op(left
->op
), left
->left
);
1496 *left_p
= left
->right
;
1500 if (get_value(left
->right
, &sval
)) {
1501 *right_p
= binop_expression(right
, invert_op(left
->op
), left
->right
);
1502 *left_p
= left
->left
;
1510 * The reason for do_simple_algebra() is to solve things like:
1511 * if (foo > 66 || foo + bar > 64) {
1512 * "foo" is not really a known variable so it won't be handled by
1513 * move_known_variables() but it's a super common idiom.
1516 static int do_simple_algebra(struct expression
**left_p
, struct expression
**right_p
)
1518 struct expression
*left
= *left_p
;
1519 struct expression
*right
= *right_p
;
1520 struct range_list
*rl
;
1523 if (left
->type
!= EXPR_BINOP
|| left
->op
!= '+')
1525 if (can_integer_overflow(get_type(left
), left
))
1527 if (!get_implied_value(right
, &tmp
))
1530 if (!get_implied_value(left
->left
, &tmp
) &&
1531 get_implied_rl(left
->left
, &rl
) &&
1533 *right_p
= binop_expression(right
, '-', left
->left
);
1534 *left_p
= left
->right
;
1537 if (!get_implied_value(left
->right
, &tmp
) &&
1538 get_implied_rl(left
->right
, &rl
) &&
1540 *right_p
= binop_expression(right
, '-', left
->right
);
1541 *left_p
= left
->left
;
1548 static int match_func_comparison(struct expression
*expr
)
1550 struct expression
*left
= strip_expr(expr
->left
);
1551 struct expression
*right
= strip_expr(expr
->right
);
1555 * fixme: think about this harder. We should always be trying to limit
1556 * the non-call side as well. If we can't determine the limitter does
1557 * that mean we aren't querying the database and are missing important
1561 if (left
->type
== EXPR_CALL
) {
1562 if (get_implied_value(left
, &sval
)) {
1563 handle_comparison(get_type(expr
), left
, expr
->op
, right
);
1566 function_comparison(left
, expr
->op
, right
);
1570 if (right
->type
== EXPR_CALL
) {
1571 if (get_implied_value(right
, &sval
)) {
1572 handle_comparison(get_type(expr
), left
, expr
->op
, right
);
1575 function_comparison(left
, expr
->op
, right
);
1582 /* Handle conditions like "if (foo + bar < foo) {" */
1583 static int handle_integer_overflow_test(struct expression
*expr
)
1585 struct expression
*left
, *right
;
1586 struct symbol
*type
;
1587 sval_t left_min
, right_min
, min
, max
;
1589 if (expr
->op
!= '<' && expr
->op
!= SPECIAL_UNSIGNED_LT
)
1592 left
= strip_parens(expr
->left
);
1593 right
= strip_parens(expr
->right
);
1595 if (left
->op
!= '+')
1598 type
= get_type(expr
);
1601 if (type_positive_bits(type
) == 32) {
1602 max
.type
= &uint_ctype
;
1603 max
.uvalue
= (unsigned int)-1;
1604 } else if (type_positive_bits(type
) == 64) {
1605 max
.type
= &ulong_ctype
;
1606 max
.value
= (unsigned long long)-1;
1611 if (!expr_equiv(left
->left
, right
) && !expr_equiv(left
->right
, right
))
1614 get_absolute_min(left
->left
, &left_min
);
1615 get_absolute_min(left
->right
, &right_min
);
1616 min
= sval_binop(left_min
, '+', right_min
);
1618 set_extra_chunk_true_false(left
, NULL
, alloc_estate_range(min
, max
));
1622 static void match_comparison(struct expression
*expr
)
1624 struct expression
*left_orig
= strip_parens(expr
->left
);
1625 struct expression
*right_orig
= strip_parens(expr
->right
);
1626 struct expression
*left
, *right
;
1627 struct expression
*prev
;
1628 struct symbol
*type
;
1630 if (match_func_comparison(expr
))
1633 type
= get_type(expr
);
1635 type
= &llong_ctype
;
1637 if (handle_integer_overflow_test(expr
))
1642 move_known_values(&left
, &right
);
1643 handle_comparison(type
, left
, expr
->op
, right
);
1647 if (do_simple_algebra(&left
, &right
))
1648 handle_comparison(type
, left
, expr
->op
, right
);
1650 prev
= get_assigned_expr(left_orig
);
1651 if (is_simple_math(prev
) && has_variable(prev
, left_orig
) == 0) {
1654 move_known_values(&left
, &right
);
1655 handle_comparison(type
, left
, expr
->op
, right
);
1658 prev
= get_assigned_expr(right_orig
);
1659 if (is_simple_math(prev
) && has_variable(prev
, right_orig
) == 0) {
1662 move_known_values(&left
, &right
);
1663 handle_comparison(type
, left
, expr
->op
, right
);
1667 static sval_t
get_high_mask(sval_t known
)
1675 for (i
= type_bits(known
.type
) - 1; i
>= 0; i
--) {
1676 if (known
.uvalue
& (1ULL << i
))
1677 ret
.uvalue
|= (1ULL << i
);
1685 static void handle_AND_condition(struct expression
*expr
)
1687 struct range_list
*orig_rl
;
1688 struct range_list
*true_rl
= NULL
;
1689 struct range_list
*false_rl
= NULL
;
1693 if (get_implied_value(expr
->left
, &known
)) {
1694 sval_t low_mask
= known
;
1697 if (known
.value
> 0) {
1698 bit
= ffsll(known
.value
) - 1;
1699 low_mask
.uvalue
= (1ULL << bit
) - 1;
1700 get_absolute_rl(expr
->right
, &orig_rl
);
1701 true_rl
= remove_range(orig_rl
, sval_type_val(known
.type
, 0), low_mask
);
1703 high_mask
= get_high_mask(known
);
1704 if (high_mask
.value
) {
1705 bit
= ffsll(high_mask
.value
) - 1;
1706 low_mask
.uvalue
= (1ULL << bit
) - 1;
1708 get_absolute_rl(expr
->left
, &orig_rl
);
1709 if (sval_is_negative(rl_min(orig_rl
)))
1710 orig_rl
= remove_range(orig_rl
, sval_type_min(known
.type
), sval_type_val(known
.type
, -1));
1711 false_rl
= remove_range(orig_rl
, low_mask
, sval_type_max(known
.type
));
1712 if (type_signed(high_mask
.type
) && type_unsigned(rl_type(false_rl
))) {
1713 false_rl
= remove_range(false_rl
,
1714 sval_type_val(rl_type(false_rl
), sval_type_max(known
.type
).uvalue
),
1715 sval_type_val(rl_type(false_rl
), -1));
1718 set_extra_expr_true_false(expr
->right
,
1719 true_rl
? alloc_estate_rl(true_rl
) : NULL
,
1720 false_rl
? alloc_estate_rl(false_rl
) : NULL
);
1725 if (get_implied_value(expr
->right
, &known
)) {
1726 sval_t low_mask
= known
;
1729 if (known
.value
> 0) {
1730 bit
= ffsll(known
.value
) - 1;
1731 low_mask
.uvalue
= (1ULL << bit
) - 1;
1732 get_absolute_rl(expr
->left
, &orig_rl
);
1733 true_rl
= remove_range(orig_rl
, sval_type_val(known
.type
, 0), low_mask
);
1735 high_mask
= get_high_mask(known
);
1736 if (high_mask
.value
) {
1737 bit
= ffsll(high_mask
.value
) - 1;
1738 low_mask
.uvalue
= (1ULL << bit
) - 1;
1740 get_absolute_rl(expr
->left
, &orig_rl
);
1741 if (sval_is_negative(rl_min(orig_rl
)))
1742 orig_rl
= remove_range(orig_rl
, sval_type_min(known
.type
), sval_type_val(known
.type
, -1));
1743 false_rl
= remove_range(orig_rl
, low_mask
, sval_type_max(known
.type
));
1744 if (type_signed(high_mask
.type
) && type_unsigned(rl_type(false_rl
))) {
1745 false_rl
= remove_range(false_rl
,
1746 sval_type_val(rl_type(false_rl
), sval_type_max(known
.type
).uvalue
),
1747 sval_type_val(rl_type(false_rl
), -1));
1750 set_extra_expr_true_false(expr
->left
,
1751 true_rl
? alloc_estate_rl(true_rl
) : NULL
,
1752 false_rl
? alloc_estate_rl(false_rl
) : NULL
);
1757 static void handle_MOD_condition(struct expression
*expr
)
1759 struct range_list
*orig_rl
;
1760 struct range_list
*true_rl
;
1761 struct range_list
*false_rl
= NULL
;
1767 if (!get_implied_value(expr
->right
, &right
) || right
.value
== 0)
1769 get_absolute_rl(expr
->left
, &orig_rl
);
1771 zero
.type
= rl_type(orig_rl
);
1773 /* We're basically dorking around the min and max here */
1774 true_rl
= remove_range(orig_rl
, zero
, zero
);
1775 if (!sval_is_max(rl_max(true_rl
)) &&
1776 !(rl_max(true_rl
).value
% right
.value
))
1777 true_rl
= remove_range(true_rl
, rl_max(true_rl
), rl_max(true_rl
));
1779 if (rl_equiv(true_rl
, orig_rl
))
1782 if (sval_is_positive(rl_min(orig_rl
)) &&
1783 (rl_max(orig_rl
).value
- rl_min(orig_rl
).value
) / right
.value
< 5) {
1787 add
= rl_min(orig_rl
);
1788 add
.value
+= right
.value
- (add
.value
% right
.value
);
1789 add
.value
-= right
.value
;
1791 for (i
= 0; i
< 5; i
++) {
1792 add
.value
+= right
.value
;
1793 if (add
.value
> rl_max(orig_rl
).value
)
1795 add_range(&false_rl
, add
, add
);
1798 if (rl_min(orig_rl
).uvalue
!= 0 &&
1799 rl_min(orig_rl
).uvalue
< right
.uvalue
) {
1800 sval_t chop
= right
;
1802 false_rl
= remove_range(orig_rl
, zero
, chop
);
1805 if (!sval_is_max(rl_max(orig_rl
)) &&
1806 (rl_max(orig_rl
).value
% right
.value
)) {
1807 sval_t chop
= rl_max(orig_rl
);
1808 chop
.value
-= chop
.value
% right
.value
;
1811 false_rl
= clone_rl(orig_rl
);
1812 false_rl
= remove_range(false_rl
, chop
, rl_max(orig_rl
));
1816 set_extra_expr_true_false(expr
->left
,
1817 true_rl
? alloc_estate_rl(true_rl
) : NULL
,
1818 false_rl
? alloc_estate_rl(false_rl
) : NULL
);
1821 /* this is actually hooked from smatch_implied.c... it's hacky, yes */
1822 void __extra_match_condition(struct expression
*expr
)
1824 struct smatch_state
*pre_state
;
1825 struct smatch_state
*true_state
;
1826 struct smatch_state
*false_state
;
1828 expr
= strip_expr(expr
);
1829 switch (expr
->type
) {
1831 function_comparison(expr
, SPECIAL_NOTEQUAL
, zero_expr());
1838 zero
= sval_blank(expr
);
1841 pre_state
= get_extra_state(expr
);
1842 true_state
= estate_filter_sval(pre_state
, zero
);
1843 if (possibly_true(expr
, SPECIAL_EQUAL
, zero_expr()))
1844 false_state
= alloc_estate_sval(zero
);
1846 false_state
= alloc_estate_empty();
1847 set_extra_expr_true_false(expr
, true_state
, false_state
);
1851 match_comparison(expr
);
1853 case EXPR_ASSIGNMENT
:
1854 __extra_match_condition(expr
->left
);
1857 if (expr
->op
== '&')
1858 handle_AND_condition(expr
);
1859 if (expr
->op
== '%')
1860 handle_MOD_condition(expr
);
1865 static void assume_indexes_are_valid(struct expression
*expr
)
1867 struct expression
*array_expr
;
1869 struct expression
*offset
;
1870 struct symbol
*offset_type
;
1871 struct range_list
*rl_before
;
1872 struct range_list
*rl_after
;
1873 struct range_list
*filter
= NULL
;
1876 expr
= strip_expr(expr
);
1877 if (!is_array(expr
))
1880 offset
= get_array_offset(expr
);
1881 offset_type
= get_type(offset
);
1882 if (offset_type
&& type_signed(offset_type
)) {
1883 filter
= alloc_rl(sval_type_min(offset_type
),
1884 sval_type_val(offset_type
, -1));
1887 array_expr
= get_array_base(expr
);
1888 array_size
= get_real_array_size(array_expr
);
1889 if (array_size
> 1) {
1890 size
= sval_type_val(offset_type
, array_size
);
1891 add_range(&filter
, size
, sval_type_max(offset_type
));
1896 get_absolute_rl(offset
, &rl_before
);
1897 rl_after
= rl_filter(rl_before
, filter
);
1898 if (rl_equiv(rl_before
, rl_after
))
1900 set_extra_expr_nomod(offset
, alloc_estate_rl(rl_after
));
1903 /* returns 1 if it is not possible for expr to be value, otherwise returns 0 */
1904 int implied_not_equal(struct expression
*expr
, long long val
)
1906 return !possibly_false(expr
, SPECIAL_NOTEQUAL
, value_expr(val
));
1909 int implied_not_equal_name_sym(char *name
, struct symbol
*sym
, long long val
)
1911 struct smatch_state
*estate
;
1913 estate
= get_state(SMATCH_EXTRA
, name
, sym
);
1916 if (!rl_has_sval(estate_rl(estate
), sval_type_val(estate_type(estate
), 0)))
1921 int parent_is_null_var_sym(const char *name
, struct symbol
*sym
)
1926 struct smatch_state
*state
;
1928 strncpy(buf
, name
, sizeof(buf
) - 1);
1929 buf
[sizeof(buf
) - 1] = '\0';
1932 while (*start
== '*') {
1934 state
= get_state(SMATCH_EXTRA
, start
, sym
);
1937 if (!estate_rl(state
))
1939 if (estate_min(state
).value
== 0 &&
1940 estate_max(state
).value
== 0)
1945 while (*start
== '&')
1948 while ((end
= strrchr(start
, '-'))) {
1950 state
= get_state(SMATCH_EXTRA
, start
, sym
);
1953 if (estate_min(state
).value
== 0 &&
1954 estate_max(state
).value
== 0)
1960 int parent_is_null(struct expression
*expr
)
1966 expr
= strip_expr(expr
);
1967 var
= expr_to_var_sym(expr
, &sym
);
1970 ret
= parent_is_null_var_sym(var
, sym
);
1976 static int param_used_callback(void *found
, int argc
, char **argv
, char **azColName
)
1982 static int filter_unused_kzalloc_info(struct expression
*call
, int param
, char *printed_name
, struct sm_state
*sm
)
1987 /* for function pointers assume everything is used */
1988 if (call
->fn
->type
!= EXPR_SYMBOL
)
1992 * kzalloc() information is treated as special because so there is just
1993 * a lot of stuff initialized to zero and it makes building the database
1994 * take hours and hours.
1996 * In theory, we should just remove this line and not pass any unused
1997 * information, but I'm not sure enough that this code works so I want
1998 * to hold off on that for now.
2000 if (!estate_get_single_value(sm
->state
, &sval
) || sval
.value
!= 0)
2003 run_sql(¶m_used_callback
, &found
,
2004 "select * from call_implies where %s and type = %d and parameter = %d and key = '%s';",
2005 get_static_filter(call
->fn
->symbol
), PARAM_USED
, param
, printed_name
);
2009 /* If the database is not built yet, then assume everything is used */
2010 run_sql(¶m_used_callback
, &found
,
2011 "select * from call_implies where %s and type = %d;",
2012 get_static_filter(call
->fn
->symbol
), PARAM_USED
);
2019 struct range_list
*intersect_with_real_abs_var_sym(const char *name
, struct symbol
*sym
, struct range_list
*start
)
2021 struct smatch_state
*state
;
2024 * Here is the difference between implied value and real absolute, say
2029 * Then you know that a is 0-255. That's real absolute. But you don't
2030 * know for sure that it actually goes up to 255. So it's not implied.
2031 * Implied indicates a degree of certainty.
2033 * But then say you cap "a" at 8. That means you know it goes up to
2034 * 8. So now the implied value is s32min-8. But you can combine it
2035 * with the real absolute to say that actually it's 0-8.
2037 * We are combining it here. But now that I think about it, this is
2038 * probably not the ideal place to combine it because it should proably
2039 * be done earlier. Oh well, this is an improvement on what was there
2040 * before so I'm going to commit this code.
2044 state
= get_real_absolute_state_var_sym(name
, sym
);
2045 if (!state
|| !estate_rl(state
))
2048 return rl_intersection(estate_rl(state
), start
);
2051 struct range_list
*intersect_with_real_abs_expr(struct expression
*expr
, struct range_list
*start
)
2053 struct smatch_state
*state
;
2055 state
= get_real_absolute_state(expr
);
2056 if (!state
|| !estate_rl(state
))
2059 return rl_intersection(estate_rl(state
), start
);
2062 static void struct_member_callback(struct expression
*call
, int param
, char *printed_name
, struct sm_state
*sm
)
2064 struct range_list
*rl
;
2066 if (estate_is_whole(sm
->state
))
2068 if (filter_unused_kzalloc_info(call
, param
, printed_name
, sm
))
2070 rl
= estate_rl(sm
->state
);
2071 rl
= intersect_with_real_abs_var_sym(sm
->name
, sm
->sym
, rl
);
2072 sql_insert_caller_info(call
, PARAM_VALUE
, param
, printed_name
, show_rl(rl
));
2073 if (estate_has_fuzzy_max(sm
->state
))
2074 sql_insert_caller_info(call
, FUZZY_MAX
, param
, printed_name
,
2075 sval_to_str(estate_get_fuzzy_max(sm
->state
)));
2078 static void returned_struct_members(int return_id
, char *return_ranges
, struct expression
*expr
)
2080 struct symbol
*returned_sym
;
2081 struct sm_state
*sm
;
2082 const char *param_name
;
2086 returned_sym
= expr_to_sym(expr
);
2090 FOR_EACH_MY_SM(my_id
, __get_cur_stree(), sm
) {
2091 if (!estate_rl(sm
->state
))
2093 if (returned_sym
!= sm
->sym
)
2096 param_name
= get_param_name(sm
);
2099 if (strcmp(param_name
, "$") == 0)
2101 compare_str
= name_sym_to_param_comparison(sm
->name
, sm
->sym
);
2102 if (!compare_str
&& estate_is_whole(sm
->state
))
2104 snprintf(buf
, sizeof(buf
), "%s%s", sm
->state
->name
, compare_str
?: "");
2106 sql_insert_return_states(return_id
, return_ranges
, PARAM_VALUE
,
2107 -1, param_name
, buf
);
2108 } END_FOR_EACH_SM(sm
);
2111 static void db_limited_before(void)
2113 unmatched_stree
= clone_stree(__get_cur_stree());
2116 static void db_limited_after(void)
2118 free_stree(&unmatched_stree
);
2121 static int rl_fits_in_type(struct range_list
*rl
, struct symbol
*type
)
2123 if (type_bits(rl_type(rl
)) <= type_bits(type
))
2125 if (sval_cmp(rl_max(rl
), sval_type_max(type
)) > 0)
2127 if (sval_is_negative(rl_min(rl
)) &&
2128 sval_cmp(rl_min(rl
), sval_type_min(type
)) < 0)
2133 static int basically_the_same(struct range_list
*orig
, struct range_list
*new)
2135 if (rl_equiv(orig
, new))
2139 * The whole range is essentially the same as 0,4096-27777777777 so
2140 * don't overwrite the implications just to store that.
2143 if (rl_type(orig
)->type
== SYM_PTR
&&
2144 is_whole_rl(orig
) &&
2145 rl_min(new).value
== 0 &&
2146 rl_max(new).value
== valid_ptr_max
)
2151 static void db_param_limit_filter(struct expression
*expr
, int param
, char *key
, char *value
, enum info_type op
)
2153 struct expression
*arg
;
2156 struct var_sym_list
*vsl
= NULL
;
2157 struct sm_state
*sm
;
2158 struct symbol
*compare_type
, *var_type
;
2159 struct range_list
*rl
;
2160 struct range_list
*limit
;
2161 struct range_list
*new;
2163 while (expr
->type
== EXPR_ASSIGNMENT
)
2164 expr
= strip_expr(expr
->right
);
2165 if (expr
->type
!= EXPR_CALL
)
2168 arg
= get_argument_from_call_expr(expr
->args
, param
);
2172 name
= get_chunk_from_key(arg
, key
, &sym
, &vsl
);
2175 if (op
!= PARAM_LIMIT
&& !sym
)
2178 if (strcmp(key
, "$") == 0)
2179 compare_type
= get_arg_type(expr
->fn
, param
);
2181 compare_type
= get_member_type_from_key(arg
, key
);
2183 sm
= get_sm_state(SMATCH_EXTRA
, name
, sym
);
2185 rl
= estate_rl(sm
->state
);
2187 rl
= alloc_whole_rl(compare_type
);
2189 if (op
== PARAM_LIMIT
&& !rl_fits_in_type(rl
, compare_type
))
2192 call_results_to_rl(expr
, compare_type
, value
, &limit
);
2193 new = rl_intersection(rl
, limit
);
2195 var_type
= get_member_type_from_key(arg
, key
);
2196 new = cast_rl(var_type
, new);
2198 /* We want to preserve the implications here */
2199 if (sm
&& basically_the_same(estate_rl(sm
->state
), new))
2200 __set_sm(sm
); /* FIXME: Is this really necessary? */
2203 struct symbol
*tmp_sym
;
2205 tmp_name
= map_long_to_short_name_sym(name
, sym
, &tmp_sym
);
2206 if (tmp_name
&& tmp_sym
) {
2212 if (op
== PARAM_LIMIT
)
2213 set_extra_nomod_vsl(name
, sym
, vsl
, alloc_estate_rl(new));
2215 set_extra_mod(name
, sym
, alloc_estate_rl(new));
2222 static void db_param_limit(struct expression
*expr
, int param
, char *key
, char *value
)
2224 db_param_limit_filter(expr
, param
, key
, value
, PARAM_LIMIT
);
2227 static void db_param_filter(struct expression
*expr
, int param
, char *key
, char *value
)
2229 db_param_limit_filter(expr
, param
, key
, value
, PARAM_FILTER
);
2232 static void db_param_add_set(struct expression
*expr
, int param
, char *key
, char *value
, enum info_type op
)
2234 struct expression
*arg
;
2235 char *name
, *tmp_name
;
2236 struct symbol
*sym
, *tmp_sym
;
2237 struct symbol
*type
;
2238 struct smatch_state
*state
;
2239 struct range_list
*new = NULL
;
2240 struct range_list
*added
= NULL
;
2242 while (expr
->type
== EXPR_ASSIGNMENT
)
2243 expr
= strip_expr(expr
->right
);
2244 if (expr
->type
!= EXPR_CALL
)
2247 arg
= get_argument_from_call_expr(expr
->args
, param
);
2250 type
= get_member_type_from_key(arg
, key
);
2251 name
= get_variable_from_key(arg
, key
, &sym
);
2255 state
= get_state(SMATCH_EXTRA
, name
, sym
);
2257 new = estate_rl(state
);
2259 call_results_to_rl(expr
, type
, value
, &added
);
2261 if (op
== PARAM_SET
)
2264 new = rl_union(new, added
);
2266 tmp_name
= map_long_to_short_name_sym_nostack(name
, sym
, &tmp_sym
);
2267 if (tmp_name
&& tmp_sym
) {
2272 set_extra_mod(name
, sym
, alloc_estate_rl(new));
2277 static void db_param_add(struct expression
*expr
, int param
, char *key
, char *value
)
2279 in_param_set
= true;
2280 db_param_add_set(expr
, param
, key
, value
, PARAM_ADD
);
2281 in_param_set
= false;
2284 static void db_param_set(struct expression
*expr
, int param
, char *key
, char *value
)
2286 in_param_set
= true;
2287 db_param_add_set(expr
, param
, key
, value
, PARAM_SET
);
2288 in_param_set
= false;
2291 static void db_param_value(struct expression
*expr
, int param
, char *key
, char *value
)
2293 struct expression
*call
;
2296 struct symbol
*type
;
2297 struct range_list
*rl
= NULL
;
2303 while (call
->type
== EXPR_ASSIGNMENT
)
2304 call
= strip_expr(call
->right
);
2305 if (call
->type
!= EXPR_CALL
)
2308 type
= get_member_type_from_key(expr
->left
, key
);
2309 name
= get_variable_from_key(expr
->left
, key
, &sym
);
2313 call_results_to_rl(call
, type
, value
, &rl
);
2315 set_extra_mod(name
, sym
, alloc_estate_rl(rl
));
2320 static void match_call_info(struct expression
*expr
)
2322 struct smatch_state
*state
;
2323 struct range_list
*rl
= NULL
;
2324 struct expression
*arg
;
2325 struct symbol
*type
;
2328 FOR_EACH_PTR(expr
->args
, arg
) {
2329 type
= get_arg_type(expr
->fn
, i
);
2331 if (get_implied_rl(arg
, &rl
))
2332 rl
= cast_rl(type
, rl
);
2334 rl
= cast_rl(type
, alloc_whole_rl(get_type(arg
)));
2336 if (!is_whole_rl(rl
)) {
2337 rl
= intersect_with_real_abs_expr(arg
, rl
);
2338 sql_insert_caller_info(expr
, PARAM_VALUE
, i
, "$", show_rl(rl
));
2340 state
= get_state_expr(SMATCH_EXTRA
, arg
);
2341 if (estate_has_fuzzy_max(state
)) {
2342 sql_insert_caller_info(expr
, FUZZY_MAX
, i
, "$",
2343 sval_to_str(estate_get_fuzzy_max(state
)));
2346 } END_FOR_EACH_PTR(arg
);
2349 static void set_param_value(const char *name
, struct symbol
*sym
, char *key
, char *value
)
2351 struct range_list
*rl
= NULL
;
2352 struct smatch_state
*state
;
2353 struct symbol
*type
;
2357 if (strcmp(key
, "*$") == 0)
2358 snprintf(fullname
, sizeof(fullname
), "*%s", name
);
2359 else if (strncmp(key
, "$", 1) == 0)
2360 snprintf(fullname
, 256, "%s%s", name
, key
+ 1);
2364 type
= get_member_type_from_key(symbol_expression(sym
), key
);
2365 str_to_rl(type
, value
, &rl
);
2366 state
= alloc_estate_rl(rl
);
2367 if (estate_get_single_value(state
, &dummy
))
2368 estate_set_hard_max(state
);
2369 set_state(SMATCH_EXTRA
, fullname
, sym
, state
);
2372 static void set_param_hard_max(const char *name
, struct symbol
*sym
, char *key
, char *value
)
2374 struct range_list
*rl
= NULL
;
2375 struct smatch_state
*state
;
2376 struct symbol
*type
;
2380 if (strcmp(key
, "*$") == 0)
2381 snprintf(fullname
, sizeof(fullname
), "*%s", name
);
2382 else if (strncmp(key
, "$", 1) == 0)
2383 snprintf(fullname
, 256, "%s%s", name
, key
+ 1);
2387 state
= get_state(SMATCH_EXTRA
, fullname
, sym
);
2390 type
= get_member_type_from_key(symbol_expression(sym
), key
);
2391 str_to_rl(type
, value
, &rl
);
2392 if (!rl_to_sval(rl
, &max
))
2394 estate_set_fuzzy_max(state
, max
);
2397 struct smatch_state
*get_extra_state(struct expression
*expr
)
2401 struct smatch_state
*ret
= NULL
;
2402 struct range_list
*rl
;
2404 if (is_pointer(expr
) && get_address_rl(expr
, &rl
))
2405 return alloc_estate_rl(rl
);
2407 name
= expr_to_known_chunk_sym(expr
, &sym
);
2411 ret
= get_state(SMATCH_EXTRA
, name
, sym
);
2417 void register_smatch_extra(int id
)
2421 add_merge_hook(my_id
, &merge_estates
);
2422 add_unmatched_state_hook(my_id
, &unmatched_state
);
2423 select_caller_info_hook(set_param_value
, PARAM_VALUE
);
2424 select_caller_info_hook(set_param_hard_max
, FUZZY_MAX
);
2425 select_return_states_before(&db_limited_before
);
2426 select_return_states_hook(PARAM_LIMIT
, &db_param_limit
);
2427 select_return_states_hook(PARAM_FILTER
, &db_param_filter
);
2428 select_return_states_hook(PARAM_ADD
, &db_param_add
);
2429 select_return_states_hook(PARAM_SET
, &db_param_set
);
2430 select_return_states_hook(PARAM_VALUE
, &db_param_value
);
2431 select_return_states_after(&db_limited_after
);
2434 static void match_link_modify(struct sm_state
*sm
, struct expression
*mod_expr
)
2436 struct var_sym_list
*links
;
2437 struct var_sym
*tmp
;
2438 struct smatch_state
*state
;
2440 links
= sm
->state
->data
;
2442 FOR_EACH_PTR(links
, tmp
) {
2443 if (sm
->sym
== tmp
->sym
&&
2444 strcmp(sm
->name
, tmp
->var
) == 0)
2446 state
= get_state(SMATCH_EXTRA
, tmp
->var
, tmp
->sym
);
2449 set_state(SMATCH_EXTRA
, tmp
->var
, tmp
->sym
, alloc_estate_whole(estate_type(state
)));
2450 } END_FOR_EACH_PTR(tmp
);
2451 set_state(link_id
, sm
->name
, sm
->sym
, &undefined
);
2454 void register_smatch_extra_links(int id
)
2459 void register_smatch_extra_late(int id
)
2461 add_merge_hook(link_id
, &merge_link_states
);
2462 add_modification_hook(link_id
, &match_link_modify
);
2463 add_hook(&match_dereferences
, DEREF_HOOK
);
2464 add_hook(&match_pointer_as_array
, OP_HOOK
);
2465 select_call_implies_hook(DEREFERENCE
, &set_param_dereferenced
);
2466 add_hook(&match_function_call
, FUNCTION_CALL_HOOK
);
2467 add_hook(&match_assign
, ASSIGNMENT_HOOK
);
2468 add_hook(&match_assign
, GLOBAL_ASSIGNMENT_HOOK
);
2469 add_hook(&unop_expr
, OP_HOOK
);
2470 add_hook(&asm_expr
, ASM_HOOK
);
2471 add_untracked_param_hook(&match_untracked_array
);
2473 add_hook(&match_call_info
, FUNCTION_CALL_HOOK
);
2474 add_member_info_callback(my_id
, struct_member_callback
);
2475 add_split_return_callback(&returned_struct_members
);
2477 add_hook(&assume_indexes_are_valid
, OP_HOOK
);