kernel_atomic_dec_test_path: move this into a separate module
[smatch.git] / check_postop_timeout.c
blob1f7b571f7bbd82150723e71359e957323dea11a4
1 /*
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
18 #include "smatch.h"
19 #include "smatch_slist.h"
21 static int my_id;
23 STATE(timed_out);
25 static void match_while_count_down(struct expression *expr)
27 struct statement *stmt = __cur_stmt;
29 if (expr->type != EXPR_POSTOP || expr->op != SPECIAL_DECREMENT)
30 return;
32 if (!stmt || stmt->type != STMT_ITERATOR)
33 return;
35 set_true_false_states_expr(my_id, strip_expr(expr->unop), NULL, &timed_out);
38 static void match_test(struct expression *expr)
40 struct sm_state *sm;
41 char *name;
43 sm = get_sm_state_expr(my_id, expr);
44 if (!sm || !slist_has_state(sm->possible, &timed_out))
45 return;
47 name = expr_to_str(expr);
48 sm_msg("warn: should this be '%s == -1'", name);
49 free_string(name);
52 void check_postop_timeout(int id)
54 my_id = id;
55 add_hook(&match_while_count_down, CONDITION_HOOK);
56 add_hook(&match_test, CONDITION_HOOK);
57 add_modification_hook(my_id, &set_undefined);