type_max(): handle unsigned long long. (sort of)
[smatch.git] / check_precedence.c
blobebb8b8f5f9a1bd63559a02b44a972f2c5d8a3bfe
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 if (is_bool(expr->left->unop))
41 return;
42 print = 1;
46 if (expr->type == EXPR_BINOP) {
47 if (expr->left->type == EXPR_COMPARE || expr->right->type == EXPR_COMPARE)
48 print = 1;
51 if (print)
52 sm_msg("warn: add some parenthesis here?");
55 static void match_binop(struct expression *expr)
57 if (expr->op != '&')
58 return;
59 if (expr->left->op == '!')
60 sm_msg("warn: add some parenthesis here?");
63 void check_precedence(int id)
65 my_id = id;
67 add_hook(&match_condition, CONDITION_HOOK);
68 add_hook(&match_binop, BINOP_HOOK);