math: introduce can_integer_overflow()
[smatch.git] / smatch_impossible.c
blob6b396160608d4f9670fcff468159946501c82af9
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_extra.h"
21 static int my_id;
23 STATE(impossible);
25 int is_impossible_path(void)
27 if (get_state(my_id, "impossible", NULL) == &impossible)
28 return 1;
29 return 0;
32 static void handle_compare(struct expression *left, int op, struct expression *right)
34 if (!possibly_true(left, op, right))
35 set_true_false_states(my_id, "impossible", NULL, &impossible, NULL);
36 if (!possibly_false(left, op, right))
37 set_true_false_states(my_id, "impossible", NULL, NULL, &impossible);
41 static void match_condition(struct expression *expr)
43 if (expr->type == EXPR_COMPARE)
44 handle_compare(expr->left, expr->op, expr->right);
45 else
46 handle_compare(expr, SPECIAL_NOTEQUAL, zero_expr());
49 void register_impossible(int id)
51 my_id = id;
53 add_hook(&match_condition, CONDITION_HOOK);