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/smatch_extra.c
          +++ new/usr/src/tools/smatch/src/smatch_extra.c
↓ open down ↓ 186 lines elided ↑ open up ↑
 187  187  static void set_extra_nomod_helper(const char *name, struct symbol *sym, struct expression *expr, struct smatch_state *state)
 188  188  {
 189  189          call_extra_nomod_hooks(name, sym, expr, state);
 190  190          set_state(SMATCH_EXTRA, name, sym, state);
 191  191  }
 192  192  
 193  193  static char *get_pointed_at(const char *name, struct symbol *sym, struct symbol **new_sym)
 194  194  {
 195  195          struct expression *assigned;
 196  196  
      197 +        /*
      198 +         * Imagine we have an assignment: "foo = &addr;" then the other name
      199 +         * of "*foo" is addr.
      200 +         */
      201 +
 197  202          if (name[0] != '*')
 198  203                  return NULL;
 199  204          if (strcmp(name + 1, sym->ident->name) != 0)
 200  205                  return NULL;
 201  206  
 202  207          assigned = get_assigned_expr_name_sym(sym->ident->name, sym);
 203  208          if (!assigned)
 204  209                  return NULL;
 205  210          assigned = strip_parens(assigned);
 206  211          if (assigned->type != EXPR_PREOP || assigned->op != '&')
↓ open down ↓ 40 lines elided ↑ open up ↑
 247  252  }
 248  253  
 249  254  static char *get_long_name_sym(const char *name, struct symbol *sym, struct symbol **new_sym, bool use_stack)
 250  255  {
 251  256          struct expression *tmp;
 252  257          struct sm_state *sm;
 253  258          char buf[256];
 254  259  
 255  260          /*
 256  261           * Just prepend the name with a different name/sym and return that.
 257      -         * For example, if we set "foo->bar = bar;" then we clamp "bar->baz",
 258      -         * that also clamps "foo->bar->baz".
 259      -         *
      262 +         * For example, if we set "foo->bar = bar;" then the other name
      263 +         * for "bar->baz" is "foo->bar->baz".  Or if we have "foo = bar;" then
      264 +         * the other name for "bar" is "foo".  A third option is if we have
      265 +         * "foo = bar;" then another name for "*bar" is "*foo".
 260  266           */
 261  267  
 262  268          FOR_EACH_MY_SM(check_assigned_expr_id, __get_cur_stree(), sm) {
 263  269                  tmp = sm->state->data;
 264  270                  if (!tmp || tmp->type != EXPR_SYMBOL)
 265  271                          continue;
 266  272                  if (tmp->symbol == sym)
 267  273                          goto found;
 268  274          } END_FOR_EACH_SM(sm);
 269  275  
 270  276          return NULL;
 271  277  
 272  278  found:
 273  279          if (!use_stack && name[tmp->symbol->ident->len] != '-')
 274  280                  return NULL;
 275      -        snprintf(buf, sizeof(buf), "%s%s", sm->name, name + tmp->symbol->ident->len);
      281 +
      282 +        if (name[0] == '*' && strcmp(name + 1, tmp->symbol_name->name) == 0)
      283 +                snprintf(buf, sizeof(buf), "*%s", sm->name);
      284 +        else if (name[tmp->symbol->ident->len] == '-' ||
      285 +                 name[tmp->symbol->ident->len] == '.')
      286 +                snprintf(buf, sizeof(buf), "%s%s", sm->name, name + tmp->symbol->ident->len);
      287 +        else if (strcmp(name, tmp->symbol_name->name) == 0)
      288 +                snprintf(buf, sizeof(buf), "%s", sm->name);
      289 +        else
      290 +                return NULL;
      291 +
 276  292          *new_sym = sm->sym;
 277  293          return alloc_string(buf);
 278  294  }
 279  295  
 280  296  char *get_other_name_sym_helper(const char *name, struct symbol *sym, struct symbol **new_sym, bool use_stack)
 281  297  {
 282  298          char buf[256];
 283  299          char *ret;
 284  300          int len;
 285  301  
↓ open down ↓ 793 lines elided ↑ open up ↑
1079 1095  
1080 1096          if (!__in_fake_assign &&
1081 1097              !(right->type == EXPR_PREOP && right->op == '&') &&
1082 1098              right_name && right_sym &&
1083 1099              values_fit_type(left, strip_expr(right)) &&
1084 1100              !has_symbol(right, sym)) {
1085 1101                  set_equiv(left, right);
1086 1102                  goto free;
1087 1103          }
1088 1104  
1089      -        if (is_pointer(right) && get_address_rl(right, &rl)) {
1090      -                state = alloc_estate_rl(rl);
1091      -                goto done;
1092      -        }
1093      -
1094 1105          if (get_implied_value(right, &sval)) {
1095 1106                  state = alloc_estate_sval(sval_cast(left_type, sval));
1096 1107                  goto done;
1097 1108          }
1098 1109  
1099 1110          if (__in_fake_assign) {
1100 1111                  struct smatch_state *right_state;
1101 1112                  sval_t sval;
1102 1113  
1103 1114                  if (get_value(right, &sval)) {
↓ open down ↓ 1843 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX