buf_size: handle dma_alloc_attrs()
[smatch.git] / check_db_info.c
blobb251c77fbf0921b8b18c5542f4e7360a37893d58
1 /*
2 * smatch/check_db_info.c
4 * Copyright (C) 2010 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 static struct range_list *return_ranges;
16 static struct ptr_list *backup;
18 static void add_return_range(struct range_list *rl)
20 rl = cast_rl(cur_func_return_type(), rl);
21 if (!return_ranges) {
22 return_ranges = rl;
23 return;
25 return_ranges = rl_union(return_ranges, rl);
28 static void match_return(struct expression *ret_value)
30 struct range_list *rl;
31 struct symbol *type = cur_func_return_type();
33 ret_value = strip_expr(ret_value);
34 if (!ret_value)
35 return;
37 if (get_implied_rl(ret_value, &rl))
38 add_return_range(rl);
39 else
40 add_return_range(alloc_whole_rl(type));
43 static void match_end_func(struct symbol *sym)
45 if (!return_ranges)
46 return;
47 sql_insert_return_values(show_rl(return_ranges));
48 return_ranges = NULL;
51 static void match_save_states(struct expression *expr)
53 __add_ptr_list(&backup, return_ranges, 0);
54 return_ranges = NULL;
57 static void match_restore_states(struct expression *expr)
59 return_ranges = last_ptr_list(backup);
60 delete_ptr_list_last(&backup);
63 void check_db_info(int id)
65 my_id = id;
66 add_hook(&match_return, RETURN_HOOK);
67 add_hook(&match_end_func, END_FUNC_HOOK);
68 add_hook(&match_save_states, INLINE_FN_START);
69 add_hook(&match_restore_states, INLINE_FN_END);