From 8680ac3160a9618be0d576002f1a99b8e8b744f3 Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Tue, 8 Oct 2013 15:53:59 +0300 Subject: [PATCH] flow: introduce outside_of_function() to fix global initializer handling These days we do more faking assignments for global initializers. This is an easier API to use. But it means that sometimes we need to know when we are outside of a function so we can ignore those cases. Signed-off-by: Dan Carpenter --- check_missing_break.c | 3 +++ smatch.h | 1 + smatch_extra.c | 2 ++ smatch_flow.c | 11 ++++++++++- 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/check_missing_break.c b/check_missing_break.c index 2c78112f..72227679 100644 --- a/check_missing_break.c +++ b/check_missing_break.c @@ -85,6 +85,9 @@ static void match_assign(struct expression *expr) static void match_symbol(struct expression *expr) { + if (outside_of_function()) + return; + expr = strip_expr(expr); if (expr == skip_this) return; diff --git a/smatch.h b/smatch.h index 45cbeca3..ad6e7819 100644 --- a/smatch.h +++ b/smatch.h @@ -154,6 +154,7 @@ typedef void (modification_hook)(struct sm_state *sm, struct expression *mod_exp void add_modification_hook(int owner, modification_hook *call_back); void add_indirect_modification_hook(int owner, modification_hook *call_back); +int outside_of_function(void); const char *get_filename(void); const char *get_base_file(void); char *get_function(void); diff --git a/smatch_extra.c b/smatch_extra.c index 46f4cd90..21b1d64d 100644 --- a/smatch_extra.c +++ b/smatch_extra.c @@ -739,6 +739,8 @@ static void match_declarations(struct symbol *sym) static void check_dereference(struct expression *expr) { + if (outside_of_function()) + return; set_extra_expr_nomod(expr, alloc_estate_range(valid_ptr_min_sval, valid_ptr_max_sval)); } diff --git a/smatch_flow.c b/smatch_flow.c index 0d5c5708..d97c036a 100644 --- a/smatch_flow.c +++ b/smatch_flow.c @@ -54,6 +54,11 @@ int option_known_conditions = 0; int option_two_passes = 0; struct symbol *cur_func_sym = NULL; +int outside_of_function(void) +{ + return cur_func_sym == NULL; +} + const char *get_filename(void) { if (option_info) @@ -205,7 +210,10 @@ void __split_expr(struct expression *expr) break; __split_expr(expr->right); - __pass_to_client(expr, ASSIGNMENT_HOOK); + if (outside_of_function()) + __pass_to_client(expr, GLOBAL_ASSIGNMENT_HOOK); + else + __pass_to_client(expr, ASSIGNMENT_HOOK); tmp = strip_expr(expr->right); if (tmp->type == EXPR_CALL) __pass_to_client(expr, CALL_ASSIGNMENT_HOOK); @@ -1038,6 +1046,7 @@ static void split_function(struct symbol *sym) __split_stmt(base_type->inline_stmt); __pass_to_client(sym, END_FUNC_HOOK); __pass_to_client(sym, AFTER_FUNC_HOOK); + cur_func_sym = NULL; cur_func = NULL; clear_all_states(); free_data_info_allocs(); -- 2.11.4.GIT