Print this page
11506 smatch resync

Split Close
Expand all
Collapse all
          --- old/usr/src/tools/smatch/src/check_64bit_shift.c
          +++ new/usr/src/tools/smatch/src/check_64bit_shift.c
↓ open down ↓ 8 lines elided ↑ open up ↑
   9    9   * This program is distributed in the hope that it will be useful,
  10   10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11   11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12   12   * GNU General Public License for more details.
  13   13   *
  14   14   * You should have received a copy of the GNU General Public License
  15   15   * along with this program; if not, see http://www.gnu.org/copyleft/gpl.txt
  16   16   */
  17   17  
  18   18  #include "smatch.h"
       19 +#include "smatch_extra.h"
  19   20  
  20   21  static int my_id;
  21   22  
       23 +static void match_shift_mask(struct expression *expr)
       24 +{
       25 +        struct expression *right, *shifter;
       26 +        struct range_list *rl;
       27 +        char *str;
       28 +
       29 +        expr = strip_expr(expr);
       30 +        if (expr->type != EXPR_BINOP || expr->op != '&')
       31 +                return;
       32 +
       33 +        if (get_type(expr->left) != &ullong_ctype)
       34 +                return;
       35 +
       36 +        if (type_bits(get_type(expr->right)) == 64)
       37 +                return;
       38 +
       39 +        right = strip_expr(expr->right);
       40 +        if (right->type != EXPR_BINOP || right->op != SPECIAL_LEFTSHIFT)
       41 +                return;
       42 +
       43 +        shifter = strip_expr(right->right);
       44 +        get_real_absolute_rl(shifter, &rl);
       45 +        if (rl_max(rl).uvalue < 32)
       46 +                return;
       47 +
       48 +        str = expr_to_str(expr->right);
       49 +        sm_warning("should '%s' be a 64 bit type?", str);
       50 +        free_string(str);
       51 +}
       52 +
  22   53  static void match_shift_assignment(struct expression *expr)
  23   54  {
  24   55          struct symbol *left_type, *right_type;
  25   56          struct expression *right;
  26   57          sval_t sval;
  27   58          sval_t bits, shifter;
  28   59          char *name;
  29   60  
  30   61          right = strip_expr(expr->right);
  31   62          if (right->type != EXPR_BINOP || right->op != SPECIAL_LEFTSHIFT)
↓ open down ↓ 24 lines elided ↑ open up ↑
  56   87          name = expr_to_str_sym(right, NULL);
  57   88          sm_warning("should '%s' be a 64 bit type?", name);
  58   89          free_string(name);
  59   90  }
  60   91  
  61   92  void check_64bit_shift(int id)
  62   93  {
  63   94          my_id = id;
  64   95  
  65   96          add_hook(&match_shift_assignment, ASSIGNMENT_HOOK);
       97 +        add_hook(&match_shift_mask, BINOP_HOOK);
  66   98  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX