From bb7951ebe8d9430cec09f26caa185940b70e577e Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Thu, 8 Dec 2011 10:17:36 +0300 Subject: [PATCH] debug: add __smatch_implied_min/max() You can put this into the code you are compiling to see what Smatch thinks is the implied min and max values for a variable or equation. Signed-off-by: Dan Carpenter --- check_debug.c | 28 ++++++++++++++++++++++++++++ check_debug.h | 2 ++ 2 files changed, 30 insertions(+) diff --git a/check_debug.c b/check_debug.c index 3ed3a19a..120f0fc4 100644 --- a/check_debug.c +++ b/check_debug.c @@ -46,6 +46,32 @@ static void match_print_value(const char *fn, struct expression *expr, void *inf free_slist(&slist); } +static void match_print_implied_min(const char *fn, struct expression *expr, void *info) +{ + struct expression *arg; + long long val; + char *name; + + arg = get_argument_from_call_expr(expr->args, 0); + name = get_variable_from_expr_complex(arg, NULL); + if (!get_implied_min(arg, &val)) + val = whole_range.min; + sm_msg("implied min: %s = %lld", name, val); +} + +static void match_print_implied_max(const char *fn, struct expression *expr, void *info) +{ + struct expression *arg; + long long val; + char *name; + + arg = get_argument_from_call_expr(expr->args, 0); + name = get_variable_from_expr_complex(arg, NULL); + if (!get_implied_max(arg, &val)) + val = whole_range.max; + sm_msg("implied max: %s = %lld", name, val); +} + static void print_possible(struct sm_state *sm) { struct sm_state *tmp; @@ -103,6 +129,8 @@ void check_debug(int id) my_id = id; add_function_hook("__smatch_all_values", &match_all_values, NULL); add_function_hook("__smatch_value", &match_print_value, NULL); + add_function_hook("__smatch_implied_min", &match_print_implied_min, NULL); + add_function_hook("__smatch_implied_max", &match_print_implied_max, NULL); add_function_hook("__smatch_possible", &match_possible, NULL); add_function_hook("__smatch_cur_slist", &match_cur_slist, NULL); add_function_hook("__smatch_note", &match_note, NULL); diff --git a/check_debug.h b/check_debug.h index 711b5e51..7f8ad66d 100644 --- a/check_debug.h +++ b/check_debug.h @@ -4,6 +4,8 @@ static inline void __smatch_cur_slist(void){} static inline void __smatch_all_values(void){} static inline void __smatch_value(const char *unused){} +static inline void __smatch_implied_min(long long val){} +static inline void __smatch_implied_max(long long val){} static inline void __smatch_possible(const char *unused){} static inline void __smatch_print_value(const char *unused){} static inline void __smatch_note(const char *note){} -- 2.11.4.GIT