2 * smatch/check_propagate.c
4 * Copyright (C) 2010 Dan Carpenter.
6 * Licensed under the Open Software License version 1.1
11 * People should just return the error codes they received
12 * instead of making up there own dumb error codes all the time.
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
)
26 if (expr
->fn
->type
!= EXPR_SYMBOL
)
28 return expr_to_var(expr
->fn
);
31 static void match_call_assignment(struct expression
*expr
)
33 if (get_macro_name(expr
->left
->pos
))
35 last_return
= expr
->left
;
36 last_func
= expr
->right
;
39 static void match_unset(struct expression
*expr
)
44 static void match_return(struct expression
*ret_value
)
50 if (!get_value(ret_value
, &rval
) || rval
.value
>= 0)
52 if (get_implied_value(last_return
, &lret
))
54 if (!get_implied_max(last_return
, &lret
) || lret
.value
>= 0)
56 if (get_implied_min(last_return
, &lret
) && !sval_is_min(lret
))
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
));
64 void check_propagate(int id
)
66 if (option_project
!= PROJ_KERNEL
)
70 add_hook(&match_unset
, ASSIGNMENT_HOOK
);
71 add_hook(&match_call_assignment
, CALL_ASSIGNMENT_HOOK
);
72 add_hook(&match_return
, RETURN_HOOK
);