debug: add __smatch_about(var) to print what smatch knows about a variable
[smatch.git] / check_propagate.c
blob0e236ee377bcf563ca30725aba4247c9734e6236
1 /*
2 * smatch/check_propagate.c
4 * Copyright (C) 2010 Dan Carpenter.
6 * Licensed under the Open Software License version 1.1
8 */
11 * People should just return the error codes they received
12 * instead of making up there own dumb error codes all the time.
15 #include "smatch.h"
17 static int my_id;
19 static struct expression *last_return;
20 static struct expression *last_func;
22 static char *get_fn_name(struct expression *expr)
24 if (expr->type != EXPR_CALL)
25 return NULL;
26 if (expr->fn->type != EXPR_SYMBOL)
27 return NULL;
28 return expr_to_var(expr->fn);
31 static void match_call_assignment(struct expression *expr)
33 if (get_macro_name(expr->left->pos))
34 return;
35 last_return = expr->left;
36 last_func = expr->right;
39 static void match_unset(struct expression *expr)
41 last_return = NULL;
44 static void match_return(struct expression *ret_value)
46 sval_t rval;
47 sval_t lret;
48 char *name;
50 if (!get_value(ret_value, &rval) || rval.value >= 0)
51 return;
52 if (get_implied_value(last_return, &lret))
53 return;
54 if (!get_implied_max(last_return, &lret) || lret.value >= 0)
55 return;
56 if (get_implied_min(last_return, &lret) && !sval_is_min(lret))
57 return;
58 name = expr_to_var(last_return);
59 sm_msg("info: why not propagate '%s' from %s() instead of %s?",
60 name, get_fn_name(last_func), sval_to_str(rval));
61 free_string(name);
64 void check_propagate(int id)
66 if (option_project != PROJ_KERNEL)
67 return;
69 my_id = id;
70 add_hook(&match_unset, ASSIGNMENT_HOOK);
71 add_hook(&match_call_assignment, CALL_ASSIGNMENT_HOOK);
72 add_hook(&match_return, RETURN_HOOK);