Print this page
12166 resync smatch to 0.6.1-rc1-il-3

Split Close
Expand all
Collapse all
          --- old/usr/src/tools/smatch/src/check_param_mapper.c
          +++ new/usr/src/tools/smatch/src/check_param_mapper.c
↓ open down ↓ 15 lines elided ↑ open up ↑
  16   16   */
  17   17  
  18   18  /*
  19   19   * The idea behind this test is that if we have:
  20   20   * void foo(int bar)
  21   21   * {
  22   22   *         baz(1, bar);
  23   23   * }
  24   24   *
  25   25   * Passing "bar" to foo() really means passing "bar" to baz();
  26      - * 
       26 + *
  27   27   * In this case it would print:
  28   28   * info: param_mapper 0 => bar 1
  29   29   *
  30   30   */
  31   31  
  32   32  #include "smatch.h"
  33   33  
  34   34  static int my_id;
  35   35  
  36      -STATE(argument);
  37      -
  38      -static struct symbol *func_sym;
  39      -
  40      -static void delete(struct sm_state *sm, struct expression *mod_expr)
  41      -{
  42      -        set_state(my_id, sm->name, sm->sym, &undefined);
  43      -}
  44      -
  45      -static void match_function_def(struct symbol *sym)
  46      -{
  47      -        struct symbol *arg;
  48      -
  49      -        func_sym = sym;
  50      -        FOR_EACH_PTR(func_sym->ctype.base_type->arguments, arg) {
  51      -                if (!arg->ident) {
  52      -                        continue;
  53      -                }
  54      -                set_state(my_id, arg->ident->name, arg, &argument);
  55      -        } END_FOR_EACH_PTR(arg);
  56      -}
  57      -
  58      -static int get_arg_num(struct expression *expr)
  59      -{
  60      -        struct smatch_state *state;
  61      -        struct symbol *arg;
  62      -        struct symbol *this_arg;
  63      -        int i;
  64      -
  65      -        expr = strip_expr(expr);
  66      -        if (expr->type != EXPR_SYMBOL)
  67      -                return -1;
  68      -        this_arg = expr->symbol;
  69      -
  70      -        state = get_state_expr(my_id, expr);
  71      -        if (!state || state != &argument)
  72      -                return -1;
  73      -        
  74      -        i = 0;
  75      -        FOR_EACH_PTR(func_sym->ctype.base_type->arguments, arg) {
  76      -                if (arg == this_arg)
  77      -                        return i;
  78      -                i++;
  79      -        } END_FOR_EACH_PTR(arg);
  80      -
  81      -        return -1;
  82      -}
  83      -
  84   36  static void match_call(struct expression *expr)
  85   37  {
  86   38          struct expression *tmp;
  87   39          char *func;
  88   40          int arg_num;
  89   41          int i;
  90   42  
  91   43          if (expr->fn->type != EXPR_SYMBOL)
  92   44                  return;
  93   45  
  94   46          func = expr->fn->symbol_name->name;
  95   47  
  96      -        i = 0;
       48 +        i = -1;
  97   49          FOR_EACH_PTR(expr->args, tmp) {
  98      -                tmp = strip_expr(tmp);
  99      -                arg_num = get_arg_num(tmp);
 100      -                if (arg_num >= 0)
 101      -                        sm_msg("info: param_mapper %d => %s %d", arg_num, func, i);
 102   50                  i++;
       51 +                tmp = strip_expr(tmp);
       52 +                if (tmp->type != EXPR_SYMBOL)
       53 +                        continue;
       54 +                if (param_was_set(tmp))
       55 +                        continue;
       56 +                arg_num = get_param_num_from_sym(tmp->symbol);
       57 +                if (arg_num < 0)
       58 +                        continue;
       59 +                sm_msg("info: param_mapper %d => %s %d", arg_num, func, i);
 103   60          } END_FOR_EACH_PTR(tmp);
 104   61  }
 105   62  
 106   63  void check_param_mapper(int id)
 107   64  {
 108      -        if (!option_param_mapper)
       65 +        if (!option_info)
 109   66                  return;
 110   67          my_id = id;
 111      -        add_modification_hook(my_id, &delete);
 112      -        add_hook(&match_function_def, FUNC_DEF_HOOK);
 113   68          add_hook(&match_call, FUNCTION_CALL_HOOK);
 114   69  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX