buf_size: using ->bit_size doesn't work for void pointers or arrays
[smatch.git] / check_logical_instead_of_bitwise.c
blobbc0f541c4a9b4021b1fae66686851ca7baf9b296
1 /*
2 * sparse/check_logical_instead_of_bitwise.c
4 * Copyright (C) 2012 Oracle.
6 * Licensed under the Open Software License version 1.1
8 */
10 #include "smatch.h"
12 static int my_id;
14 static void match_logic(struct expression *expr)
16 long long val;
18 if (expr->type != EXPR_LOGICAL)
19 return;
21 if (get_macro_name(expr->pos))
22 return;
24 if (!get_value(expr->right, &val)) {
25 if (!get_value(expr->left, &val))
26 return;
29 if (val == 0 || val == 1)
30 return;
32 sm_msg("warn: should this be a bitwise op?");
35 void check_logical_instead_of_bitwise(int id)
37 my_id = id;
39 add_hook(&match_logic, LOGIC_HOOK);