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_math.c
          +++ new/usr/src/tools/smatch/src/smatch_math.c
↓ open down ↓ 327 lines elided ↑ open up ↑
 328  328                          return -1;
 329  329                  right = strip_expr(right->unop);
 330  330                  right_offset = get_member_offset_from_deref(right);
 331  331          }
 332  332          if (left_offset < 0 || right_offset < 0)
 333  333                  return -1;
 334  334  
 335  335          return left_offset - right_offset;
 336  336  }
 337  337  
      338 +static bool max_is_unknown_max(struct range_list *rl)
      339 +{
      340 +        /*
      341 +         * The issue with this code is that we had:
      342 +         * if (foo > 1) return 1 - foo;
      343 +         * Ideally we would say that returns s32min-(-1) but what Smatch
      344 +         * was saying was that the lowest possible value was "1 - INT_MAX"
      345 +         *
      346 +         * My solution is to ignore max values for int or larger.  I keep
      347 +         * the max for shorts etc, because those might be worthwhile.
      348 +         *
      349 +         * The problem with just returning 1 - INT_MAX is that that is
      350 +         * treated as useful information but s32min is treated as basically
      351 +         * unknown.
      352 +         */
      353 +
      354 +        if (type_bits(rl_type(rl)) < 31)
      355 +                return false;
      356 +        return sval_is_max(rl_max(rl));
      357 +}
      358 +
 338  359  static bool handle_subtract_rl(struct expression *expr, int implied, int *recurse_cnt, struct range_list **res)
 339  360  {
 340  361          struct symbol *type;
 341  362          struct range_list *left_orig, *right_orig;
 342  363          struct range_list *left_rl, *right_rl;
 343  364          sval_t min, max, tmp;
 344  365          int comparison;
 345  366          int offset;
 346  367  
 347  368          type = get_type(expr);
↓ open down ↓ 54 lines elided ↑ open up ↑
 402  423          case SPECIAL_UNSIGNED_LTE:
 403  424                  max = sval_type_val(type, 0);
 404  425                  break;
 405  426          default:
 406  427                  if (!left_orig || !right_orig)
 407  428                          return false;
 408  429                  *res = rl_binop(left_rl, '-', right_rl);
 409  430                  return true;
 410  431          }
 411  432  
 412      -        if (!sval_binop_overflows(rl_min(left_rl), '-', rl_max(right_rl))) {
      433 +        if (!max_is_unknown_max(right_rl) &&
      434 +            !sval_binop_overflows(rl_min(left_rl), '-', rl_max(right_rl))) {
 413  435                  tmp = sval_binop(rl_min(left_rl), '-', rl_max(right_rl));
 414  436                  if (sval_cmp(tmp, min) > 0)
 415  437                          min = tmp;
 416  438          }
 417  439  
 418  440          if (!sval_is_max(rl_max(left_rl))) {
 419  441                  tmp = sval_binop(rl_max(left_rl), '-', rl_min(right_rl));
 420  442                  if (sval_cmp(tmp, max) < 0)
 421  443                          max = tmp;
 422  444          }
↓ open down ↓ 785 lines elided ↑ open up ↑
1208 1230              sym_name_is("__builtin_bswap64", expr->fn)) {
1209 1231                  struct expression *arg;
1210 1232  
1211 1233                  arg = get_argument_from_call_expr(expr->args, 0);
1212 1234                  return get_rl_sval(arg, implied, recurse_cnt, res, res_sval);
1213 1235          }
1214 1236  
1215 1237          if (sym_name_is("strlen", expr->fn))
1216 1238                  return handle_strlen(expr, implied, recurse_cnt, res, res_sval);
1217 1239  
1218      -        if (implied == RL_EXACT || implied == RL_HARD || implied == RL_FUZZY)
     1240 +        if (implied == RL_EXACT || implied == RL_HARD)
1219 1241                  return false;
1220 1242  
1221 1243          if (custom_handle_variable) {
1222 1244                  rl = custom_handle_variable(expr);
1223 1245                  if (rl) {
1224 1246                          *res = rl;
1225 1247                          return true;
1226 1248                  }
1227 1249          }
1228 1250  
↓ open down ↓ 669 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX