Print this page
new smatch

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 ↓ 23 lines elided ↑ open up ↑
  24   24  static bool get_rl_internal(struct expression *expr, int implied, int *recurse_cnt, struct range_list **res);
  25   25  static bool handle_variable(struct expression *expr, int implied, int *recurse_cnt, struct range_list **res, sval_t *res_sval);
  26   26  static struct range_list *(*custom_handle_variable)(struct expression *expr);
  27   27  
  28   28  static bool get_implied_value_internal(struct expression *expr, int *recurse_cnt, sval_t *res_sval);
  29   29  static int get_absolute_rl_internal(struct expression *expr, struct range_list **rl, int *recurse_cnt);
  30   30  
  31   31  static sval_t zero  = {.type = &int_ctype, {.value = 0} };
  32   32  static sval_t one   = {.type = &int_ctype, {.value = 1} };
  33   33  
       34 +static int fast_math_only;
       35 +
  34   36  struct range_list *rl_zero(void)
  35   37  {
  36   38          static struct range_list *zero_perm;
  37   39  
  38   40          if (!zero_perm)
  39   41                  zero_perm = clone_rl_permanent(alloc_rl(zero, zero));
  40   42          return zero_perm;
  41   43  }
  42   44  
  43   45  struct range_list *rl_one(void)
↓ open down ↓ 805 lines elided ↑ open up ↑
 849  851  
 850  852          if (implied == RL_EXACT)
 851  853                  return false;
 852  854  
 853  855          if (implied_condition_true(expr->conditional))
 854  856                  return get_rl_sval(cond_true, implied, recurse_cnt, res, res_sval);
 855  857          if (implied_condition_false(expr->conditional))
 856  858                  return get_rl_sval(expr->cond_false, implied, recurse_cnt, res, res_sval);
 857  859  
 858  860          /* this becomes a problem with deeply nested conditional statements */
 859      -        if (low_on_memory())
      861 +        if (fast_math_only || low_on_memory())
 860  862                  return false;
 861  863  
 862  864          type = get_type(expr);
 863  865  
 864  866          __push_fake_cur_stree();
 865  867          final_pass = 0;
 866  868          __split_whole_condition(expr->conditional);
 867  869          true_rl = NULL;
 868  870          get_rl_internal(cond_true, implied, recurse_cnt, &true_rl);
 869  871          __push_true_states();
