2 * smatch/check_db_info.c
4 * Copyright (C) 2010 Dan Carpenter.
6 * Licensed under the Open Software License version 1.1
11 #include "smatch_extra.h"
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
);
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
);
37 if (get_implied_rl(ret_value
, &rl
))
40 add_return_range(alloc_whole_rl(type
));
43 static void match_end_func(struct symbol
*sym
)
47 sql_insert_return_values(show_rl(return_ranges
));
51 static void match_save_states(struct expression
*expr
)
53 __add_ptr_list(&backup
, return_ranges
, 0);
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
)
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
);