locking: make spinlock_irqsave() work for my config
[smatch.git] / check_deref_check.c
blob3c5c8859fb018ad0d72078f994c485ac51b94ef1
1 /*
2 * sparse/check_deref_check.c
4 * Copyright (C) 2009 Dan Carpenter.
6 * Licensed under the Open Software License version 1.1
8 */
10 #include "smatch.h"
11 #include "smatch_extra.h"
13 static int my_id;
15 STATE(derefed);
16 STATE(oktocheck);
18 static void underef(const char *name, struct symbol *sym, struct expression *expr, void *unused)
20 set_state(my_id, name, sym, &oktocheck);
23 static void match_dereference(struct expression *expr)
25 char *name;
27 if (expr->type != EXPR_PREOP)
28 return;
29 if (getting_address())
30 return;
32 expr = strip_expr(expr->unop);
33 if (implied_not_equal(expr, 0))
34 return;
35 set_state_expr(my_id, expr, &derefed);
36 name = get_variable_from_expr(expr, NULL);
37 if (!name)
38 return;
39 add_modification_hook(my_id, name, &underef, NULL);
40 free_string(name);
43 static void match_condition(struct expression *expr)
45 if (__in_pre_condition)
46 return;
48 if (get_state_expr(my_id, expr) == &derefed) {
49 char *name;
51 name = get_variable_from_expr(expr, NULL);
52 if (!implied_not_equal(expr, 0))
53 sm_msg("warn: variable dereferenced before check '%s'", name);
54 set_state_expr(my_id, expr, &oktocheck);
55 free_string(name);
59 void check_deref_check(int id)
61 my_id = id;
62 add_hook(&match_dereference, DEREF_HOOK);
63 add_hook(&match_condition, CONDITION_HOOK);