From 186ab734a040e3448e57a444fe4f4bf831160fff Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Mon, 11 Sep 2017 12:05:14 +0300 Subject: [PATCH] extra: add extra_nomod_hooks This is a hook for when we set nomod states (normally because of conditions). It's like the mod hooks. I'm going to use it for check_user_data2.c. Signed-off-by: Dan Carpenter --- smatch_extra.c | 35 ++++++++++++++++++++++++++++++----- smatch_extra.h | 1 + 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/smatch_extra.c b/smatch_extra.c index 36151c74..1063712d 100644 --- a/smatch_extra.c +++ b/smatch_extra.c @@ -63,6 +63,8 @@ static int in_warn_on_macro(void) typedef void (mod_hook)(const char *name, struct symbol *sym, struct smatch_state *state); DECLARE_PTR_LIST(void_fn_list, mod_hook *); static struct void_fn_list *extra_mod_hooks; +static struct void_fn_list *extra_nomod_hooks; + void add_extra_mod_hook(mod_hook *fn) { mod_hook **p = malloc(sizeof(mod_hook *)); @@ -70,15 +72,32 @@ void add_extra_mod_hook(mod_hook *fn) add_ptr_list(&extra_mod_hooks, p); } -void call_extra_mod_hooks(const char *name, struct symbol *sym, struct smatch_state *state) +void add_extra_nomod_hook(mod_hook *fn) +{ + mod_hook **p = malloc(sizeof(mod_hook *)); + *p = fn; + add_ptr_list(&extra_nomod_hooks, p); +} + +void call_extra_hooks(struct void_fn_list *hooks, const char *name, struct symbol *sym, struct smatch_state *state) { mod_hook **fn; - FOR_EACH_PTR(extra_mod_hooks, fn) { + FOR_EACH_PTR(hooks, fn) { (*fn)(name, sym, state); } END_FOR_EACH_PTR(fn); } +void call_extra_mod_hooks(const char *name, struct symbol *sym, struct smatch_state *state) +{ + call_extra_hooks(extra_mod_hooks, name, sym, state); +} + +void call_extra_nomod_hooks(const char *name, struct symbol *sym, struct smatch_state *state) +{ + call_extra_hooks(extra_nomod_hooks, name, sym, state); +} + static bool in_param_set; static void set_extra_mod_helper(const char *name, struct symbol *sym, struct smatch_state *state) { @@ -90,6 +109,12 @@ static void set_extra_mod_helper(const char *name, struct symbol *sym, struct sm set_state(SMATCH_EXTRA, name, sym, state); } +static void set_extra_nomod_helper(const char *name, struct symbol *sym, struct smatch_state *state) +{ + call_extra_nomod_hooks(name, sym, state); + set_state(SMATCH_EXTRA, name, sym, state); +} + static char *get_pointed_at(const char *name, struct symbol *sym, struct symbol **new_sym) { struct expression *assigned; @@ -246,11 +271,11 @@ void set_extra_nomod(const char *name, struct symbol *sym, struct smatch_state * new_name = get_other_name_sym(name, sym, &new_sym); if (new_name && new_sym) - set_state(SMATCH_EXTRA, new_name, new_sym, state); + set_extra_nomod_helper(new_name, new_sym, state); free_string(new_name); if (!estate_related(orig_state)) { - set_state(SMATCH_EXTRA, name, sym, state); + set_extra_nomod_helper(name, sym, state); return; } @@ -263,7 +288,7 @@ void set_extra_nomod(const char *name, struct symbol *sym, struct smatch_state * estate = get_state(SMATCH_EXTRA, rel->name, rel->sym); if (!estate) continue; - set_state(SMATCH_EXTRA, rel->name, rel->sym, clone_estate_cast(estate_type(estate), state)); + set_extra_nomod_helper(rel->name, rel->sym, clone_estate_cast(estate_type(estate), state)); } END_FOR_EACH_PTR(rel); } diff --git a/smatch_extra.h b/smatch_extra.h index 94415a61..6b7cabdd 100644 --- a/smatch_extra.h +++ b/smatch_extra.h @@ -161,6 +161,7 @@ void set_extra_expr_nomod(struct expression *expr, struct smatch_state *state); struct data_info *get_dinfo(struct smatch_state *state); void add_extra_mod_hook(void (*fn)(const char *name, struct symbol *sym, struct smatch_state *state)); +void add_extra_nomod_hook(void (*fn)(const char *name, struct symbol *sym, struct smatch_state *state)); int implied_not_equal(struct expression *expr, long long val); int implied_not_equal_name_sym(char *name, struct symbol *sym, long long val); int parent_is_null_var_sym(const char *name, struct symbol *sym); -- 2.11.4.GIT