2 * sparse/check_dereferences_param.c
4 * Copyright (C) 2012 Oracle.
6 * Licensed under the Open Software License version 1.1
11 #include "smatch_extra.h"
12 #include "smatch_slist.h"
20 static int is_arg(struct expression
*expr
)
24 if (expr
->type
!= EXPR_SYMBOL
)
27 FOR_EACH_PTR(cur_func_sym
->ctype
.base_type
->arguments
, arg
) {
28 if (arg
== expr
->symbol
)
30 } END_FOR_EACH_PTR(arg
);
34 static void set_ignore(struct sm_state
*sm
)
36 if (sm
->state
== &derefed
)
38 set_state(my_id
, sm
->name
, sm
->sym
, &ignore
);
41 static void match_function_def(struct symbol
*sym
)
47 FOR_EACH_PTR(sym
->ctype
.base_type
->arguments
, arg
) {
51 set_state(my_id
, arg
->ident
->name
, arg
, ¶m
);
52 } END_FOR_EACH_PTR(arg
);
55 static void check_deref(struct expression
*expr
)
59 expr
= strip_expr(expr
);
63 if (implied_not_equal(expr
, 0))
66 sm
= get_sm_state_expr(my_id
, expr
);
67 if (sm
&& slist_has_state(sm
->possible
, &ignore
))
69 set_state_expr(my_id
, expr
, &derefed
);
72 static void match_dereference(struct expression
*expr
)
74 if (expr
->type
!= EXPR_PREOP
)
76 if (getting_address())
78 check_deref(expr
->unop
);
81 static void set_param_dereferenced(struct expression
*arg
, char *unused
)
86 static void process_states(struct state_list
*slist
)
92 FOR_EACH_PTR(cur_func_sym
->ctype
.base_type
->arguments
, arg
) {
96 if (get_state_slist(slist
, my_id
, arg
->ident
->name
, arg
) == &derefed
)
97 sm_msg("info: dereferences_param %d %s", i
, global_static());
98 } END_FOR_EACH_PTR(arg
);
101 void check_dereferences_param(int id
)
108 add_hook(&match_function_def
, FUNC_DEF_HOOK
);
110 add_hook(&match_dereference
, DEREF_HOOK
);
111 add_db_fn_call_callback(DEREFERENCE
, &set_param_dereferenced
);
112 add_modification_hook(my_id
, &set_ignore
);
114 all_return_states_hook(&process_states
);