Print this page
11506 smatch resync

Split Close
Expand all
Collapse all
          --- old/usr/src/tools/smatch/src/smatch_sval.c
          +++ new/usr/src/tools/smatch/src/smatch_sval.c
↓ open down ↓ 59 lines elided ↑ open up ↑
  60   60          ret.value = 123456789;
  61   61  
  62   62          return ret;
  63   63  }
  64   64  
  65   65  sval_t sval_type_val(struct symbol *type, long long val)
  66   66  {
  67   67          sval_t ret;
  68   68  
  69   69          if (!type)
  70      -                type = &int_ctype;
       70 +                type = &llong_ctype;
  71   71  
  72   72          ret.type = type;
  73   73          ret.value = val;
  74   74          return ret;
  75   75  }
  76   76  
  77   77  sval_t sval_from_val(struct expression *expr, long long val)
  78   78  {
  79   79          sval_t ret;
  80   80  
↓ open down ↓ 6 lines elided ↑ open up ↑
  87   87  
  88   88  int sval_is_ptr(sval_t sval)
  89   89  {
  90   90          if (!sval.type)
  91   91                  return 0;
  92   92          return (sval.type->type == SYM_PTR || sval.type->type == SYM_ARRAY);
  93   93  }
  94   94  
  95   95  int sval_unsigned(sval_t sval)
  96   96  {
       97 +        if (is_ptr_type(sval.type))
       98 +                return true;
  97   99          return type_unsigned(sval.type);
  98  100  }
  99  101  
 100  102  int sval_signed(sval_t sval)
 101  103  {
 102  104          return !type_unsigned(sval.type);
 103  105  }
 104  106  
 105  107  int sval_bits(sval_t sval)
 106  108  {
↓ open down ↓ 117 lines elided ↑ open up ↑
 224  226  {
 225  227          if (sval_cmp(one, two) < 0)
 226  228                  return two;
 227  229          return one;
 228  230  }
 229  231  
 230  232  int sval_too_low(struct symbol *type, sval_t sval)
 231  233  {
 232  234          if (sval_is_negative(sval) && type_unsigned(type))
 233  235                  return 1;
 234      -        if (type_signed(type) &&  sval_unsigned(sval))
      236 +        if (type_signed(type) && sval_unsigned(sval))
 235  237                  return 0;
 236  238          if (type_signed(sval.type) &&
 237  239              sval.value < sval_type_min(type).value)
 238  240                  return 1;
 239  241          if (sval_cmp(sval, sval_type_min(type)) < 0)
 240  242                  return 1;
 241  243          return 0;
 242  244  }
 243  245  
 244  246  int sval_too_high(struct symbol *type, sval_t sval)
↓ open down ↓ 206 lines elided ↑ open up ↑
 451  453                          left.value = -left.value;
 452  454                          ret = ptr_binop(type, left, '+', right);
 453  455                  } else if (!type_is_ptr(right.type)) {
 454  456                          right.value = -right.value;
 455  457                          ret = ptr_binop(type, left, '+', right);
 456  458                  } else {
 457  459                          ret.value = (left.value - right.value) / align;
 458  460                  }
 459  461          }
 460  462  
      463 +        if (op == '-')
      464 +                ret.type = ssize_t_ctype;
 461  465          return ret;
 462  466  }
 463  467  
 464  468  sval_t sval_binop(sval_t left, int op, sval_t right)
 465  469  {
 466  470          struct symbol *type;
 467  471          sval_t ret;
 468  472  
 469  473          type = get_promoted_type(left.type, right.type);
 470  474  
↓ open down ↓ 105 lines elided ↑ open up ↑
 576  580          if (type_positive_bits(type) <= 31)
 577  581                  type = &uint_ctype;
 578  582          else
 579  583                  type = &ullong_ctype;
 580  584  
 581  585          left = sval_cast(type, left);
 582  586          right = sval_cast(type, right);
 583  587          return sval_binop_overflows(left, op, right);
 584  588  }
 585  589  
 586      -unsigned long long fls_mask(unsigned long long uvalue)
      590 +int find_first_zero_bit(unsigned long long uvalue)
 587  591  {
 588      -        unsigned long long high_bit = 0;
      592 +        int i;
 589  593  
      594 +        for (i = 0; i < 64; i++) {
      595 +                if (!(uvalue & (1ULL << i)))
      596 +                        return i;
      597 +        }
      598 +        return i;
      599 +}
      600 +
      601 +int sm_fls64(unsigned long long uvalue)
      602 +{
      603 +        int high_bit = 0;
      604 +
 590  605          while (uvalue) {
 591  606                  uvalue >>= 1;
 592  607                  high_bit++;
 593  608          }
 594  609  
      610 +        return high_bit;
      611 +}
      612 +
      613 +unsigned long long fls_mask(unsigned long long uvalue)
      614 +{
      615 +        int high_bit = 0;
      616 +
      617 +        high_bit = sm_fls64(uvalue);
 595  618          if (high_bit == 0)
 596  619                  return 0;
 597  620  
 598  621          return ((unsigned long long)-1) >> (64 - high_bit);
 599  622  }
 600  623  
 601  624  unsigned long long sval_fls_mask(sval_t sval)
 602  625  {
 603  626          return fls_mask(sval.uvalue);
 604  627  }
 605  628  
 606  629  const char *sval_to_str(sval_t sval)
 607  630  {
 608  631          char buf[30];
 609  632  
      633 +        if (sval_is_ptr(sval) && sval.value == valid_ptr_max)
      634 +                return "ptr_max";
 610  635          if (sval_unsigned(sval) && sval.value == ULLONG_MAX)
 611  636                  return "u64max";
 612  637          if (sval_unsigned(sval) && sval.value == UINT_MAX)
 613  638                  return "u32max";
 614  639          if (sval.value == USHRT_MAX)
 615  640                  return "u16max";
 616  641  
 617  642          if (sval_signed(sval) && sval.value == LLONG_MAX)
 618  643                  return "s64max";
 619  644          if (sval.value == INT_MAX)
↓ open down ↓ 11 lines elided ↑ open up ↑
 631  656          if (sval_unsigned(sval))
 632  657                  snprintf(buf, sizeof(buf), "%llu", sval.value);
 633  658          else if (sval.value < 0)
 634  659                  snprintf(buf, sizeof(buf), "(%lld)", sval.value);
 635  660          else
 636  661                  snprintf(buf, sizeof(buf), "%lld", sval.value);
 637  662  
 638  663          return alloc_sname(buf);
 639  664  }
 640  665  
      666 +const char *sval_to_str_or_err_ptr(sval_t sval)
      667 +{
      668 +        char buf[12];
      669 +
      670 +        if (option_project != PROJ_KERNEL ||
      671 +            !is_ptr_type(sval.type))
      672 +                return sval_to_str(sval);
      673 +
      674 +        if (sval.uvalue >= -4905ULL) {
      675 +                snprintf(buf, sizeof(buf), "(%lld)", sval.value);
      676 +                return alloc_sname(buf);
      677 +        }
      678 +
      679 +        return sval_to_str(sval);
      680 +}
      681 +
 641  682  const char *sval_to_numstr(sval_t sval)
 642  683  {
 643  684          char buf[30];
 644  685  
 645  686          if (sval_unsigned(sval))
 646  687                  snprintf(buf, sizeof(buf), "%llu", sval.value);
 647  688          else if (sval.value < 0)
 648  689                  snprintf(buf, sizeof(buf), "(%lld)", sval.value);
 649  690          else
 650  691                  snprintf(buf, sizeof(buf), "%lld", sval.value);
↓ open down ↓ 24 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX