Print this page
12166 resync smatch to 0.6.1-rc1-il-3

Split Close
Expand all
Collapse all
          --- old/usr/src/tools/smatch/src/smatch_type.c
          +++ new/usr/src/tools/smatch/src/smatch_type.c
↓ open down ↓ 69 lines elided ↑ open up ↑
  70   70          if (expr->op == SPECIAL_LEFTSHIFT ||
  71   71              expr->op == SPECIAL_RIGHTSHIFT) {
  72   72                  if (type_positive_bits(left) < 31)
  73   73                          return &int_ctype;
  74   74                  return left;
  75   75          }
  76   76          right = get_type(expr->right);
  77   77          if (!right)
  78   78                  return NULL;
  79   79  
       80 +        if (type_is_fp(left)) {
       81 +                if (type_is_fp(right)) {
       82 +                        if (type_bits(left) > type_bits(right))
       83 +                                return left;
       84 +                        return right;
       85 +                }
       86 +                return left;
       87 +        }
       88 +
       89 +        if (type_is_fp(right)) {
       90 +                if (type_is_fp(left)) {
       91 +                        if (type_bits(right) > type_bits(left))
       92 +                                return right;
       93 +                        return left;
       94 +                }
       95 +                return right;
       96 +        }
       97 +
  80   98          if (expr->op == '-' &&
  81   99              (is_ptr_type(left) && is_ptr_type(right)))
  82  100                  return ssize_t_ctype;
  83  101  
  84  102          if (left->type == SYM_PTR || left->type == SYM_ARRAY)
  85  103                  return left;
  86  104          if (right->type == SYM_PTR || right->type == SYM_ARRAY)
  87  105                  return right;
  88  106  
  89  107          if (type_positive_bits(left) < 31 && type_positive_bits(right) < 31)
↓ open down ↓ 46 lines elided ↑ open up ↑
 136  154                  return NULL;
 137  155          }
 138  156          if (sym->type == SYM_PTR)
 139  157                  sym = get_real_base_type(sym);
 140  158          sym = get_member_symbol(sym->symbol_list, member);
 141  159          if (!sym)
 142  160                  return NULL;
 143  161          return get_real_base_type(sym);
 144  162  }
 145  163  
      164 +static struct symbol *handle__builtin_choose_expr(struct expression *expr)
      165 +{
      166 +        struct expression *const_expr, *expr1, *expr2;
      167 +        sval_t sval;
      168 +
      169 +        const_expr = get_argument_from_call_expr(expr->args, 0);
      170 +        expr1 = get_argument_from_call_expr(expr->args, 1);
      171 +        expr2 = get_argument_from_call_expr(expr->args, 2);
      172 +
      173 +        if (!get_value(const_expr, &sval) || !expr1 || !expr2)
      174 +                return NULL;
      175 +        if (sval.value)
      176 +                return get_type(expr1);
      177 +        else
      178 +                return get_type(expr2);
      179 +}
      180 +
 146  181  static struct symbol *get_return_type(struct expression *expr)
 147  182  {
 148  183          struct symbol *tmp;
 149  184  
      185 +        if (sym_name_is("__builtin_choose_expr", expr->fn))
      186 +                return handle__builtin_choose_expr(expr);
      187 +
 150  188          tmp = get_type(expr->fn);
 151  189          if (!tmp)
 152  190                  return NULL;
 153  191          /* this is to handle __builtin_constant_p() */
 154  192          if (tmp->type != SYM_FN)
 155  193                  tmp = get_base_type(tmp);
 156  194          return get_real_base_type(tmp);
 157  195  }
 158  196  
 159  197  static struct symbol *get_expr_stmt_type(struct statement *stmt)
↓ open down ↓ 236 lines elided ↑ open up ↑
 396  434                  return 0;
 397  435          sym = get_base_type(sym);
 398  436          if (!sym || sym->type != SYM_FN)
 399  437                  return 0;
 400  438          sym = get_base_type(sym);
 401  439          if (sym && sym->type == SYM_PTR)
 402  440                  return 1;
 403  441          return 0;
 404  442  }
 405  443  
      444 +static sval_t fp_max(struct symbol *type)
      445 +{
      446 +        sval_t ret = { .type = type };
      447 +
      448 +        if (type == &float_ctype)
      449 +                ret.fvalue = FLT_MAX;
      450 +        else if (type == &double_ctype)
      451 +                ret.dvalue = DBL_MAX;
      452 +        else
      453 +                ret.ldvalue = LDBL_MAX;
      454 +
      455 +        return ret;
      456 +}
      457 +
 406  458  sval_t sval_type_max(struct symbol *base_type)
 407  459  {
 408  460          sval_t ret;
 409  461  
      462 +        if (type_is_fp(base_type))
      463 +                return fp_max(base_type);
      464 +
 410  465          if (!base_type || !type_bits(base_type))
 411  466                  base_type = &llong_ctype;
 412  467          ret.type = base_type;
 413  468  
 414  469          ret.value = (~0ULL) >> (64 - type_positive_bits(base_type));
 415  470          return ret;
 416  471  }
 417  472  
      473 +static sval_t fp_min(struct symbol *type)
      474 +{
      475 +        sval_t ret = { .type = type };
      476 +
      477 +        if (type == &float_ctype)
      478 +                ret.fvalue = -FLT_MAX;
      479 +        else if (type == &double_ctype)
      480 +                ret.dvalue = -DBL_MAX;
      481 +        else
      482 +                ret.ldvalue = -LDBL_MAX;
      483 +
      484 +        return ret;
      485 +}
      486 +
 418  487  sval_t sval_type_min(struct symbol *base_type)
 419  488  {
 420  489          sval_t ret;
 421  490  
      491 +        if (type_is_fp(base_type))
      492 +                return fp_min(base_type);
      493 +
 422  494          if (!base_type || !type_bits(base_type))
 423  495                  base_type = &llong_ctype;
 424  496          ret.type = base_type;
 425  497  
 426  498          if (type_unsigned(base_type) || is_ptr_type(base_type)) {
 427  499                  ret.value = 0;
 428  500                  return ret;
 429  501          }
 430  502  
 431  503          ret.value = (~0ULL) << type_positive_bits(base_type);
↓ open down ↓ 360 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX