kernel_user_data: delete some dead code
[smatch.git] / smatch_kernel_atomic_dec_test_path.c
blob25026e492077376fdf4f4ba1aa2d59c2bd992cea
1 /*
2 * Copyright (C) 2016 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(zero_path);
26 static void handle_test_functions(struct expression *expr)
28 struct expression *tmp;
29 struct statement *stmt;
30 int count = 0;
32 if (expr->type != EXPR_CALL ||
33 expr->fn->type != EXPR_SYMBOL ||
34 !expr->fn->symbol_name)
35 return;
36 if (!strstr(expr->fn->symbol_name->name, "test"))
37 return;
39 while ((tmp = expr_get_parent_expr(expr))) {
40 expr = tmp;
41 if (count++ > 5)
42 break;
45 stmt = expr_get_parent_stmt(expr);
46 if (!stmt || stmt->type != STMT_IF)
47 return;
49 set_true_false_states(my_id, "dec_path", NULL, &zero_path, NULL);
52 static void match_dec(struct expression *expr, const char *name, struct symbol *sym)
54 handle_test_functions(expr);
57 int on_atomic_dec_path(void)
59 return get_state(my_id, "dec_path", NULL) == &zero_path;
62 void register_kernel_atomic_dec_test_path(int id)
64 my_id = id;
66 if (option_project != PROJ_KERNEL)
67 return;
69 add_refcount_dec_hook(&match_dec);