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
19 #include "smatch_slist.h"
22 int __ignore_param_used
;
24 static struct stree
*used_stree
;
28 static void get_state_hook(int owner
, const char *name
, struct symbol
*sym
)
30 static const char *prev
;
36 if (__ignore_param_used
||
38 __in_fake_parameter_assign
||
43 if (!name
|| name
[0] == '&')
50 arg
= get_param_num_from_sym(sym
);
53 if (param_was_set_var_sym(name
, sym
))
55 if (parent_was_PARAM_CLEAR(name
, sym
))
58 set_state_stree(&used_stree
, my_id
, name
, sym
, &used
);
61 static void set_param_used(struct expression
*call
, struct expression
*arg
, char *key
, char *unused
)
73 name
= get_variable_from_key(arg
, key
, &sym
);
77 arg_nr
= get_param_num_from_sym(sym
);
80 if (param_was_set_var_sym(name
, sym
))
82 set_state_stree(&used_stree
, my_id
, name
, sym
, &used
);
87 static void process_states(void)
93 FOR_EACH_SM(used_stree
, tmp
) {
94 arg
= get_param_num_from_sym(tmp
->sym
);
97 name
= get_param_name(tmp
);
100 if (strcmp(name
, "$") == 0 ||
101 strcmp(name
, "*$") == 0)
103 if (is_recursive_member(name
))
106 if (is_ignored_kernel_data(name
))
109 sql_insert_return_implies(PARAM_USED
, arg
, name
, "");
110 } END_FOR_EACH_SM(tmp
);
112 free_stree(&used_stree
);
115 static void match_function_def(struct symbol
*sym
)
117 free_stree(&used_stree
);
120 void register_param_used(int id
)
124 add_hook(&match_function_def
, AFTER_FUNC_HOOK
);
125 add_function_data((unsigned long *)&used_stree
);
127 add_get_state_hook(&get_state_hook
);
129 select_return_implies_hook(PARAM_USED
, &set_param_used
);
130 all_return_states_hook(&process_states
);