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"
19 static int is_arg(struct expression
*expr
)
23 if (expr
->type
!= EXPR_SYMBOL
)
26 FOR_EACH_PTR(cur_func_sym
->ctype
.base_type
->arguments
, arg
) {
27 if (arg
== expr
->symbol
)
29 } END_FOR_EACH_PTR(arg
);
33 static void set_ignore(const char *name
, struct symbol
*sym
, struct expression
*expr
, void *unused
)
35 if (get_state(my_id
, name
, sym
) == &derefed
)
37 set_state(my_id
, name
, sym
, &ignore
);
40 static void match_function_def(struct symbol
*sym
)
46 FOR_EACH_PTR(sym
->ctype
.base_type
->arguments
, arg
) {
50 add_modification_hook(my_id
, arg
->ident
->name
, &set_ignore
, NULL
);
51 } END_FOR_EACH_PTR(arg
);
54 static void check_deref(struct expression
*expr
)
58 expr
= strip_expr(expr
);
62 if (implied_not_equal(expr
, 0))
65 sm
= get_sm_state_expr(my_id
, expr
);
66 if (sm
&& slist_has_state(sm
->possible
, &ignore
))
68 set_state_expr(my_id
, expr
, &derefed
);
71 static void match_dereference(struct expression
*expr
)
73 if (expr
->type
!= EXPR_PREOP
)
75 if (getting_address())
77 check_deref(expr
->unop
);
80 static void set_param_dereferenced(struct expression
*arg
, char *unused
)
85 static void process_states(struct state_list
*slist
)
91 FOR_EACH_PTR(cur_func_sym
->ctype
.base_type
->arguments
, arg
) {
95 if (get_state_slist(slist
, my_id
, arg
->ident
->name
, arg
) == &derefed
)
96 sm_msg("info: dereferences_param %d", i
);
97 } END_FOR_EACH_PTR(arg
);
100 void check_dereferences_param(int id
)
107 add_hook(&match_function_def
, FUNC_DEF_HOOK
);
109 add_hook(&match_dereference
, DEREF_HOOK
);
110 add_db_fn_call_callback(DEREFERENCE
, &set_param_dereferenced
);
112 all_return_states_hook(&process_states
);