flow: introduce outside_of_function() to fix global initializer handling
authorDan Carpenter <dan.carpenter@oracle.com>
Tue, 8 Oct 2013 12:53:59 +0000 (8 15:53 +0300)
committerDan Carpenter <dan.carpenter@oracle.com>
Tue, 8 Oct 2013 12:53:59 +0000 (8 15:53 +0300)
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 <dan.carpenter@oracle.com>
check_missing_break.c
smatch.h
smatch_extra.c
smatch_flow.c

index 2c78112..7222767 100644 (file)
@@ -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;
index 45cbeca..ad6e781 100644 (file)
--- 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);
index 46f4cd9..21b1d64 100644 (file)
@@ -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));
 }
 
index 0d5c570..d97c036 100644 (file)
@@ -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();