math: remove the get_implied_value_low_overhead() function
[smatch.git] / smatch_param_used.c
blobe81bd8358ad0f7d4a3a7cb5266447d4ff1fe7a5f
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;
24 static struct stree_stack *saved_stack;
26 STATE(used);
28 static void get_state_hook(int owner, const char *name, struct symbol *sym)
30 int arg;
32 if (!option_info)
33 return;
34 if (__in_fake_assign || __in_fake_parameter_assign || __in_function_def)
35 return;
37 arg = get_param_num_from_sym(sym);
38 if (arg >= 0)
39 set_state_stree(&used_stree, my_id, name, sym, &used);
42 static void set_param_used(struct expression *call, struct expression *arg, char *key, char *unused)
44 struct symbol *sym;
45 char *name;
46 int arg_nr;
48 name = get_variable_from_key(arg, key, &sym);
49 if (!name || !sym)
50 goto free;
52 arg_nr = get_param_num_from_sym(sym);
53 if (arg_nr >= 0)
54 set_state_stree(&used_stree, my_id, name, sym, &used);
55 free:
56 free_string(name);
59 static void process_states(void)
61 struct sm_state *tmp;
62 int arg;
63 const char *name;
65 FOR_EACH_SM(used_stree, tmp) {
66 arg = get_param_num_from_sym(tmp->sym);
67 if (arg < 0)
68 continue;
69 name = get_param_name(tmp);
70 if (!name)
71 continue;
72 if (is_recursive_member(name))
73 continue;
75 if (is_ignored_kernel_data(name))
76 continue;
78 sql_insert_return_implies(PARAM_USED, arg, name, "");
79 } END_FOR_EACH_SM(tmp);
81 free_stree(&used_stree);
84 static void match_function_def(struct symbol *sym)
86 free_stree(&used_stree);
89 static void match_save_states(struct expression *expr)
91 push_stree(&saved_stack, used_stree);
92 used_stree = NULL;
95 static void match_restore_states(struct expression *expr)
97 free_stree(&used_stree);
98 used_stree = pop_stree(&saved_stack);
101 void register_param_used(int id)
103 my_id = id;
105 add_hook(&match_function_def, FUNC_DEF_HOOK);
107 add_get_state_hook(&get_state_hook);
109 add_hook(&match_save_states, INLINE_FN_START);
110 add_hook(&match_restore_states, INLINE_FN_END);
112 select_return_implies_hook(PARAM_USED, &set_param_used);
113 all_return_states_hook(&process_states);