param_limit: don't print unneeded information
authorDan Carpenter <dan.carpenter@oracle.com>
Sat, 15 Dec 2012 10:19:21 +0000 (15 13:19 +0300)
committerDan Carpenter <dan.carpenter@oracle.com>
Sat, 15 Dec 2012 10:19:21 +0000 (15 13:19 +0300)
If there isn't any limit then don't print that.  This makes the database
a bit smaller.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
smatch.h
smatch_flow.c
smatch_hooks.c
smatch_param_limit.c

index 5ca504c..09f9b24 100644 (file)
--- a/smatch.h
+++ b/smatch.h
@@ -96,6 +96,7 @@ enum hook_type {
        SIZEOF_HOOK,
        BASE_HOOK,
        FUNC_DEF_HOOK,
+       AFTER_DEF_HOOK,
        END_FUNC_HOOK,
        RETURN_HOOK,
        END_FILE_HOOK,
index ec811a6..66970b4 100644 (file)
@@ -818,6 +818,7 @@ static void split_function(struct symbol *sym)
                loop_num = 0;
                final_pass = 0;
                __pass_to_client(sym, FUNC_DEF_HOOK);
+               __pass_to_client(sym, AFTER_DEF_HOOK);
                __split_stmt(base_type->stmt);
                __split_stmt(base_type->inline_stmt);
                nullify_path();
@@ -826,6 +827,7 @@ static void split_function(struct symbol *sym)
        loop_num = 0;
        final_pass = 1;
        __pass_to_client(sym, FUNC_DEF_HOOK);
+       __pass_to_client(sym, AFTER_DEF_HOOK);
        __split_stmt(base_type->stmt);
        __split_stmt(base_type->inline_stmt);
        __pass_to_client(sym, END_FUNC_HOOK);
index 3f84fd0..787170b 100644 (file)
@@ -116,6 +116,9 @@ void add_hook(void *func, enum hook_type type)
        case FUNC_DEF_HOOK:
                container->data_type = SYMBOL_PTR;
                break;
+       case AFTER_DEF_HOOK:
+               container->data_type = SYMBOL_PTR;
+               break;
        case END_FUNC_HOOK:
                container->data_type = SYMBOL_PTR;
                break;
index 778845e..183412b 100644 (file)
@@ -15,6 +15,8 @@ static int orig_id;
 static int modify_id;
 static int side_effects;
 
+static struct smatch_state *orig_states[16];
+
 STATE(modified);
 
 static struct smatch_state *unmatched_state(struct sm_state *sm)
@@ -170,6 +172,26 @@ struct smatch_state *get_orig_estate(struct symbol *sym)
        return get_state(SMATCH_EXTRA, sym->ident->name, sym);
 }
 
+static void match_after_def(struct symbol *sym)
+{
+       struct smatch_state *state;
+       struct symbol *tmp;
+       int param;
+
+       param = -1;
+       FOR_EACH_PTR(cur_func_sym->ctype.base_type->arguments, tmp) {
+               param++;
+               if (param >= 16)
+                       return;
+
+               orig_states[param] = NULL;
+               state = get_orig_estate(tmp);
+               if (!state)
+                       continue;
+               orig_states[param] = state;
+       } END_FOR_EACH_PTR(tmp);
+}
+
 static void print_return_value_param(int return_id, char *return_ranges, struct expression *expr, struct state_list *slist)
 {
        struct smatch_state *state;
@@ -182,6 +204,8 @@ static void print_return_value_param(int return_id, char *return_ranges, struct
                state = get_orig_estate(tmp);
                if (!state)
                        continue;
+               if (range_lists_equiv(estate_ranges(orig_states[param]), estate_ranges(state)))
+                       continue;
                sm_msg("info: return_limited_param %d %d '%s' '$$' '%s' %s",
                       return_id, param, return_ranges,
                       state->name, global_static());
@@ -199,6 +223,7 @@ void register_param_limit(int id)
 {
        modify_id = id;
 
+       add_hook(&match_after_def, AFTER_DEF_HOOK);
        add_hook(&match_assign, ASSIGNMENT_HOOK);
        add_hook(&unop_expr, OP_HOOK);
        add_hook(&match_call, FUNCTION_CALL_HOOK);