user_data: delete debug code
[smatch.git] / smatch_param_used.c
blob5b3a31ed8da446057ccc632853682aa59c64b5dc
1 /*
2 * Copyright (C) 2015 Oracle.
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
18 #include "smatch.h"
19 #include "smatch_slist.h"
21 static int my_id;
23 static struct stree *used_stree;
25 STATE(used);
27 static void get_state_hook(int owner, const char *name, struct symbol *sym)
29 int arg;
31 if (!option_info)
32 return;
34 if (__in_fake_assign || __in_fake_parameter_assign || __in_function_def || __in_unmatched_hook)
35 return;
37 arg = get_param_num_from_sym(sym);
38 if (arg < 0)
39 return;
40 if (param_was_set_var_sym(name, sym))
41 return;
42 set_state_stree(&used_stree, my_id, name, sym, &used);
45 static void set_param_used(struct expression *call, struct expression *arg, char *key, char *unused)
47 struct symbol *sym;
48 char *name;
49 int arg_nr;
51 if (!option_info)
52 return;
54 name = get_variable_from_key(arg, key, &sym);
55 if (!name || !sym)
56 goto free;
58 arg_nr = get_param_num_from_sym(sym);
59 if (arg_nr < 0)
60 goto free;
61 if (param_was_set_var_sym(name, sym))
62 goto free;
63 set_state_stree(&used_stree, my_id, name, sym, &used);
64 free:
65 free_string(name);
68 static void process_states(void)
70 struct sm_state *tmp;
71 int arg;
72 const char *name;
74 FOR_EACH_SM(used_stree, tmp) {
75 arg = get_param_num_from_sym(tmp->sym);
76 if (arg < 0)
77 continue;
78 name = get_param_name(tmp);
79 if (!name)
80 continue;
81 if (strcmp(name, "$") == 0 ||
82 strcmp(name, "*$") == 0)
83 continue;
84 if (is_recursive_member(name))
85 continue;
87 if (is_ignored_kernel_data(name))
88 continue;
90 sql_insert_return_implies(PARAM_USED, arg, name, "");
91 } END_FOR_EACH_SM(tmp);
93 free_stree(&used_stree);
96 static void match_function_def(struct symbol *sym)
98 free_stree(&used_stree);
101 void register_param_used(int id)
103 my_id = id;
105 add_hook(&match_function_def, AFTER_FUNC_HOOK);
106 add_function_data((unsigned long *)&used_stree);
108 add_get_state_hook(&get_state_hook);
110 select_return_implies_hook(PARAM_USED, &set_param_used);
111 all_return_states_hook(&process_states);