From 98c57a0c58658b9f32479249f3a793952c7308ea Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Wed, 13 Sep 2017 00:35:27 +0300 Subject: [PATCH] debug: introduce __smatch_rl() Normally when I want a range, then I just use a series of if statements to filter out the numbers I don't need. But now I can just say: int x = __smatch_rl("0-9"); Which is simpler. Signed-off-by: Dan Carpenter --- check_debug.c | 15 +++++++-------- check_debug.h | 9 +++++++-- validation/sm_val_parse1.c | 5 +++-- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/check_debug.c b/check_debug.c index d8431c8c..7910d024 100644 --- a/check_debug.c +++ b/check_debug.c @@ -569,22 +569,21 @@ static void match_type(const char *fn, struct expression *expr, void *info) free_string(name); } -static void match_type_rl(const char *fn, struct expression *expr, void *info) +static int match_type_rl_return(struct expression *call, void *unused, struct range_list **rl) { struct expression *one, *two; struct symbol *type; - struct range_list *rl; - one = get_argument_from_call_expr(expr->args, 0); + one = get_argument_from_call_expr(call->args, 0); type = get_type(one); - two = get_argument_from_call_expr(expr->args, 1); + two = get_argument_from_call_expr(call->args, 1); if (!two || two->type != EXPR_STRING) { sm_msg("expected: __smatch_type_rl(type, \"string\")"); - return; + return 0; } - call_results_to_rl(expr, type, two->string->data, &rl); - sm_msg("'%s' => '%s'", two->string->data, show_rl(rl)); + call_results_to_rl(call, type, two->string->data, rl); + return 1; } static void print_left_right(struct sm_state *sm) @@ -718,7 +717,7 @@ void check_debug(int id) add_function_hook("__smatch_debug_implied_off", &match_debug_implied_off, NULL); add_function_hook("__smatch_intersection", &match_intersection, NULL); add_function_hook("__smatch_type", &match_type, NULL); - add_function_hook("__smatch_type_rl_helper", match_type_rl, NULL); + add_implied_return_hook("__smatch_type_rl_helper", &match_type_rl_return, NULL); add_function_hook("__smatch_merge_tree", &match_print_merge_tree, NULL); add_function_hook("__smatch_stree_id", &match_print_stree_id, NULL); add_function_hook("__smatch_exit", &match_exit, NULL); diff --git a/check_debug.h b/check_debug.h index 82842368..00e81e2e 100644 --- a/check_debug.h +++ b/check_debug.h @@ -53,8 +53,13 @@ static inline void __smatch_debug_implied_off(void){} static inline void __smatch_intersection(long long one, long long two){} static inline void __smatch_type(long long one){} -static inline void __smatch_type_rl_helper(long long type, const char *str, ...){} -#define __smatch_type_rl(type, rl, other...) __smatch_type_rl_helper((type)0, rl, other) +static long long __smatch_val; +static inline long long __smatch_type_rl_helper(long long type, const char *str, ...) +{ + return __smatch_val; +} +#define __smatch_type_rl(type, fmt...) __smatch_type_rl_helper((type)0, fmt) +#define __smatch_rl(fmt...) __smatch_type_rl(long long, fmt) static inline void __smatch_bit_info(long long expr){} diff --git a/validation/sm_val_parse1.c b/validation/sm_val_parse1.c index 0a72352c..f1c1fcd5 100644 --- a/validation/sm_val_parse1.c +++ b/validation/sm_val_parse1.c @@ -2,7 +2,8 @@ int main(int x) { - __smatch_type_rl(int, "s32min-s32max[$2 + 4]", 5); + x = __smatch_type_rl(int, "s32min-s32max[$2 + 4]", 5); + __smatch_implied(x); return 0; } @@ -11,6 +12,6 @@ int main(int x) * check-command: smatch -I.. sm_val_parse1.c * * check-output-start -sm_val_parse1.c:5 main() 's32min-s32max[$2 + 4]' => '9' +sm_val_parse1.c:6 main() implied: x = '9' * check-output-end */ -- 2.11.4.GIT