unwind: ignore path states in pre-merge hook
[smatch.git] / check_postop_timeout.c
blob0693d7b03392c2e745e9a5ac70462812b70e4f04
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 clear(struct sm_state *sm, struct expression *mod_expr)
27 set_state(my_id, sm->name, sm->sym, &undefined);
30 static void match_while_count_down(struct expression *expr)
32 struct statement *stmt = __cur_stmt;
34 if (expr->type != EXPR_POSTOP || expr->op != SPECIAL_DECREMENT)
35 return;
37 if (!stmt || stmt->type != STMT_ITERATOR)
38 return;
40 set_true_false_states_expr(my_id, strip_expr(expr->unop), NULL, &timed_out);
43 static void match_test(struct expression *expr)
45 struct sm_state *sm;
46 char *name;
48 sm = get_sm_state_expr(my_id, expr);
49 if (!sm || !slist_has_state(sm->possible, &timed_out))
50 return;
52 name = expr_to_str(expr);
53 sm_msg("warn: should this be '%s == -1'", name);
54 free_string(name);
57 void check_postop_timeout(int id)
59 my_id = id;
60 add_hook(&match_while_count_down, CONDITION_HOOK);
61 add_hook(&match_test, CONDITION_HOOK);
62 add_modification_hook(my_id, &clear);