generisize.pl: strip all strings not just the first
[smatch.git] / check_propagate.c
blob949c8c3ec9cedcd49ae9c7a4455d4019bcd3aea8
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 recieved
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 get_variable_from_expr(expr->fn, NULL);
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 long long rval;
47 long long lret;
48 char *name;
50 if (!get_value(ret_value, &rval) || rval >= 0)
51 return;
52 if (get_implied_value(last_return, &lret))
53 return;
54 if (!get_implied_max(last_return, &lret) || lret >= 0)
55 return;
56 if (get_implied_min(last_return, &lret))
57 return;
58 name = get_variable_from_expr(last_return, NULL);
59 sm_msg("info: why not propagate '%s' from %s() instead of %lld?",
60 name, get_fn_name(last_func), 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);