db: remove return_implies table and related code
authorDan Carpenter <dan.carpenter@oracle.com>
Fri, 14 Dec 2012 13:30:38 +0000 (14 16:30 +0300)
committerDan Carpenter <dan.carpenter@oracle.com>
Fri, 14 Dec 2012 13:30:38 +0000 (14 16:30 +0300)
Everything is in the return_states hook now so none of this is needed.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
check_list.h
check_param_range.c [deleted file]
smatch.h
smatch_function_hooks.c
smatch_project.c
smatch_scripts/db/fill_db_return_implies.pl [deleted file]
smatch_scripts/db/return_implies.schema [deleted file]

index fb3cbb6..6debfae 100644 (file)
@@ -97,7 +97,6 @@ CK(check_return_negative_var)
 CK(check_rosenberg)
 CK(check_wait_for_common)
 CK(check_bogus_irqrestore)
-CK(check_param_range)
 
 /* wine specific stuff */
 CK(check_wine_filehandles)
diff --git a/check_param_range.c b/check_param_range.c
deleted file mode 100644 (file)
index 84683f6..0000000
+++ /dev/null
@@ -1,233 +0,0 @@
-/*
- * sparse/check_param_range.c
- *
- * Copyright (C) 2012 Oracle.
- *
- * Licensed under the Open Software License version 1.1
- *
- */
-
-#include "smatch.h"
-#include "smatch_extra.h"
-#include "smatch_slist.h"
-
-static int my_id;
-
-static int have_returned_zero;
-static struct range_list *param_constraints[16];
-
-
-static struct statement *prev_statement(void)
-{
-       struct statement *tmp;
-       int i;
-
-       i = 0;
-       FOR_EACH_PTR_REVERSE(big_statement_stack, tmp) {
-               if (i++ == 1)
-                       return tmp;
-       } END_FOR_EACH_PTR_REVERSE(tmp);
-       return NULL;
-}
-
-/*
- * on_main_path() is supposed to check for nesting.  As a hack it just counts
- * the current indent level.
- */
-static int on_main_path(struct expression *expr)
-{
-       if (expr->pos.pos == 24)
-               return 1;
-       return 0;
-}
-
-static int is_error_value(struct expression *ret_value)
-{
-       sval_t sval;
-       char *name;
-
-       if (!ret_value)
-               return 0;
-
-       if (ret_value->type != EXPR_PREOP || ret_value->op != '-')
-               return 0;
-
-       if (!get_value(ret_value, &sval))
-               return 0;
-       if (sval.value < -4095 || sval.value >= 0)
-               return 0;
-
-       name = pos_ident(ret_value->unop->pos);
-       if (!name)
-               return 0;
-       if (name[0] == 'E')
-               return 1;
-       return 0;
-}
-
-static struct expression *get_param(struct expression *expr)
-{
-       struct symbol *sym;
-       struct symbol *tmp;
-
-       expr = strip_expr(expr);
-       if (!expr || expr->type != EXPR_SYMBOL)
-               return 0;
-
-       sym = expr->symbol;
-       FOR_EACH_PTR(cur_func_sym->ctype.base_type->arguments, tmp) {
-               if (tmp == sym)
-                       return expr;
-       } END_FOR_EACH_PTR(tmp);
-
-       return NULL;
-}
-
-static int get_param_num(struct expression *expr)
-{
-       struct symbol *sym;
-       struct symbol *tmp;
-       int i;
-
-       expr = strip_expr(expr);
-       if (!expr || expr->type != EXPR_SYMBOL)
-               return -1;
-
-       sym = expr->symbol;
-       i = 0;
-       FOR_EACH_PTR(cur_func_sym->ctype.base_type->arguments, tmp) {
-               if (tmp == sym)
-                       return i;
-               i++;
-       } END_FOR_EACH_PTR(tmp);
-
-       return -1;
-}
-
-static void add_param_constraint(int idx, struct range_list *rl)
-{
-       if (!param_constraints[idx]) {
-               param_constraints[idx] = rl;
-               return;
-       }
-       param_constraints[idx] = range_list_union(param_constraints[idx], rl);
-}
-
-static void handle_condition(struct expression *expr)
-{
-       struct sm_state *sm;
-       struct expression *param;
-       struct state_list *slist = NULL;
-       char *name;
-       struct symbol *sym;
-
-       expr = strip_expr(expr);
-       if (!expr)
-               return;
-
-       switch (expr->type) {
-       case EXPR_LOGICAL:
-               if (expr->op == SPECIAL_LOGICAL_OR) {
-                       handle_condition(expr->left);
-                       handle_condition(expr->right);
-               }
-               return;
-       case EXPR_COMPARE:
-               param = get_param(expr->left);
-               if (param)
-                       break;
-               param = get_param(expr->right);
-               if (param)
-                       break;
-               return;
-       case EXPR_PREOP:
-               if (expr->op == '!') {
-                       param = get_param(expr->unop);
-                       if (param)
-                               break;
-               }
-               return;
-       case EXPR_SYMBOL:
-               param = get_param(expr);
-               if (param)
-                       break;
-               return;
-       default:
-               return;
-       }
-
-       name = get_variable_from_expr(param, &sym);
-       if (!name || !sym)
-               goto free;
-
-       __push_fake_cur_slist();
-       __split_whole_condition(expr);
-
-       sm = get_sm_state(SMATCH_EXTRA, name, sym);
-       if (sm) {
-               int num;
-
-               num = get_param_num(param);
-               add_param_constraint(num, estate_ranges(sm->state));
-       }
-
-       __push_true_states();
-       __use_false_states();
-       __merge_true_states();
-       slist = __pop_fake_cur_slist();
-
-free:
-       free_string(name);
-       free_slist(&slist);
-}
-
-static void match_return(struct expression *ret_value)
-{
-       struct statement *stmt;
-
-       if (have_returned_zero)
-               return;
-       if (possibly_true(ret_value, SPECIAL_EQUAL, zero_expr())) {
-               have_returned_zero = 1;
-               return;
-       }
-
-       if (!on_main_path(ret_value))  /* should we just set have_returned_zero here? */
-               return;
-
-       if (!is_error_value(ret_value))
-               return;
-       stmt = prev_statement();
-       if (!stmt || stmt->type != STMT_IF)
-               return;
-       handle_condition(stmt->if_conditional);
-}
-
-static void match_end_func(struct symbol *sym)
-{
-       int i;
-
-       for (i = 0; i < ARRAY_SIZE(param_constraints); i++) {
-               if (!param_constraints[i])
-                       continue;
-               if (is_whole_range_rl(param_constraints[i]))
-                       continue;
-               sm_msg("info: %s param %d range '%s' implies error return %s",
-                      global_static(), i, show_ranges(param_constraints[i]),
-                      global_static());
-       }
-
-       have_returned_zero = 0;
-       for (i = 0; i < ARRAY_SIZE(param_constraints); i++)
-               param_constraints[i] = NULL;
-}
-
-void check_param_range(int id)
-{
-       if (!option_info || option_project != PROJ_KERNEL)
-               return;
-
-       my_id = id;
-       add_hook(&match_return, RETURN_HOOK);
-       add_hook(&match_end_func, END_FUNC_HOOK);
-}
index b7b13af..5ca504c 100644 (file)
--- a/smatch.h
+++ b/smatch.h
@@ -132,7 +132,6 @@ void add_macro_assign_hook_extra(const char *look_for, func_hook *call_back,
                              void *info);
 void return_implies_state(const char *look_for, long long start, long long end,
                         implication_hook *call_back, void *info);
