Print this page
12724 update smatch to 0.6.1-rc1-il-5

Split Close
Expand all
Collapse all
          --- old/usr/src/tools/smatch/src/smatch_bits.c
          +++ new/usr/src/tools/smatch/src/smatch_bits.c
↓ open down ↓ 103 lines elided ↑ open up ↑
 104  104                  return alloc_bstate(0, -1ULL);
 105  105  
 106  106          if (type_bits(type) == 64)
 107  107                  possible = -1ULL;
 108  108          else
 109  109                  possible = (1ULL << type_bits(type)) - 1;
 110  110  
 111  111          return alloc_bstate(0, possible);
 112  112  }
 113  113  
      114 +static bool is_loop_iterator(struct expression *expr)
      115 +{
      116 +        struct statement *pre_stmt, *loop_stmt;
      117 +
      118 +        pre_stmt = expr_get_parent_stmt(expr);
      119 +        if (!pre_stmt || pre_stmt->type != STMT_EXPRESSION)
      120 +                return false;
      121 +
      122 +        loop_stmt = stmt_get_parent_stmt(pre_stmt);
      123 +        if (!loop_stmt || loop_stmt->type != STMT_ITERATOR)
      124 +                return false;
      125 +        if (loop_stmt->iterator_pre_statement != pre_stmt)
      126 +                return false;
      127 +
      128 +        return true;
      129 +}
      130 +
      131 +static bool handled_by_assign_hook(struct expression *expr)
      132 +{
      133 +        if (!expr || expr->type != EXPR_ASSIGNMENT)
      134 +                return false;
      135 +        if (__in_fake_assign)
      136 +                return false;
      137 +        if (is_loop_iterator(expr))
      138 +                return false;
      139 +
      140 +        if (expr->op == '=' ||
      141 +            expr->op == SPECIAL_OR_ASSIGN ||
      142 +            expr->op == SPECIAL_AND_ASSIGN)
      143 +                return true;
      144 +
      145 +        return false;
      146 +}
      147 +
 114  148  static void match_modify(struct sm_state *sm, struct expression *mod_expr)
 115  149  {
 116  150          // FIXME: we really need to store the type
 117  151  
      152 +        if (handled_by_assign_hook(mod_expr))
      153 +                return;
 118  154          set_state(my_id, sm->name, sm->sym, alloc_bstate(0, -1ULL));
 119  155  }
 120  156  
 121  157  static int binfo_equiv(struct bit_info *one, struct bit_info *two)
 122  158  {
 123  159          if (one->set == two->set &&
 124  160              one->possible == two->possible)
 125  161                  return 1;
 126  162          return 0;
 127  163  }
↓ open down ↓ 148 lines elided ↑ open up ↑
 276  312                  return;
 277  313  
 278  314          if (!get_implied_value(expr->right, &val))
 279  315                  return;
 280  316  
 281  317          set_true_false_states_expr(my_id, expr->left,
 282  318                          (expr->op == SPECIAL_EQUAL) ? alloc_bstate(val.uvalue, val.uvalue) : NULL,
 283  319                          (expr->op == SPECIAL_EQUAL) ? NULL : alloc_bstate(val.uvalue, val.uvalue));
 284  320  }
 285  321  
 286      -static bool is_loop_iterator(struct expression *expr)
 287      -{
 288      -        struct statement *pre_stmt, *loop_stmt;
 289      -
 290      -        pre_stmt = expr_get_parent_stmt(expr);
 291      -        if (!pre_stmt || pre_stmt->type != STMT_EXPRESSION)
 292      -                return false;
 293      -
 294      -        loop_stmt = stmt_get_parent_stmt(pre_stmt);
 295      -        if (!loop_stmt || loop_stmt->type != STMT_ITERATOR)
 296      -                return false;
 297      -        if (loop_stmt->iterator_pre_statement != pre_stmt)
 298      -                return false;
 299      -
 300      -        return true;
 301      -}
 302      -
 303  322  static void match_assign(struct expression *expr)
 304  323  {
 305      -        struct bit_info *binfo;
      324 +        struct bit_info *start, *binfo;
      325 +        struct smatch_state *new;
 306  326  
 307      -        if (expr->op != '=')
      327 +        if (!handled_by_assign_hook(expr))
 308  328                  return;
 309      -        if (__in_fake_assign)
 310      -                return;
 311      -        if (is_loop_iterator(expr))
 312      -                return;
 313  329  
 314  330          binfo = get_bit_info(expr->right);
 315  331          if (!binfo)
 316  332                  return;
 317      -        if (is_unknown_binfo(get_type(expr->left), binfo))
 318      -                return;
 319      -        set_state_expr(my_id, expr->left, alloc_bstate(binfo->set, binfo->possible));
      333 +        if (expr->op == '=') {
      334 +                if (is_unknown_binfo(get_type(expr->left), binfo))
      335 +                        return;
      336 +
      337 +                set_state_expr(my_id, expr->left, alloc_bstate(binfo->set, binfo->possible));
      338 +        } else if (expr->op == SPECIAL_OR_ASSIGN) {
      339 +                start = get_bit_info(expr->left);
      340 +                new = alloc_bstate(start->set | binfo->set, start->possible | binfo->possible);
      341 +                set_state_expr(my_id, expr->left, new);
      342 +        } else if (expr->op == SPECIAL_AND_ASSIGN) {
      343 +                start = get_bit_info(expr->left);
      344 +                new = alloc_bstate(start->set & binfo->set, start->possible & binfo->possible);
      345 +                set_state_expr(my_id, expr->left, new);
      346 +        }
 320  347  }
 321  348  
 322  349  static void match_condition(struct expression *expr)
 323  350  {
 324  351          struct bit_info *orig;
 325  352          struct bit_info true_info;
 326  353          struct bit_info false_info;
 327  354          sval_t right;
 328  355  
 329  356          if (expr->type != EXPR_BINOP ||
↓ open down ↓ 121 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX