implied: try again in get_tf_stacks_from_pool()
[smatch.git] / smatch_refcount.c
blob41136094721d0284320863e5a61d45ff6ec76231
1 /*
2 * Copyright (C) 2021 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_extra.h"
20 #include "smatch_slist.h"
22 static int my_id;
24 STATE(inc);
25 STATE(dec);
27 static void match_inc(struct expression *expr, const char *name, struct symbol *sym)
29 set_state(my_id, name, sym, &inc);
32 static void match_dec(struct expression *expr, const char *name, struct symbol *sym)
34 set_state(my_id, name, sym, &dec);
37 int was_inced(const char *name, struct symbol *sym)
39 if (has_possible_state(my_id, name, sym, &inc))
40 return true;
41 return false;
44 int refcount_was_inced_name_sym(const char *name, struct symbol *sym, const char *counter_str)
46 char buf[256];
48 snprintf(buf, sizeof(buf), "%s%s", name, counter_str);
49 return was_inced(buf, sym);
52 int refcount_was_inced(struct expression *expr, const char *counter_str)
54 char *name;
55 struct symbol *sym;
56 int ret = 0;
58 name = expr_to_var_sym(expr, &sym);
59 if (!name || !sym)
60 goto free;
62 ret = refcount_was_inced_name_sym(name, sym, counter_str);
63 free:
64 free_string(name);
65 return ret;
68 void register_refcount(int id)
70 my_id = id;
72 if (option_project != PROJ_KERNEL)
73 return;
75 add_modification_hook(my_id, &set_undefined);
77 add_refcount_inc_hook(&match_inc);
78 add_refcount_dec_hook(&match_dec);