-void add_db_return_implies_callback(int type, return_implies_hook *callback);
 void add_db_return_states_callback(int type, return_implies_hook *callback);
 int get_implied_return(struct expression *expr, struct range_list **rl);
 
index defd63c..3faadef 100644 (file)
@@ -55,7 +55,6 @@ struct return_implies_callback {
 };
 ALLOCATOR(return_implies_callback, "return_implies callbacks");
 DECLARE_PTR_LIST(db_implies_list, struct return_implies_callback);
-static struct db_implies_list *db_implies_list;
 static struct db_implies_list *db_return_states_list;
 
 static struct fcall_back *alloc_fcall_back(int type, void *call_back,
@@ -125,15 +124,6 @@ void return_implies_state(const char *look_for, long long start, long long end,
        add_callback(func_hash, look_for, cb);
 }
 
-void add_db_return_implies_callback(int type, return_implies_hook *callback)
-{
-       struct return_implies_callback *cb = __alloc_return_implies_callback(0);
-
-       cb->type = type;
-       cb->callback = callback;
-       add_ptr_list(&db_implies_list, cb);
-}
-
 void add_db_return_states_callback(int type, return_implies_hook *callback)
 {
        struct return_implies_callback *cb = __alloc_return_implies_callback(0);
@@ -351,61 +341,6 @@ static int db_compare_callback(void *unused, int argc, char **argv, char **azCol
        return 0;
 }
 
-void compare_db_implies_callbacks(int comparison, struct expression *expr, sval_t sval, int left)
-{
-       struct symbol *sym;
-        static char sql_filter[1024];
-       struct state_list *true_states;
-       struct state_list *false_states;
-       struct sm_state *sm;
-
-       if (expr->fn->type != EXPR_SYMBOL || !expr->fn->symbol)
-               return;
-
-       sym = expr->fn->symbol;
-       if (!sym)
-               return;
-
-       if (sym->ctype.modifiers & MOD_STATIC) {
-               snprintf(sql_filter, 1024,
-                        "file = '%s' and function = '%s' and static = '1';",
-                        get_filename(), sym->ident->name);
-       } else {
-               snprintf(sql_filter, 1024,
-                        "function = '%s' and static = '0';", sym->ident->name);
-       }
-
-       db_info.comparison = comparison;
-       db_info.expr = expr;
-       db_info.rl = alloc_range_list(sval, sval);
-       db_info.left = left;
-       db_info.callbacks = db_implies_list;
-
-       db_info.true_side = 1;
-       __push_fake_cur_slist();
-       run_sql(db_compare_callback,
-               "select return, type, parameter, key, value from return_implies where %s",
-               sql_filter);
-       true_states = __pop_fake_cur_slist();
-
-       db_info.true_side = 0;
-       __push_fake_cur_slist();
-       run_sql(db_compare_callback,
-               "select return, type, parameter, key, value from return_implies where %s",
-               sql_filter);
-       false_states = __pop_fake_cur_slist();
-
-       FOR_EACH_PTR(true_states, sm) {
-               __set_true_false_sm(sm, NULL);
-       } END_FOR_EACH_PTR(sm);
-       FOR_EACH_PTR(false_states, sm) {
-               __set_true_false_sm(NULL, sm);
-       } END_FOR_EACH_PTR(sm);
-
-       free_slist(&true_states);
-       free_slist(&false_states);
-}
-
 void compare_db_return_states_callbacks(int comparison, struct expression *expr, sval_t sval, int left)
 {
        struct symbol *sym;
@@ -467,78 +402,9 @@ void function_comparison(int comparison, struct expression *expr, sval_t sval, i
 {
        if (call_implies_callbacks(comparison, expr, sval, left))
                return;
-       compare_db_implies_callbacks(comparison, expr, sval, left);
        compare_db_return_states_callbacks(comparison, expr, sval, left);
 }
 
-static int db_assign_callback(void *unused, int argc, char **argv, char **azColName)
-{
-       struct range_list *ret_range;
-       int type, param;
-       char *key, *value;
-       struct return_implies_callback *tmp;
-       struct state_list *slist;
-
-       if (argc != 5)
-               return 0;
-
-       parse_value_ranges_type(get_type(db_info.expr->right), argv[0], &ret_range);
-       type = atoi(argv[1]);
-       param = atoi(argv[2]);
-       key = argv[3];
-       value = argv[4];
-
-       __push_fake_cur_slist();
-       FOR_EACH_PTR(db_implies_list, tmp) {
-               if (tmp->type == type)
-                       tmp->callback(db_info.expr->right, param, key, value);
-       } END_FOR_EACH_PTR(tmp);
-       ret_range = cast_rl(get_type(db_info.expr->left), ret_range);
-       set_extra_expr_mod(db_info.expr->left, alloc_estate_range_list(ret_range));
-       slist = __pop_fake_cur_slist();
-
-       merge_slist(&db_info.slist, slist);
-
-       return 0;
-}
-
-static int db_return_implies_assign(struct expression *expr)
-{
-       struct symbol *sym;
-        static char sql_filter[1024];
-       static struct sm_state *sm;
-       int handled = 0;
-
-       if (expr->right->fn->type != EXPR_SYMBOL || !expr->right->fn->symbol)
-               return 0;
-
-       sym = expr->right->fn->symbol;
-       if (!sym)
-               return 0;
-
-       if (sym->ctype.modifiers & MOD_STATIC) {
-               snprintf(sql_filter, 1024,
-                        "file = '%s' and function = '%s' and static = '1';",
-                        get_filename(), sym->ident->name);
-       } else {
-               snprintf(sql_filter, 1024,
-                        "function = '%s' and static = '0';", sym->ident->name);
-       }
-
-       db_info.expr = expr;
-       db_info.slist = NULL;
-       run_sql(db_assign_callback,
-               "select return, type, parameter, key, value from return_implies where %s",
-               sql_filter);
-
-       FOR_EACH_PTR(db_info.slist, sm) {
-               __set_sm(sm);
-               handled = 1;
-       } END_FOR_EACH_PTR(sm);
-
-       return handled;
-}
-
 static int prev_return_id;
 static int db_assign_return_states_callback(void *unused, int argc, char **argv, char **azColName)
 {
@@ -656,7 +522,6 @@ static void match_assign_call(struct expression *expr)
        call_call_backs(call_backs, ASSIGN_CALL, fn, expr);
 
        handled |= db_return_states_assign(expr);
-       handled |= db_return_implies_assign(expr);
        handled |= assign_ranged_funcs(fn, expr, call_backs);
        handled |= handle_implied_return(expr);
 
index c104986..7b24908 100644 (file)
@@ -44,19 +44,6 @@ static void register_no_return_funcs(void)
        clear_token_alloc();
 }
 
-static void return_implies(struct expression *call_expr, int param, char *key, char *value)
-{
-       struct range_list *rl;
-       struct expression *arg;
-
-       if (call_expr->type == EXPR_ASSIGNMENT)
-               call_expr = strip_expr(call_expr->right);
-
-       arg = get_argument_from_call_expr(call_expr->args, param);
-       parse_value_ranges_type(get_type(call_expr), value, &rl);
-       set_extra_expr_nomod(arg, alloc_estate_range_list(rl));
-}
-
 static void register_ignored_macros(void)
 {
        struct token *token;
@@ -88,5 +75,4 @@ void register_project(int id)
 {
        register_no_return_funcs();
        register_ignored_macros();
-       add_db_return_implies_callback(RANGE_CAP, &return_implies);
 }
diff --git a/smatch_scripts/db/fill_db_return_implies.pl b/smatch_scripts/db/fill_db_return_implies.pl
deleted file mode 100755 (executable)
index 27b1315..0000000
+++ /dev/null
@@ -1,249 +0,0 @@
-#!/usr/bin/perl
-
-use strict;
-use DBI;
-use bignum;
-
-my $warns = shift;
-
-if (!defined($warns)) {
-    print "usage:  $0 <warns.txt>\n";
-    exit(1);
-}
-
-my $db = DBI->connect("dbi:SQLite:smatch_db.sqlite", "", "", {AutoCommit => 0});
-$db->do("PRAGMA synchronous = OFF");
-$db->do("PRAGMA cache_size = 800000");
-$db->do("PRAGMA journal_mode = OFF");
-
-$db->do("delete from return_implies");
-
-my $type = 7;  # RANGE_CAP
-
-sub get_error_num($)
-{
-    my $str = shift;
-
-    $str =~ s/min/-4095/;
-    if ($str =~ /^\((.*)\)/) {
-        $str = $1;
-    }
-    return $str;
-}
-
-sub get_num($)
-{
-    my $str = shift;
-
-    if ($str =~ /^\((.*)\)/) {
-        $str = $1;
-    }
-    return $str;
-}
-
-sub show_num($)
-{
-    my $str = shift;
-
-    if ($str =~ /^-/) {
-        $str = "($str)";
-    }
-    return $str;
-}
-
-sub show_range($$)
-{
-    my $min = shift;
-    my $max = shift;
-
-    if ($min =~ /^$max$/) {
-        return "$min";
-    }
-    return "$min-$max";
-}
-
-sub get_error_returns($)
-{
-    my $total_ranges = shift;
-    my @error_ranges;
-    my $ret;
-
-    foreach my $range (split(",", $total_ranges)) {
-        my ($range_1, $range_2);
-        my ($min, $max);
-
-        if ($range =~ /(.*[^(])-(.*)/) {
-            $range_1 = $1;
-            $range_2 = $2;
-        } else {
-            $range_1 = $range;
-            $range_2 = $range;
-        }
-
-        $min = get_error_num($range_1);
-        $max = get_error_num($range_2);
-
-        if ($max + 0 < 0) {
-            push @error_ranges, $range;
-        } elsif ($min + 0 < 0) {
-            push @error_ranges, show_num($min) . "-(-1)";
-        }
-    }
-
-    foreach my $range (@error_ranges) {
-        if ($ret) {
-            $ret = $ret . ",";
-        }
-        $ret = $ret . $range;
-    }
-    return $ret;
-}
-
-sub get_success_returns($)
-{
-    my $total_ranges = shift;
-    my @success_ranges;
-    my $ret;
-
-    foreach my $range (split(",", $total_ranges)) {
-        my ($range_1, $range_2);
-        my ($min, $max);
-
-        if ($range =~ /(.*[^(])-(.*)/) {
-            $range_1 = $1;
-            $range_2 = $2;
-        } else {
-            $range_1 = $range;
-            $range_2 = $range;
-        }
-
-        $min = get_error_num($range_1);
-        $max = get_error_num($range_2);
-
-        if ($min + 0 >= 0) {
-            push @success_ranges, $range;
-        } elsif ($max + 0 >= 0 || $max =~ /max/) {
-            push @success_ranges, show_range(0, $range_2);
-        }
-    }
-
-    foreach my $range (@success_ranges) {
-        if ($ret) {
-            $ret = $ret . ",";
-        }
-        $ret = $ret . $range;
-    }
-    return $ret;
-}
-
-sub invert_range($)
-{
-    my $orig = shift;
-    my $old_max;
-    my $ret;
-
-    foreach my $range (split(",", $orig)) {
-        my ($range_1, $range_2);
-        my ($min, $max);
-
-        if ($range =~ /(.*[^(])-(.*)/) {
-            $range_1 = $1;
-            $range_2 = $2;
-        } else {
-            $range_1 = $range;
-            $range_2 = $range;
-        }
-
-        $min = get_num($range_1);
-        $min = show_num($min - 1);
-
-        $max = get_num($range_2);
-        $max = show_num($max + 1);
-
-        if (!defined($old_max)) {
-            if (!($range_1 =~ /min/)) {
-                $ret = "min-" . $min;
-            }
-        } else {
-            if ($ret) {
-                $ret = $ret . ",";
-            }
-
-            $ret = $ret . show_range($old_max, $min);
-        }
-        $old_max = $max;
-    }
-
-    if (!($orig =~ /max$/)) {
-        if ($ret) {
-            $ret = $ret . ",";
-        }
-        $ret = $ret . "$old_max-max";
-    }
-
-    return $ret;
-}
-
-my $old_func = "";
-my $total_returns = "";
-
-open(FILE, "<$warns");
-while (<FILE>) {
-    # test.c:26 func() info: function_return_values '(-20),(-12),0' global
-    if (/.*?:\d+ (\w+)\(\) info: function_return_values '(.*?)'/) {
-        $old_func = $1;
-        $total_returns = $2;
-    }
-
-    # test.c:14 func() info: param 0 range 'min-(-1),12-max' implies error return static
-    if (/(.*?):\d+ (\w+)\(\) info: param (\d+) range '(.*?)' implies error return (global|static)/) {
-        my $file = $1;
-        my $func = $2;
-        my $param = $3;
-        my $bad_range = $4;
-
-        my $static = 0;
-        if ($5 =~ /static/) {
-            $static = 1;
-        }
-
-        my $error_returns;
-        my $success_returns;
-        my $good_range = invert_range($bad_range);
-
-        if (!($func =~ /^$old_func$/)) {
-            next;
-        }
-
-        $error_returns = get_error_returns($total_returns);
-        $success_returns = get_success_returns($total_returns);
-
-        $db->do("insert into return_implies values ('$file', '$func', $static, $type, '$success_returns', $param, '', '$good_range')");
-        $db->do("insert into return_implies values ('$file', '$func', $static, $type, '$error_returns', $param, '', 'min-max')");
-   }
-}
-close(FILE);
-
-
-open(FILE, "<$warns");
-while (<FILE>) {
-    # crypto/cbc.c:54 is_power_of_2() info: bool_return_implication "1" 0 "min-(-1),1-max static"
-    if (/(.*?):\d+ (\w+)\(\) info: bool_return_implication "(.*?)" (\d+) "(.*?)" (global|static)/) {
-        my $file = $1;
-        my $func = $2;
-        my $return_range = $3;
-        my $param = $4;
-        my $implied_range = $5;
-        my $static = 0;
-        if ($6 =~ /static/) {
-            $static = 1;
-        }
-
-        $db->do("insert into return_implies values ('$file', '$func', $static, $type, '$return_range', $param, '', '$implied_range')");
-   }
-}
-close(FILE);
-
-
-$db->commit();
-$db->disconnect();
diff --git a/smatch_scripts/db/return_implies.schema b/smatch_scripts/db/return_implies.schema
deleted file mode 100644 (file)
index 07fdee9..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-CREATE TABLE return_implies (file varchar(256), function varchar(256), static integer, type integer, return varchar(256), parameter integer, key varchar(256), value varchar(256));
-
-CREATE INDEX return_implies_fn_idx on return_implies (function);
-CREATE INDEX return_implies_ff_idx on return_implies (file, function);
-