Print this page
11972 resync smatch

Split Close
Expand all
Collapse all
          --- old/usr/src/tools/smatch/src/smatch_implied.c
          +++ new/usr/src/tools/smatch/src/smatch_implied.c
↓ open down ↓ 50 lines elided ↑ open up ↑
  51   51   *
  52   52   * merge_slist() sets up ->pool.  An sm_state only has one ->pool and
  53   53   *    that is the pool where it was first set.  The my pool gets set when
  54   54   *    code paths merge.  States that have been set since the last merge do
  55   55   *    not have a ->pool.
  56   56   * merge_sm_state() sets ->left and ->right.  (These are the states which were
  57   57   *    merged to form the current state.)
  58   58   * a pool:  a pool is an slist that has been merged with another slist.
  59   59   */
  60   60  
  61      -#include <sys/time.h>
  62   61  #include <time.h>
  63   62  #include "smatch.h"
  64   63  #include "smatch_slist.h"
  65   64  #include "smatch_extra.h"
  66   65  
  67   66  char *implied_debug_msg;
  68   67  
  69   68  bool implications_off;
  70   69  
  71   70  #define implied_debug 0
  72   71  #define DIMPLIED(msg...) do { if (implied_debug) printf(msg); } while (0)
  73   72  
       73 +bool debug_implied(void)
       74 +{
       75 +        return implied_debug;
       76 +}
       77 +
  74   78  /*
  75   79   * tmp_range_list():
  76   80   * It messes things up to free range list allocations.  This helper fuction
  77   81   * lets us reuse memory instead of doing new allocations.
  78   82   */
  79   83  static struct range_list *tmp_range_list(struct symbol *type, long long num)
  80   84  {
  81   85          static struct range_list *my_list = NULL;
  82   86          static struct data_range *my_range;
  83   87  
↓ open down ↓ 207 lines elided ↑ open up ↑
 291  295   */
 292  296  static void __separate_pools(struct sm_state *sm, int comparison, struct range_list *rl,
 293  297                          struct state_list **true_stack,
 294  298                          struct state_list **maybe_stack,
 295  299                          struct state_list **false_stack,
 296  300                          struct state_list **checked, int *mixed, struct sm_state *gate_sm,
 297  301                          struct timeval *start_time)
 298  302  {
 299  303          int free_checked = 0;
 300  304          struct state_list *checked_states = NULL;
 301      -        struct timeval now;
      305 +        struct timeval now, diff;
 302  306  
 303  307          if (!sm)
 304  308                  return;
 305  309  
 306  310          gettimeofday(&now, NULL);
 307      -        if (now.tv_usec - start_time->tv_usec > 1000000) {
      311 +        timersub(&now, start_time, &diff);
      312 +        if (diff.tv_sec >= 1) {
 308  313                  if (implied_debug) {
 309  314                          sm_msg("debug: %s: implications taking too long.  (%s %s %s)",
 310  315                                 __func__, sm->state->name, show_special(comparison), show_rl(rl));
 311  316                  }
 312  317                  if (mixed)
 313  318                          *mixed = 1;
 314  319          }
 315  320  
 316  321          if (checked == NULL) {
 317  322                  checked = &checked_states;
↓ open down ↓ 126 lines elided ↑ open up ↑
 444  449  struct sm_state *filter_pools(struct sm_state *sm,
 445  450                                const struct state_list *remove_stack,
 446  451                                const struct state_list *keep_stack,
 447  452                                int *modified, int *recurse_cnt,
 448  453                                struct timeval *start, int *skip, int *bail)
 449  454  {
 450  455          struct sm_state *ret = NULL;
 451  456          struct sm_state *left;
 452  457          struct sm_state *right;
 453  458          int removed = 0;
 454      -        struct timeval now;
      459 +        struct timeval now, diff;
 455  460  
 456  461          if (!sm)
 457  462                  return NULL;
 458  463          if (*bail)
 459  464                  return NULL;
 460  465          gettimeofday(&now, NULL);
 461      -        if (now.tv_usec - start->tv_usec > 3000000) {
      466 +        timersub(&now, start, &diff);
      467 +        if (diff.tv_sec >= 3) {
 462  468                  DIMPLIED("%s: implications taking too long: %s\n", __func__, sm_state_info(sm));
 463  469                  *bail = 1;
 464  470                  return NULL;
 465  471          }
 466  472          if ((*recurse_cnt)++ > RECURSE_LIMIT) {
 467  473                  DIMPLIED("%s: recursed too far:  %s\n", __func__, sm_state_info(sm));
 468  474                  *skip = 1;
 469  475                  return NULL;
 470  476          }
 471  477  
↓ open down ↓ 120 lines elided ↑ open up ↑
 592  598          }
 593  599  
 594  600          separate_pools(sm, comparison, rl, &true_stack, &false_stack, NULL, mixed);
 595  601  
 596  602          DIMPLIED("filtering true stack.\n");
 597  603          *true_states = filter_stack(sm, pre_stree, false_stack, true_stack);
 598  604          DIMPLIED("filtering false stack.\n");
 599  605          *false_states = filter_stack(sm, pre_stree, true_stack, false_stack);
 600  606          free_slist(&true_stack);
 601  607          free_slist(&false_stack);
 602      -        if (implied_debug) {
 603      -                printf("These are the implied states for the true path: (%s (%s) %s %s)\n",
 604      -                       sm->name, sm->state->name, show_special(comparison), show_rl(rl));
 605      -                __print_stree(*true_states);
 606      -                printf("These are the implied states for the false path: (%s (%s) %s %s)\n",
 607      -                       sm->name, sm->state->name, show_special(comparison), show_rl(rl));
 608      -                __print_stree(*false_states);
 609      -        }
 610  608  
 611  609          gettimeofday(&time_after, NULL);
 612  610          sec = time_after.tv_sec - time_before.tv_sec;
 613  611          if (option_timeout && sec > option_timeout) {
 614  612                  sm_perror("Function too hairy.  Ignoring implications after %d seconds.", sec);
 615  613          }
 616  614  }
 617  615  
 618  616  static struct expression *get_last_expr(struct statement *stmt)
 619  617  {
↓ open down ↓ 170 lines elided ↑ open up ↑
 790  788          free_slist(&true_stack);
 791  789          free_slist(&false_stack);
 792  790  
 793  791          return 1;
 794  792  }
 795  793  
 796  794  static int handled_by_extra_states(struct expression *expr,
 797  795                                     struct stree **implied_true,
 798  796                                     struct stree **implied_false)
 799  797  {
      798 +        sval_t sval;
      799 +
      800 +        /* If the expression is known then it has no implications.  */
      801 +        if (get_implied_value(expr, &sval))
      802 +                return true;
      803 +
 800  804          if (expr->type == EXPR_COMPARE)
 801  805                  return handle_comparison(expr, implied_true, implied_false);
 802  806          else
 803  807                  return handle_zero_comparison(expr, implied_true, implied_false);
 804  808  }
 805  809  
 806  810  static int handled_by_stored_conditions(struct expression *expr,
 807  811                                          struct stree **implied_true,
 808  812                                          struct stree **implied_false)
 809  813  {
↓ open down ↓ 66 lines elided ↑ open up ↑
 876  880  {
 877  881          if (going_too_slow())
 878  882                  return;
 879  883          get_tf_states(expr, &saved_implied_true, &saved_implied_false);
 880  884  }
 881  885  
 882  886  static void set_implied_states(struct expression *expr)
 883  887  {
 884  888          struct sm_state *sm;
 885  889  
      890 +        if (implied_debug &&
      891 +            (expr || saved_implied_true || saved_implied_false)) {
      892 +                char *name;
      893 +
      894 +                name = expr_to_str(expr);
      895 +                printf("These are the implied states for the true path: (%s)\n", name);
      896 +                __print_stree(saved_implied_true);
      897 +                printf("These are the implied states for the false path: (%s)\n", name);
      898 +                __print_stree(saved_implied_false);
      899 +                free_string(name);
      900 +        }
      901 +
 886  902          FOR_EACH_SM(saved_implied_true, sm) {
 887  903                  __set_true_false_sm(sm, NULL);
 888  904          } END_FOR_EACH_SM(sm);
 889  905          free_stree(&saved_implied_true);
 890  906  
 891  907          FOR_EACH_SM(saved_implied_false, sm) {
 892  908                  __set_true_false_sm(NULL, sm);
 893  909          } END_FOR_EACH_SM(sm);
 894  910          free_stree(&saved_implied_false);
 895  911  }
↓ open down ↓ 234 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX