precedence: warn about: if (!a & b) {...
[smatch.git] / check_precedence.c
blobad4ada643ba78c038fce6ccdb1e0af8325c09803
1 /*
2 * sparse/check_precedence.c
4 * Copyright (C) 20XX Your Name.
6 * Licensed under the Open Software License version 1.1
8 */
10 #include "smatch.h"
12 static int my_id;
14 static void match_condition(struct expression *expr)
16 if (expr->type != EXPR_BINOP)
17 return;
18 if (expr->left->type == EXPR_COMPARE ||
19 expr->right->type == EXPR_COMPARE)
20 sm_msg("warning: do you want parens here?");
23 static void match_binop(struct expression *expr)
25 if (expr->op != '&')
26 return;
27 if (expr->left->op == '!')
28 sm_msg("warning: you probably want parens here.");
32 void check_precedence(int id)
34 my_id = id;
36 add_hook(&match_condition, CONDITION_HOOK);
37 add_hook(&match_binop, BINOP_HOOK);