Print this page
new smatch
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/tools/smatch/src/smatch_param_used.c
+++ new/usr/src/tools/smatch/src/smatch_param_used.c
1 1 /*
2 2 * Copyright (C) 2015 Oracle.
3 3 *
4 4 * This program is free software; you can redistribute it and/or
5 5 * modify it under the terms of the GNU General Public License
6 6 * as published by the Free Software Foundation; either version 2
7 7 * of the License, or (at your option) any later version.
8 8 *
9 9 * This program is distributed in the hope that it will be useful,
10 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 * GNU General Public License for more details.
13 13 *
14 14 * You should have received a copy of the GNU General Public License
15 15 * along with this program; if not, see http://www.gnu.org/copyleft/gpl.txt
16 16 */
17 17
18 18 #include "smatch.h"
19 19 #include "smatch_slist.h"
20 20
21 21 static int my_id;
22 22
23 23 static struct stree *used_stree;
↓ open down ↓ |
23 lines elided |
↑ open up ↑ |
24 24 static struct stree_stack *saved_stack;
25 25
26 26 STATE(used);
27 27
28 28 static void get_state_hook(int owner, const char *name, struct symbol *sym)
29 29 {
30 30 int arg;
31 31
32 32 if (!option_info)
33 33 return;
34 - if (__in_fake_assign || __in_fake_parameter_assign || __in_function_def)
34 +
35 + if (__in_fake_assign || __in_fake_parameter_assign || __in_function_def || __in_unmatched_hook)
35 36 return;
36 37
37 38 arg = get_param_num_from_sym(sym);
38 - if (arg >= 0)
39 - set_state_stree(&used_stree, my_id, name, sym, &used);
39 + if (arg < 0)
40 + return;
41 + if (param_was_set_var_sym(name, sym))
42 + return;
43 + set_state_stree(&used_stree, my_id, name, sym, &used);
40 44 }
41 45
42 46 static void set_param_used(struct expression *call, struct expression *arg, char *key, char *unused)
43 47 {
44 48 struct symbol *sym;
45 49 char *name;
46 50 int arg_nr;
47 51
52 + if (!option_info)
53 + return;
54 +
48 55 name = get_variable_from_key(arg, key, &sym);
49 56 if (!name || !sym)
50 57 goto free;
51 58
52 59 arg_nr = get_param_num_from_sym(sym);
53 - if (arg_nr >= 0)
54 - set_state_stree(&used_stree, my_id, name, sym, &used);
60 + if (arg_nr < 0)
61 + goto free;
62 + if (param_was_set_var_sym(name, sym))
63 + goto free;
64 + set_state_stree(&used_stree, my_id, name, sym, &used);
55 65 free:
56 66 free_string(name);
57 67 }
58 68
59 69 static void process_states(void)
60 70 {
61 71 struct sm_state *tmp;
62 72 int arg;
63 73 const char *name;
64 74
65 75 FOR_EACH_SM(used_stree, tmp) {
66 76 arg = get_param_num_from_sym(tmp->sym);
67 77 if (arg < 0)
68 78 continue;
69 79 name = get_param_name(tmp);
70 80 if (!name)
71 81 continue;
72 82 if (is_recursive_member(name))
73 83 continue;
74 84
75 85 if (is_ignored_kernel_data(name))
76 86 continue;
77 87
78 88 sql_insert_return_implies(PARAM_USED, arg, name, "");
79 89 } END_FOR_EACH_SM(tmp);
80 90
81 91 free_stree(&used_stree);
82 92 }
83 93
84 94 static void match_function_def(struct symbol *sym)
85 95 {
86 96 free_stree(&used_stree);
87 97 }
88 98
89 99 static void match_save_states(struct expression *expr)
90 100 {
91 101 push_stree(&saved_stack, used_stree);
92 102 used_stree = NULL;
93 103 }
94 104
95 105 static void match_restore_states(struct expression *expr)
96 106 {
97 107 free_stree(&used_stree);
98 108 used_stree = pop_stree(&saved_stack);
99 109 }
100 110
101 111 void register_param_used(int id)
102 112 {
103 113 my_id = id;
104 114
105 115 add_hook(&match_function_def, FUNC_DEF_HOOK);
106 116
107 117 add_get_state_hook(&get_state_hook);
108 118
109 119 add_hook(&match_save_states, INLINE_FN_START);
110 120 add_hook(&match_restore_states, INLINE_FN_END);
111 121
112 122 select_return_implies_hook(PARAM_USED, &set_param_used);
113 123 all_return_states_hook(&process_states);
114 124 }
↓ open down ↓ |
50 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX