ranges: rename alloc_range_list() and friends to alloc_rl()
[smatch.git] / check_min_t.c
blobb28b8b4b065ca72aaaf7508c1906b6cb8d53f699
1 /*
2 * smatch/check_min_t.c
4 * Copyright (C) 2011 Dan Carpenter.
6 * Licensed under the Open Software License version 1.1
8 */
10 #include "smatch.h"
12 static int my_id;
14 static void match_assign(struct expression *expr)
16 const char *macro;
17 sval_t max_left, max_right;
18 char *name;
20 if (expr->op != '=')
21 return;
23 macro = get_macro_name(expr->pos);
24 if (!macro)
25 return;
26 if (strcmp(macro, "min_t"))
27 return;
29 if (!get_absolute_max(expr->left, &max_left))
30 return;
31 if (!get_absolute_max(expr->right, &max_right))
32 return;
34 if (sval_cmp(max_left, max_right) >= 0)
35 return;
37 name = get_variable_from_expr_complex(expr->right, NULL);
38 sm_msg("warn: min_t truncates here '%s' (%s vs %s)", name, sval_to_str(max_left), sval_to_str(max_right));
39 free_string(name);
42 void check_min_t(int id)
44 my_id = id;
45 if (option_project != PROJ_KERNEL)
46 return;
47 add_hook(&match_assign, ASSIGNMENT_HOOK);