Print this page
12257 resync smatch to 0.6.1-rc1-il-4

Split Close
Expand all
Collapse all
          --- old/usr/src/tools/smatch/src/smatch_container_of.c
          +++ new/usr/src/tools/smatch/src/smatch_container_of.c
↓ open down ↓ 207 lines elided ↑ open up ↑
 208  208          p = strchr(buf, '|');
 209  209          if (!p)
 210  210                  return NULL;
 211  211          *p = '\0';
 212  212          param = atoi(p + 2);
 213  213          if (get_param_sym_from_num(param) == container->symbol)
 214  214                  return buf;
 215  215          return NULL;
 216  216  }
 217  217  
 218      -char *get_container_name(struct expression *container, struct expression *expr)
      218 +static char *get_container_name_helper(struct expression *container, struct expression *expr)
 219  219  {
 220  220          struct symbol *container_sym, *sym;
 221      -        struct expression *tmp;
 222  221          static char buf[64];
 223  222          char *ret, *shared;
 224  223          bool star;
 225      -        int cnt;
 226  224  
 227  225          expr = strip_expr(expr);
 228  226          container = strip_expr(container);
      227 +        if (!expr || !container)
      228 +                return NULL;
 229  229  
 230  230          ret = get_stored_container_name(container, expr);
 231  231          if (ret)
 232  232                  return ret;
 233  233  
 234  234          sym = expr_to_sym(expr);
 235  235          container_sym = expr_to_sym(container);
 236      -        if (sym && sym == container_sym)
 237      -                goto found;
      236 +        if (!sym || !container_sym)
      237 +                return NULL;
      238 +        if (sym != container_sym)
      239 +                return NULL;
 238  240  
 239      -        cnt = 0;
 240      -        while ((tmp = get_assigned_expr(container))) {
 241      -                container = strip_expr(tmp);
 242      -                if (cnt++ > 3)
 243      -                        break;
 244      -        }
 245      -
 246      -        cnt = 0;
 247      -        while ((tmp = get_assigned_expr(expr))) {
 248      -                expr = strip_expr(tmp);
 249      -                if (cnt++ > 3)
 250      -                        break;
 251      -        }
 252      -
 253      -found:
 254      -
 255  241          if (container->type == EXPR_DEREF)
 256  242                  star = true;
 257  243          else
 258  244                  star = false;
 259  245  
 260  246          if (container->type == EXPR_PREOP && container->op == '&')
 261  247                  container = strip_expr(container->unop);
 262  248          if (expr->type == EXPR_PREOP && expr->op == '&')
 263  249                  expr = strip_expr(expr->unop);
 264  250  
 265      -        sym = expr_to_sym(expr);
 266      -        if (!sym)
 267      -                return NULL;
 268      -        container_sym = expr_to_sym(container);
 269      -        if (!container_sym || sym != container_sym)
 270      -                return NULL;
 271      -
 272  251          shared = get_shared_str(expr, container);
 273  252          if (!shared)
 274  253                  return NULL;
 275  254          if (star)
 276  255                  snprintf(buf, sizeof(buf), "*(%s)", shared);
 277  256          else
 278  257                  snprintf(buf, sizeof(buf), "%s", shared);
 279  258  
 280  259          return buf;
 281  260  }
 282  261  
      262 +char *get_container_name(struct expression *container, struct expression *expr)
      263 +{
      264 +        char *ret;
      265 +
      266 +        ret = get_container_name_helper(container, expr);
      267 +        if (ret)
      268 +                return ret;
      269 +
      270 +        ret = get_container_name_helper(get_assigned_expr(container), expr);
      271 +        if (ret)
      272 +                return ret;
      273 +
      274 +        ret = get_container_name_helper(container, get_assigned_expr(expr));
      275 +        if (ret)
      276 +                return ret;
      277 +
      278 +        ret = get_container_name_helper(get_assigned_expr(container),
      279 +                                        get_assigned_expr(expr));
      280 +        if (ret)
      281 +                return ret;
      282 +
      283 +        return NULL;
      284 +}
      285 +
 283  286  static bool is_fn_ptr(struct expression *expr)
 284  287  {
 285  288          struct symbol *type;
 286  289  
 287  290          if (!expr)
 288  291                  return false;
 289  292          if (expr->type != EXPR_SYMBOL && expr->type != EXPR_DEREF)
 290  293                  return false;
 291  294  
 292  295          type = get_type(expr);
↓ open down ↓ 352 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX