db/fixup_kernel.sh: bitmap_allocate_region doesn't return 1
[smatch.git] / smatch_auto_copy.c
blob00b34112679d6b6919f0dfbd9dadd20dd01705cf
1 /*
2 * Copyright (C) 2014 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 int *auto_copy;
25 void set_auto_copy(int owner)
27 if (owner <= 1 || owner > num_checks) {
28 printf("bogus set_auto_copy()\n");
29 return;
31 auto_copy[owner] = 1;
34 static void match_assign(struct expression *expr)
36 char *left_name = NULL;
37 char *right_name = NULL;
38 struct symbol *left_sym, *right_sym;
39 struct state_list *slist = NULL;
40 struct sm_state *sm;
42 left_name = expr_to_var_sym(expr->left, &left_sym);
43 if (!left_name || !left_sym)
44 goto free;
45 right_name = expr_to_var_sym(expr->right, &right_sym);
46 if (!right_name || !right_sym)
47 goto free;
49 FOR_EACH_SM(__get_cur_stree(), sm) {
50 if (!auto_copy[sm->owner])
51 continue;
52 if (right_sym != sm->sym)
53 continue;
54 if (strcmp(right_name, sm->name) != 0)
55 continue;
56 add_ptr_list(&slist, sm);
57 } END_FOR_EACH_SM(sm);
60 FOR_EACH_PTR(slist, sm) {
61 set_state(sm->owner, left_name, left_sym, sm->state);
62 } END_FOR_EACH_PTR(sm);
64 free:
65 free_slist(&slist);
66 free_string(left_name);
67 free_string(right_name);
70 void register_auto_copy(int id)
72 my_id = id;
73 auto_copy = malloc((num_checks + 1) * sizeof(*auto_copy));
74 memset(auto_copy, 0, (num_checks + 1) * sizeof(*auto_copy));
76 add_hook(&match_assign, ASSIGNMENT_HOOK);