[PATCH smatch-devel 4/5] smatch: add passed-to debug helper
Harshit Mogalapalli <[email protected]>
| Newsgroups | org.kernel.vger.smatch |
|---|---|
| Message-ID | <[email protected]> |
Add __smatch_passed_to() to check_debug so validation and developers can print the linked call history for a variable expression. Cover sequential calls using different argument positions and verify the reported $N indexes. Assisted-by: Codex:5.6 Signed-off-by: Harshit Mogalapalli <[email protected]> --- check_debug.c | 9 +++++++++ check_debug.h | 3 +++ validation/sm_passed_to.c | 21 +++++++++++++++++++++ 3 files changed, 33 insertions(+) create mode 100644 validation/sm_passed_to.c diff --git a/check_debug.c b/check_debug.c index 30b9e617ca5d..59970412a491 100644 --- a/check_debug.c +++ b/check_debug.c @@ -782,6 +782,14 @@ static void match_about(const char *fn, struct expression *expr, void *info) debug_print_about(arg); } +static void match_passed_to(const char *fn, struct expression *expr, void *info) +{ + struct expression *arg; + + arg = get_check_arg(expr, 0); + print_passed_to(arg); +} + static void match_intersection(const char *fn, struct expression *expr, void *info) { struct expression *one, *two; @@ -1173,6 +1181,7 @@ void check_debug(int id) my_id = id; add_function_hook("__smatch_about", &match_about, NULL); + add_function_hook("__smatch_passed_to", &match_passed_to, NULL); add_function_hook("__smatch_all_values", &match_all_values, NULL); add_function_hook("__smatch_state", &match_state, NULL); add_function_hook("__smatch_states", &match_states, NULL); diff --git a/check_debug.h b/check_debug.h index 59714b7b82ab..5758919059cf 100644 --- a/check_debug.h +++ b/check_debug.h @@ -6,6 +6,9 @@ static inline void __smatch_about(long var){} #define __smatch_about(x) __smatch_about(cast_ptr(x)) +static inline void __smatch_passed_to(long var){} +#define __smatch_passed_to(x) __smatch_passed_to(cast_ptr(x)) + static inline void __smatch_cur_stree(void){} static inline void __smatch_all_values(void){} static inline void __smatch_state(const char *check_name, const char *state_name){} diff --git a/validation/sm_passed_to.c b/validation/sm_passed_to.c new file mode 100644 index 000000000000..57c284f96e22 --- /dev/null +++ b/validation/sm_passed_to.c @@ -0,0 +1,21 @@ +#include "check_debug.h" + +void first(int ignored, int value); +void second(int value); + +void func(int value) +{ + first(0, value); + second(value); + __smatch_passed_to(value); +} + +/* + * check-name: smatch passed to + * check-command: smatch -I.. sm_passed_to.c + * + * check-output-start +sm_passed_to.c:10 func() passed to first $1 +sm_passed_to.c:10 func() passed to second $0 + * check-output-end + */ -- 2.52.0