states: remove some dead code
[smatch.git] / check_min_t.c
blob3e4ad138b727ddd5706226e0400b8d3740fc380f
1 /*
2 * Copyright (C) 2011 Dan Carpenter.
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"
20 static int my_id;
22 static void match_assign(struct expression *expr)
24 const char *macro;
25 sval_t max_left, max_right;
26 char *name;
28 if (expr->op != '=')
29 return;
31 macro = get_macro_name(expr->pos);
32 if (!macro)
33 return;
34 if (strcmp(macro, "min_t"))
35 return;
37 if (!get_absolute_max(expr->left, &max_left))
38 return;
39 if (!get_absolute_max(expr->right, &max_right))
40 return;
42 if (sval_cmp(max_left, max_right) >= 0)
43 return;
45 name = expr_to_str(expr->right);
46 sm_msg("warn: min_t truncates here '%s' (%s vs %s)", name, sval_to_str(max_left), sval_to_str(max_right));
47 free_string(name);
50 void check_min_t(int id)
52 my_id = id;
53 if (option_project != PROJ_KERNEL)
54 return;
55 add_hook(&match_assign, ASSIGNMENT_HOOK);