Print this page
11506 smatch resync

Split Close
Expand all
Collapse all
          --- old/usr/src/tools/smatch/src/smatch_estate.c
          +++ new/usr/src/tools/smatch/src/smatch_estate.c
↓ open down ↓ 35 lines elided ↑ open up ↑
  36   36          struct range_list *value_ranges;
  37   37          struct related_list *rlist;
  38   38  
  39   39          if (estates_equiv(s1, s2))
  40   40                  return s1;
  41   41  
  42   42          value_ranges = rl_union(estate_rl(s1), estate_rl(s2));
  43   43          tmp = alloc_estate_rl(value_ranges);
  44   44          rlist = get_shared_relations(estate_related(s1), estate_related(s2));
  45   45          set_related(tmp, rlist);
  46      -        if (estate_has_hard_max(s1) && estate_has_hard_max(s2))
       46 +
       47 +        if ((estate_has_hard_max(s1) && (!estate_rl(s2) || estate_has_hard_max(s2))) ||
       48 +            (estate_has_hard_max(s2) && (!estate_rl(s1) || estate_has_hard_max(s1))))
  47   49                  estate_set_hard_max(tmp);
  48   50  
  49   51          estate_set_fuzzy_max(tmp, sval_max(estate_get_fuzzy_max(s1), estate_get_fuzzy_max(s2)));
  50   52  
       53 +        if (estate_capped(s1) && estate_capped(s2))
       54 +                estate_set_capped(tmp);
       55 +
  51   56          return tmp;
  52   57  }
  53   58  
  54   59  struct data_info *get_dinfo(struct smatch_state *state)
  55   60  {
  56   61          if (!state)
  57   62                  return NULL;
  58   63          return (struct data_info *)state->data;
  59   64  }
  60   65  
↓ open down ↓ 66 lines elided ↑ open up ↑
 127  132  }
 128  133  
 129  134  int estate_get_hard_max(struct smatch_state *state, sval_t *sval)
 130  135  {
 131  136          if (!state || !get_dinfo(state)->hard_max || !estate_rl(state))
 132  137                  return 0;
 133  138          *sval = rl_max(estate_rl(state));
 134  139          return 1;
 135  140  }
 136  141  
      142 +bool estate_capped(struct smatch_state *state)
      143 +{
      144 +        if (!state)
      145 +                return false;
      146 +        /* impossible states are capped */
      147 +        if (!estate_rl(state))
      148 +                return true;
      149 +        return get_dinfo(state)->capped;
      150 +}
      151 +
      152 +void estate_set_capped(struct smatch_state *state)
      153 +{
      154 +        get_dinfo(state)->capped = true;
      155 +}
      156 +
 137  157  sval_t estate_min(struct smatch_state *state)
 138  158  {
 139  159          return rl_min(estate_rl(state));
 140  160  }
 141  161  
 142  162  sval_t estate_max(struct smatch_state *state)
 143  163  {
 144  164          return rl_max(estate_rl(state));
 145  165  }
 146  166  
↓ open down ↓ 28 lines elided ↑ open up ↑
 175  195  }
 176  196  
 177  197  int estates_equiv(struct smatch_state *one, struct smatch_state *two)
 178  198  {
 179  199          if (!one || !two)
 180  200                  return 0;
 181  201          if (one == two)
 182  202                  return 1;
 183  203          if (!rlists_equiv(estate_related(one), estate_related(two)))
 184  204                  return 0;
      205 +        if (estate_capped(one) != estate_capped(two))
      206 +                return 0;
 185  207          if (strcmp(one->name, two->name) == 0)
 186  208                  return 1;
 187  209          return 0;
 188  210  }
 189  211  
 190  212  int estate_is_whole(struct smatch_state *state)
 191  213  {
 192  214          return is_whole_rl(estate_rl(state));
 193  215  }
 194  216  
↓ open down ↓ 70 lines elided ↑ open up ↑
 265  287  
 266  288          if (!state)
 267  289                  return NULL;
 268  290  
 269  291          ret = __alloc_smatch_state(0);
 270  292          ret->name = state->name;
 271  293          ret->data = clone_dinfo(get_dinfo(state));
 272  294          return ret;
 273  295  }
 274  296  
      297 +struct smatch_state *clone_partial_estate(struct smatch_state *state, struct range_list *rl)
      298 +{
      299 +        struct smatch_state *ret;
      300 +
      301 +        if (!state)
      302 +                return NULL;
      303 +
      304 +        rl = cast_rl(estate_type(state), rl);
      305 +
      306 +        ret = alloc_estate_rl(rl);
      307 +        set_related(ret, clone_related_list(estate_related(state)));
      308 +        if (estate_has_hard_max(state))
      309 +                estate_set_hard_max(ret);
      310 +        if (estate_has_fuzzy_max(state))
      311 +                estate_set_fuzzy_max(ret, estate_get_fuzzy_max(state));
      312 +
      313 +        return ret;
      314 +}
      315 +
 275  316  struct smatch_state *alloc_estate_empty(void)
 276  317  {
 277  318          struct smatch_state *state;
 278  319          struct data_info *dinfo;
 279  320  
 280  321          dinfo = alloc_dinfo();
 281  322          state = __alloc_smatch_state(0);
 282  323          state->data = dinfo;
 283  324          state->name = "";
 284  325          return state;
↓ open down ↓ 73 lines elided ↑ open up ↑
 358  399          struct range_list *rl;
 359  400  
 360  401          state = get_state_expr(SMATCH_EXTRA, expr);
 361  402          if (state)
 362  403                  return state;
 363  404          if (!get_implied_rl(expr, &rl))
 364  405                  rl = alloc_whole_rl(get_type(expr));
 365  406          return alloc_estate_rl(rl);
 366  407  }
 367  408  
 368      -struct smatch_state *estate_filter_range(struct smatch_state *orig,
 369      -                                 sval_t filter_min, sval_t filter_max)
 370      -{
 371      -        struct range_list *rl;
 372      -        struct smatch_state *state;
 373      -
 374      -        if (!orig)
 375      -                orig = alloc_estate_whole(filter_min.type);
 376      -
 377      -        rl = remove_range(estate_rl(orig), filter_min, filter_max);
 378      -        state = alloc_estate_rl(rl);
 379      -        if (estate_has_hard_max(orig))
 380      -                estate_set_hard_max(state);
 381      -        if (estate_has_fuzzy_max(orig))
 382      -                estate_set_fuzzy_max(state, estate_get_fuzzy_max(orig));
 383      -        return state;
 384      -}
 385      -
 386      -struct smatch_state *estate_filter_sval(struct smatch_state *orig, sval_t sval)
 387      -{
 388      -        return estate_filter_range(orig, sval, sval);
 389      -}
 390      -
 391  409  /*
 392  410   * One of the complications is that smatch tries to free a bunch of data at the
 393  411   * end of every function.
 394  412   */
 395  413  struct data_info *clone_dinfo_perm(struct data_info *dinfo)
 396  414  {
 397  415          struct data_info *ret;
 398  416  
 399  417          ret = malloc(sizeof(*ret));
 400  418          memset(ret, 0, sizeof(*ret));
↓ open down ↓ 18 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX