check_overflow: store the size in bytes instead of bits.
[smatch.git] / check_precedence.c
blob70fb69b0ba642fa9507ee86b5110217aac103f97
1 /*
2 * sparse/check_precedence.c
4 * Copyright (C) 2010 Dan Carpenter.
6 * Licensed under the Open Software License version 1.1
8 */
10 #include "smatch.h"
12 static int my_id;
14 static int is_bool(struct expression *expr)
16 struct symbol *type;
18 type = get_type(expr);
19 if (!type)
20 return 0;
21 if (type->bit_size == 1 && type->ctype.modifiers & MOD_UNSIGNED)
22 return 1;
23 return 0;
26 static void match_condition(struct expression *expr)
28 int print = 0;
30 if (expr->type == EXPR_COMPARE) {
31 if (expr->left->type == EXPR_COMPARE || expr->right->type == EXPR_COMPARE)
32 print = 1;
33 if (expr->left->op == '!') {
34 if (expr->left->type == EXPR_PREOP && expr->left->unop->op == '!')
35 return;
36 if (expr->right->op == '!')
37 return;
38 if (is_bool(expr->right))
39 return;
40 print = 1;
44 if (expr->type == EXPR_BINOP) {
45 if (expr->left->type == EXPR_COMPARE || expr->right->type == EXPR_COMPARE)
46 print = 1;
49 if (print)
50 sm_msg("warn: add some parenthesis here?");
53 static void match_binop(struct expression *expr)
55 if (expr->op != '&')
56 return;
57 if (expr->left->op == '!')
58 sm_msg("warn: add some parenthesis here?");
61 void check_precedence(int id)
63 my_id = id;
65 add_hook(&match_condition, CONDITION_HOOK);
66 add_hook(&match_binop, BINOP_HOOK);