↓ open down ↓ 70 lines elided ↑ open up ↑
 940  942  struct range_list *var_to_absolute_rl(struct expression *expr)
 941  943  {
 942  944          struct smatch_state *state;
 943  945          struct range_list *rl;
 944  946  
 945  947          state = get_extra_state(expr);
 946  948          if (!state || is_whole_rl(estate_rl(state))) {
 947  949                  state = get_real_absolute_state(expr);
 948  950                  if (state && state->data && !estate_is_whole(state))
 949  951                          return clone_rl(estate_rl(state));
 950      -                if (get_local_rl(expr, &rl) && !is_whole_rl(rl))
 951      -                        return rl;
 952  952                  if (get_mtag_rl(expr, &rl))
 953  953                          return rl;
 954  954                  if (get_db_type_rl(expr, &rl) && !is_whole_rl(rl))
 955  955                          return rl;
 956  956                  return alloc_whole_rl(get_type(expr));
 957  957          }
 958  958          /* err on the side of saying things are possible */
 959  959          if (!estate_rl(state))
 960  960                  return alloc_whole_rl(get_type(expr));
 961  961          return clone_rl(estate_rl(state));
↓ open down ↓ 39 lines elided ↑ open up ↑
1001 1001          /* FIXME: call rl_to_sval() on the results */
1002 1002  
1003 1003          switch (implied) {
1004 1004          case RL_HARD:
1005 1005          case RL_IMPLIED:
1006 1006          case RL_ABSOLUTE:
1007 1007                  state = get_extra_state(expr);
1008 1008                  if (!state) {
1009 1009                          if (implied == RL_HARD)
1010 1010                                  return false;
1011      -                        if (get_local_rl(expr, res))
1012      -                                return true;
1013 1011                          if (get_mtag_rl(expr, res))
1014 1012                                  return true;
1015 1013                          if (get_db_type_rl(expr, res))
1016 1014                                  return true;
1017 1015                          if (is_array(expr) && get_array_rl(expr, res))
1018 1016                                  return true;
1019 1017                          return false;
1020 1018                  }
1021 1019                  if (implied == RL_HARD && !estate_has_hard_max(state))
1022 1020                          return false;
↓ open down ↓ 30 lines elided ↑ open up ↑
1053 1051                           * that gets translated into the whole range in
1054 1052                           * get_real_absolute_rl().
1055 1053                           *
1056 1054                           */
1057 1055                          return false;
1058 1056                  } else if (estate_rl(abs_state)) {
1059 1057                          *res = clone_rl(estate_rl(abs_state));
1060 1058                          return true;
1061 1059                  }
1062 1060  
1063      -                if (get_local_rl(expr, res))
1064      -                        return true;
1065 1061                  if (get_mtag_rl(expr, res))
1066 1062                          return true;
1067 1063                  if (get_db_type_rl(expr, res))
1068 1064                          return true;
1069 1065                  if (is_array(expr) && get_array_rl(expr, res))
1070 1066                          return true;
1071 1067                  return false;
1072 1068          }
1073 1069          case RL_FUZZY:
1074 1070                  if (!get_fuzzy_min_helper(expr, &min))
↓ open down ↓ 434 lines elided ↑ open up ↑
1509 1505          struct expression *expr;
1510 1506          sval_t sval;
1511 1507  } cached_results[24];
1512 1508  static int cache_idx;
1513 1509  
1514 1510  void clear_math_cache(void)
1515 1511  {
1516 1512          memset(cached_results, 0, sizeof(cached_results));
1517 1513  }
1518 1514  
     1515 +void set_fast_math_only(void)
     1516 +{
     1517 +        fast_math_only++;
     1518 +}
     1519 +
     1520 +void clear_fast_math_only(void)
     1521 +{
     1522 +        fast_math_only--;
     1523 +}
     1524 +
1519 1525  /*
1520 1526   * Don't cache EXPR_VALUE because values are fast already.
1521 1527   *
1522 1528   */
1523 1529  static bool get_value_literal(struct expression *expr, sval_t *res_sval)
1524 1530  {
1525 1531          struct expression *tmp;
1526 1532          int recurse_cnt = 0;
1527 1533  
1528 1534          tmp = strip_expr(expr);
↓ open down ↓ 224 lines elided ↑ open up ↑
1753 1759          return 1;
1754 1760  }
1755 1761  
1756 1762  int known_condition_true(struct expression *expr)
1757 1763  {
1758 1764          sval_t tmp;
1759 1765  
1760 1766          if (!expr)
1761 1767                  return 0;
1762 1768  
     1769 +        if (__inline_fn && get_param_num(expr) >= 0) {
     1770 +                if (get_implied_value(expr, &tmp) && tmp.value)
     1771 +                        return 1;
     1772 +                return 0;
     1773 +        }
     1774 +
1763 1775          if (get_value(expr, &tmp) && tmp.value)
1764 1776                  return 1;
1765 1777  
1766 1778          return 0;
1767 1779  }
1768 1780  
1769 1781  int known_condition_false(struct expression *expr)
1770 1782  {
     1783 +        sval_t tmp;
     1784 +
1771 1785          if (!expr)
1772 1786                  return 0;
1773 1787  
1774      -        if (is_zero(expr))
     1788 +        if (__inline_fn && get_param_num(expr) >= 0) {
     1789 +                if (get_implied_value(expr, &tmp) && tmp.value == 0)
     1790 +                        return 1;
     1791 +                return 0;
     1792 +        }
     1793 +
     1794 +        if (expr_is_zero(expr))
1775 1795                  return 1;
1776 1796  
1777 1797          return 0;
1778 1798  }
1779 1799  
1780 1800  int implied_condition_true(struct expression *expr)
1781 1801  {
1782 1802          sval_t tmp;
1783 1803  
1784 1804          if (!expr)
↓ open down ↓ 70 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX