1 /*
2 * Copyright (C) 2011 Dan Carpenter.
3 *
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.
8 *
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.
13 *
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
16 */
17
18 #include "smatch.h"
19
20 static int my_id;
21
match_assign(struct expression * expr)22 static void match_assign(struct expression *expr)
23 {
24 const char *macro;
25 sval_t max_left, max_right;
26 char *name;
27
28 if (expr->op != '=')
29 return;
30
31 macro = get_macro_name(expr->pos);
32 if (!macro)
33 return;
34 if (strcmp(macro, "min_t"))
35 return;
36
37 if (!get_absolute_max(expr->left, &max_left))
38 return;
39 if (!get_absolute_max(expr->right, &max_right))
40 return;
41
42 if (sval_cmp(max_left, max_right) >= 0)
43 return;
44
45 name = expr_to_str(expr->right);
46 sm_warning("min_t truncates here '%s' (%s vs %s)", name, sval_to_str(max_left), sval_to_str(max_right));
47 free_string(name);
48 }
49
check_min_t(int id)50 void check_min_t(int id)
51 {
52 my_id = id;
53 if (option_project != PROJ_KERNEL)
54 return;
55 add_hook(&match_assign, ASSIGNMENT_HOOK);
56 }
57