2 * Copyright (C) 2006 Dan Carpenter.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, see http://www.gnu.org/copyleft/gpl.txt
29 #include "expression.h"
36 unsigned long long uvalue
;
44 #define STATE(_x) static struct smatch_state _x = { .name = #_x }
45 extern struct smatch_state undefined
;
46 extern struct smatch_state ghost
;
47 extern struct smatch_state merged
;
48 extern struct smatch_state true_state
;
49 extern struct smatch_state false_state
;
50 DECLARE_ALLOCATOR(smatch_state
);
52 static inline void *INT_PTR(int i
)
54 return (void *)(long)i
;
57 static inline int PTR_INT(void *p
)
67 DECLARE_ALLOCATOR(tracker
);
68 DECLARE_PTR_LIST(tracker_list
, struct tracker
);
69 DECLARE_PTR_LIST(stree_stack
, struct stree
);
71 /* The first 3 struct members must match struct tracker */
76 unsigned short merged
:1;
77 unsigned short implied
:1;
78 unsigned int nr_children
;
80 struct smatch_state
*state
;
82 struct sm_state
*left
;
83 struct sm_state
*right
;
84 struct state_list
*possible
;
91 DECLARE_ALLOCATOR(var_sym
);
92 DECLARE_PTR_LIST(var_sym_list
, struct var_sym
);
103 GLOBAL_ASSIGNMENT_HOOK
,
108 WHOLE_CONDITION_HOOK
,
110 CALL_HOOK_AFTER_INLINE
,
111 FUNCTION_CALL_HOOK_AFTER
,
112 CALL_ASSIGNMENT_HOOK
,
113 MACRO_ASSIGNMENT_HOOK
,
137 void add_hook(void *func
, enum hook_type type
);
138 typedef struct smatch_state
*(merge_func_t
)(struct smatch_state
*s1
, struct smatch_state
*s2
);
139 typedef struct smatch_state
*(unmatched_func_t
)(struct sm_state
*state
);
140 void add_merge_hook(int client_id
, merge_func_t
*func
);
141 void add_unmatched_state_hook(int client_id
, unmatched_func_t
*func
);
142 void add_pre_merge_hook(int client_id
, void (*hook
)(struct sm_state
*sm
));
143 typedef void (scope_hook
)(void *data
);
144 void add_scope_hook(scope_hook
*hook
, void *data
);
145 typedef void (func_hook
)(const char *fn
, struct expression
*expr
, void *data
);
146 typedef void (implication_hook
)(const char *fn
, struct expression
*call_expr
,
147 struct expression
*assign_expr
, void *data
);
148 typedef void (return_implies_hook
)(struct expression
*call_expr
,
149 int param
, char *key
, char *value
);
150 typedef int (implied_return_hook
)(struct expression
*call_expr
, void *info
, struct range_list
**rl
);
151 void add_function_hook(const char *look_for
, func_hook
*call_back
, void *data
);
153 void add_function_assign_hook(const char *look_for
, func_hook
*call_back
,
155 void add_implied_return_hook(const char *look_for
,
156 implied_return_hook
*call_back
,
158 void add_macro_assign_hook(const char *look_for
, func_hook
*call_back
,
160 void add_macro_assign_hook_extra(const char *look_for
, func_hook
*call_back
,
162 void return_implies_state(const char *look_for
, long long start
, long long end
,
163 implication_hook
*call_back
, void *info
);
164 void select_return_states_hook(int type
, return_implies_hook
*callback
);
165 void select_return_states_before(void (*fn
)(void));
166 void select_return_states_after(void (*fn
)(void));
167 int get_implied_return(struct expression
*expr
, struct range_list
**rl
);
168 void allocate_hook_memory(void);
170 struct modification_data
{
171 struct smatch_state
*prev
;
172 struct expression
*cur
;
175 typedef void (modification_hook
)(struct sm_state
*sm
, struct expression
*mod_expr
);
176 void add_modification_hook(int owner
, modification_hook
*call_back
);
177 void add_indirect_modification_hook(int owner
, modification_hook
*call_back
);
178 struct smatch_state
*get_modification_state(struct expression
*expr
);
180 int outside_of_function(void);
181 const char *get_filename(void);
182 const char *get_base_file(void);
183 char *get_function(void);
184 int get_lineno(void);
185 extern int final_pass
;
186 extern struct symbol
*cur_func_sym
;
187 extern int option_debug
;
188 extern int local_debug
;
189 extern int option_info
;
190 extern char *trace_variable
;
191 extern struct stree
*global_states
;
192 int is_silenced_function(void);
194 extern FILE *sm_outfd
;
195 #define sm_printf(msg...) do { if (final_pass || option_debug || local_debug) fprintf(sm_outfd, msg); } while (0)
197 static inline void sm_prefix(void)
199 sm_printf("%s:%d %s() ", get_filename(), get_lineno(), get_function());
202 static inline void print_implied_debug_msg();
204 #define sm_msg(msg...) \
206 print_implied_debug_msg(); \
207 if (!option_debug && !final_pass && !local_debug) \
209 if (!option_info && is_silenced_function()) \
216 #define local_debug(msg...) \
222 extern char *implied_debug_msg
;
223 static inline void print_implied_debug_msg(void)
225 static struct symbol
*last_printed
= NULL
;
227 if (!implied_debug_msg
)
229 if (last_printed
== cur_func_sym
)
231 last_printed
= cur_func_sym
;
232 sm_msg("%s", implied_debug_msg
);
235 #define sm_debug(msg...) do { if (option_debug) sm_printf(msg); } while (0)
237 #define sm_info(msg...) do { \
238 if (option_debug || (option_info && final_pass)) { \
240 sm_printf("info: "); \
246 #define ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1))
248 struct smatch_state
*get_state(int owner
, const char *name
, struct symbol
*sym
);
249 struct smatch_state
*get_state_expr(int owner
, struct expression
*expr
);
250 struct state_list
*get_possible_states(int owner
, const char *name
,
252 struct state_list
*get_possible_states_expr(int owner
, struct expression
*expr
);
253 struct sm_state
*set_state(int owner
, const char *name
, struct symbol
*sym
,
254 struct smatch_state
*state
);
255 struct sm_state
*set_state_expr(int owner
, struct expression
*expr
,
256 struct smatch_state
*state
);
257 void delete_state(int owner
, const char *name
, struct symbol
*sym
);
258 void delete_state_expr(int owner
, struct expression
*expr
);
259 void set_true_false_states(int owner
, const char *name
, struct symbol
*sym
,
260 struct smatch_state
*true_state
,
261 struct smatch_state
*false_state
);
262 void set_true_false_states_expr(int owner
, struct expression
*expr
,
263 struct smatch_state
*true_state
,
264 struct smatch_state
*false_state
);
266 struct stree
*get_all_states_from_stree(int owner
, struct stree
*source
);
267 struct stree
*get_all_states_stree(int id
);
268 struct stree
*__get_cur_stree(void);
269 int is_reachable(void);
271 /* smatch_helper.c */
272 char *alloc_string(const char *str
);
273 void free_string(char *str
);
274 void append(char *dest
, const char *data
, int buff_len
);
275 void remove_parens(char *str
);
276 struct smatch_state
*alloc_state_num(int num
);
277 struct smatch_state
*alloc_state_str(const char *name
);
278 struct expression
*get_argument_from_call_expr(struct expression_list
*args
,
281 char *expr_to_var(struct expression
*expr
);
282 struct symbol
*expr_to_sym(struct expression
*expr
);
283 char *expr_to_str(struct expression
*expr
);
284 char *expr_to_str_sym(struct expression
*expr
,
285 struct symbol
**sym_ptr
);
286 char *expr_to_var_sym(struct expression
*expr
,
287 struct symbol
**sym_ptr
);
288 char *expr_to_known_chunk_sym(struct expression
*expr
, struct symbol
**sym
);
289 char *expr_to_chunk_sym_vsl(struct expression
*expr
, struct symbol
**sym
, struct var_sym_list
**vsl
);
290 int get_complication_score(struct expression
*expr
);
292 int sym_name_is(const char *name
, struct expression
*expr
);
293 int get_const_value(struct expression
*expr
, sval_t
*sval
);
294 int get_value(struct expression
*expr
, sval_t
*val
);
295 int get_implied_value(struct expression
*expr
, sval_t
*val
);
296 int get_implied_min(struct expression
*expr
, sval_t
*sval
);
297 int get_implied_max(struct expression
*expr
, sval_t
*val
);
298 int get_hard_max(struct expression
*expr
, sval_t
*sval
);
299 int get_fuzzy_min(struct expression
*expr
, sval_t
*min
);
300 int get_fuzzy_max(struct expression
*expr
, sval_t
*max
);
301 int get_absolute_min(struct expression
*expr
, sval_t
*sval
);
302 int get_absolute_max(struct expression
*expr
, sval_t
*sval
);
303 int parse_call_math(struct expression
*expr
, char *math
, sval_t
*val
);
304 int parse_call_math_rl(struct expression
*call
, char *math
, struct range_list
**rl
);
305 char *get_value_in_terms_of_parameter_math(struct expression
*expr
);
306 char *get_value_in_terms_of_parameter_math_var_sym(const char *var
, struct symbol
*sym
);
307 int is_zero(struct expression
*expr
);
308 int known_condition_true(struct expression
*expr
);
309 int known_condition_false(struct expression
*expr
);
310 int implied_condition_true(struct expression
*expr
);
311 int implied_condition_false(struct expression
*expr
);
312 int can_integer_overflow(struct symbol
*type
, struct expression
*expr
);
314 int is_array(struct expression
*expr
);
315 struct expression
*get_array_base(struct expression
*expr
);
316 struct expression
*get_array_offset(struct expression
*expr
);
317 const char *show_state(struct smatch_state
*state
);
318 struct statement
*get_expression_statement(struct expression
*expr
);
319 struct expression
*strip_parens(struct expression
*expr
);
320 struct expression
*strip_expr(struct expression
*expr
);
321 void scoped_state(int my_id
, const char *name
, struct symbol
*sym
);
322 int is_error_return(struct expression
*expr
);
323 int getting_address(void);
324 char *get_member_name(struct expression
*expr
);
325 char *get_fnptr_name(struct expression
*expr
);
326 int cmp_pos(struct position pos1
, struct position pos2
);
327 int positions_eq(struct position pos1
, struct position pos2
);
328 struct statement
*get_current_statement(void);
329 struct statement
*get_prev_statement(void);
330 int get_param_num_from_sym(struct symbol
*sym
);
331 int get_param_num(struct expression
*expr
);
332 int ms_since(struct timeval
*start
);
333 int parent_is_gone_var_sym(const char *name
, struct symbol
*sym
);
334 int parent_is_gone(struct expression
*expr
);
335 int invert_op(int op
);
336 int expr_equiv(struct expression
*one
, struct expression
*two
);
339 struct symbol
*get_real_base_type(struct symbol
*sym
);
340 int type_bits(struct symbol
*type
);
341 int type_bytes(struct symbol
*type
);
342 int type_positive_bits(struct symbol
*type
);
343 struct symbol
*get_pointer_type(struct expression
*expr
);
344 struct symbol
*get_type(struct expression
*expr
);
345 int type_unsigned(struct symbol
*base_type
);
346 int type_signed(struct symbol
*base_type
);
347 int expr_unsigned(struct expression
*expr
);
348 int expr_signed(struct expression
*expr
);
349 int returns_unsigned(struct symbol
*base_type
);
350 int is_pointer(struct expression
*expr
);
351 int returns_pointer(struct symbol
*base_type
);
352 sval_t
sval_type_max(struct symbol
*base_type
);
353 sval_t
sval_type_min(struct symbol
*base_type
);
354 int nr_bits(struct expression
*expr
);
355 int is_void_pointer(struct expression
*expr
);
356 int is_char_pointer(struct expression
*expr
);
357 int is_string(struct expression
*expr
);
358 int is_static(struct expression
*expr
);
359 int is_local_variable(struct expression
*expr
);
360 int types_equiv(struct symbol
*one
, struct symbol
*two
);
362 const char *global_static();
363 struct symbol
*cur_func_return_type(void);
364 struct symbol
*get_arg_type(struct expression
*fn
, int arg
);
365 struct symbol
*get_member_type_from_key(struct expression
*expr
, char *key
);
366 int is_struct(struct expression
*expr
);
367 char *type_to_str(struct symbol
*type
);
369 /* smatch_ignore.c */
370 void add_ignore(int owner
, const char *name
, struct symbol
*sym
);
371 int is_ignored(int owner
, const char *name
, struct symbol
*sym
);
374 struct var_sym
*alloc_var_sym(const char *var
, struct symbol
*sym
);
375 struct var_sym_list
*expr_to_vsl(struct expression
*expr
);
376 void add_var_sym(struct var_sym_list
**list
, const char *var
, struct symbol
*sym
);
377 void add_var_sym_expr(struct var_sym_list
**list
, struct expression
*expr
);
378 void del_var_sym(struct var_sym_list
**list
, const char *var
, struct symbol
*sym
);
379 int in_var_sym_list(struct var_sym_list
*list
, const char *var
, struct symbol
*sym
);
380 struct var_sym_list
*clone_var_sym_list(struct var_sym_list
*from_vsl
);
381 void merge_var_sym_list(struct var_sym_list
**dest
, struct var_sym_list
*src
);
382 struct var_sym_list
*combine_var_sym_lists(struct var_sym_list
*one
, struct var_sym_list
*two
);
383 void free_var_sym_list(struct var_sym_list
**list
);
384 void free_var_syms_and_list(struct var_sym_list
**list
);
387 struct tracker
*alloc_tracker(int owner
, const char *name
, struct symbol
*sym
);
388 void add_tracker(struct tracker_list
**list
, int owner
, const char *name
,
390 void add_tracker_expr(struct tracker_list
**list
, int owner
, struct expression
*expr
);
391 void del_tracker(struct tracker_list
**list
, int owner
, const char *name
,
393 int in_tracker_list(struct tracker_list
*list
, int owner
, const char *name
,
395 void free_tracker_list(struct tracker_list
**list
);
396 void free_trackers_and_list(struct tracker_list
**list
);
398 /* smatch_conditions */
399 int in_condition(void);
403 extern int __in_fake_assign
;
404 void smatch (int argc
, char **argv
);
405 int inside_loop(void);
406 int definitely_inside_loop(void);
407 struct expression
*get_switch_expr(void);
408 int in_expression_statement(void);
409 void __process_post_op_stack(void);
410 void __split_expr(struct expression
*expr
);
411 void __split_stmt(struct statement
*stmt
);
412 extern int __in_function_def
;
413 extern int option_assume_loops
;
414 extern int option_two_passes
;
415 extern int option_no_db
;
416 extern int option_file_output
;
417 extern int option_time
;
418 extern struct expression_list
*big_expression_stack
;
419 extern struct statement_list
*big_statement_stack
;
420 int is_assigned_call(struct expression
*expr
);
421 int inlinable(struct expression
*expr
);
422 extern int __inline_call
;
423 extern struct expression
*__inline_fn
;
424 extern int __in_pre_condition
;
425 extern int __bail_on_rest_of_function
;
426 extern struct statement
*__prev_stmt
;
427 extern struct statement
*__cur_stmt
;
428 extern struct statement
*__next_stmt
;
430 /* smatch_struct_assignment.c */
431 struct expression
*get_faked_expression(void);
432 void __fake_struct_member_assignments(struct expression
*expr
);
434 /* smatch_project.c */
435 int is_no_inline_function(const char *function
);
437 /* smatch_conditions */
438 void __split_whole_condition(struct expression
*expr
);
439 void __handle_logic(struct expression
*expr
);
440 int is_condition(struct expression
*expr
);
441 int __handle_condition_assigns(struct expression
*expr
);
442 int __handle_select_assigns(struct expression
*expr
);
443 int __handle_expr_statement_assigns(struct expression
*expr
);
445 /* smatch_implied.c */
446 extern int option_debug_implied
;
447 extern int option_debug_related
;
448 struct range_list_stack
;
449 struct stree
*__implied_case_stree(struct expression
*switch_expr
,
450 struct expression
*case_expr
,
451 struct expression
*case_to
,
452 struct range_list_stack
**remaining_cases
,
453 struct stree
**raw_stree
);
454 struct range_list
*__get_implied_values(struct expression
*switch_expr
);
455 void overwrite_states_using_pool(struct sm_state
*sm
);
456 void add_pool(struct stree_stack
**pools
, struct stree
*new);
458 /* smatch_extras.c */
459 #define SMATCH_EXTRA 1 /* this is my_id from smatch extra set in smatch.c */
466 extern long long valid_ptr_min
, valid_ptr_max
;
467 extern sval_t valid_ptr_min_sval
, valid_ptr_max_sval
;
468 static const sval_t array_min_sval
= {
472 static const sval_t array_max_sval
= {
476 static const sval_t text_seg_min
= {
478 {.value
= 100000000},
480 static const sval_t text_seg_max
= {
482 {.value
= 177777777},
484 static const sval_t data_seg_min
= {
486 {.value
= 200000000},
488 static const sval_t data_seg_max
= {
490 {.value
= 277777777},
492 static const sval_t bss_seg_min
= {
494 {.value
= 300000000},
496 static const sval_t bss_seg_max
= {
498 {.value
= 377777777},
500 static const sval_t stack_seg_min
= {
502 {.value
= 400000000},
504 static const sval_t stack_seg_max
= {
506 {.value
= 477777777},
508 static const sval_t kmalloc_seg_min
= {
510 {.value
= 500000000},
512 static const sval_t kmalloc_seg_max
= {
514 {.value
= 577777777},
516 static const sval_t vmalloc_seg_min
= {
518 {.value
= 600000000},
520 static const sval_t vmalloc_seg_max
= {
522 {.value
= 677777777},
525 #define STRLEN_MAX_RET 1010101
527 /* smatch_absolute.c */
528 int get_absolute_min_helper(struct expression
*expr
, sval_t
*sval
);
529 int get_absolute_max_helper(struct expression
*expr
, sval_t
*sval
);
531 /* smatch_local_values.c */
532 int get_local_rl(struct expression
*expr
, struct range_list
**rl
);
533 int get_local_max_helper(struct expression
*expr
, sval_t
*sval
);
534 int get_local_min_helper(struct expression
*expr
, sval_t
*sval
);
536 /* smatch_type_value.c */
537 int get_db_type_rl(struct expression
*expr
, struct range_list
**rl
);
539 /* smatch_states.c */
540 void __swap_cur_stree(struct stree
*stree
);
541 void __push_fake_cur_stree();
542 struct stree
*__pop_fake_cur_stree();
543 void __free_fake_cur_stree();
544 void __set_fake_cur_stree_fast(struct stree
*stree
);
545 void __pop_fake_cur_stree_fast(void);
546 void __merge_stree_into_cur(struct stree
*stree
);
548 int unreachable(void);
549 void __set_sm(struct sm_state
*sm
);
550 void __use_orig_if_not_set(struct sm_state
*sm
);
551 void __set_true_false_sm(struct sm_state
*true_state
,
552 struct sm_state
*false_state
);
553 void nullify_path(void);
554 void __match_nullify_path_hook(const char *fn
, struct expression
*expr
,
556 void __unnullify_path(void);
557 int __path_is_null(void);
558 void save_all_states(void);
559 void restore_all_states(void);
560 void free_goto_stack(void);
561 void clear_all_states(void);
563 struct sm_state
*get_sm_state(int owner
, const char *name
,
565 struct sm_state
*get_sm_state_expr(int owner
, struct expression
*expr
);
566 void __push_true_states(void);
567 void __use_false_states(void);
568 void __discard_false_states(void);
569 void __merge_false_states(void);
570 void __merge_true_states(void);
572 void __negate_cond_stacks(void);
573 void __use_pre_cond_states(void);
574 void __use_cond_true_states(void);
575 void __use_cond_false_states(void);
576 void __push_cond_stacks(void);
577 struct stree
*__copy_cond_true_states(void);
578 struct stree
*__copy_cond_false_states(void);
579 struct stree
*__pop_cond_true_stack(void);
580 struct stree
*__pop_cond_false_stack(void);
581 void __and_cond_states(void);
582 void __or_cond_states(void);
583 void __save_pre_cond_states(void);
584 void __discard_pre_cond_states(void);
585 void __use_cond_states(void);
586 extern struct state_list
*__last_base_slist
;
588 void __push_continues(void);
589 void __discard_continues(void);
590 void __process_continues(void);
591 void __merge_continues(void);
593 void __push_breaks(void);
594 void __process_breaks(void);
595 int __has_breaks(void);
596 void __merge_breaks(void);
597 void __use_breaks(void);
599 void __save_switch_states(struct expression
*switch_expr
);
600 void __discard_switches(void);
601 void __merge_switches(struct expression
*switch_expr
, struct expression
*case_expr
, struct expression
*case_to
);
602 void __push_default(void);
603 void __set_default(void);
604 int __pop_default(void);
606 void __push_conditions(void);
607 void __discard_conditions(void);
609 void __save_gotos(const char *name
);
610 void __merge_gotos(const char *name
);
612 void __print_cur_stree(void);
615 void __pass_to_client(void *data
, enum hook_type type
);
616 void __pass_to_client_no_data(enum hook_type type
);
617 void __pass_case_to_client(struct expression
*switch_expr
,
618 struct expression
*case_expr
);
619 int __has_merge_function(int client_id
);
620 struct smatch_state
*__client_merge_function(int owner
,
621 struct smatch_state
*s1
,
622 struct smatch_state
*s2
);
623 struct smatch_state
*__client_unmatched_state_function(struct sm_state
*sm
);
624 void call_pre_merge_hook(struct sm_state
*sm
);
625 void __push_scope_hooks(void);
626 void __call_scope_hooks(void);
628 /* smatch_function_hooks.c */
629 void create_function_hook_hash(void);
630 void __match_initializer_call(struct symbol
*sym
);
636 * Changing these numbers is a pain. Don't do it. If you ever use a
637 * number it can't be re-used right away so there may be gaps.
638 * We select these in order by type so if the order matters, then give
639 * it a number below 100-999,9000-9999 ranges. */
653 LOCK_RELEASED
= 1009,
654 ABSOLUTE_LIMITS
= 1010,
664 UNTRACKED_PARAM
= 1023,
669 /* put random temporary stuff in the 7000-7999 range for testing */
671 USER_DATA_SET
= 9018,
672 USER_DATA_LIMITED
= 9019,
675 void debug_sql(const char *sql
);
676 void debug_mem_sql(const char *sql
);
677 void select_caller_info_hook(void (*callback
)(const char *name
, struct symbol
*sym
, char *key
, char *value
), int type
);
678 void add_member_info_callback(int owner
, void (*callback
)(struct expression
*call
, int param
, char *printed_name
, struct sm_state
*sm
));
679 void add_split_return_callback(void (*fn
)(int return_id
, char *return_ranges
, struct expression
*returned_expr
));
680 void add_returned_member_callback(int owner
, void (*callback
)(int return_id
, char *return_ranges
, struct expression
*expr
, char *printed_name
, struct smatch_state
*state
));
681 void select_call_implies_hook(int type
, void (*callback
)(struct expression
*arg
, char *key
, char *value
));
682 struct range_list
*db_return_vals(struct expression
*expr
);
683 char *return_state_to_var_sym(struct expression
*expr
, int param
, char *key
, struct symbol
**sym
);
684 char *get_variable_from_key(struct expression
*arg
, char *key
, struct symbol
**sym
);
685 const char *get_param_name(struct sm_state
*sm
);
686 char *get_data_info_name(struct expression
*expr
);
688 #define run_sql(call_back, data, sql...) \
690 char sql_txt[1024]; \
693 snprintf(sql_txt, 1024, sql); \
694 debug_sql(sql_txt); \
695 sql_exec(call_back, data, sql_txt); \
698 /* like run_sql() but for the in-memory database */
699 #define mem_sql(call_back, data, sql...) \
701 char sql_txt[1024]; \
703 snprintf(sql_txt, sizeof(sql_txt), sql); \
704 sm_debug("in-mem: %s\n", sql_txt); \
705 debug_mem_sql(sql_txt); \
706 sql_mem_exec(call_back, data, sql_txt); \
709 char *get_static_filter(struct symbol
*sym
);
711 void sql_insert_return_states(int return_id
, const char *return_ranges
,
712 int type
, int param
, const char *key
, const char *value
);
713 void sql_insert_caller_info(struct expression
*call
, int type
, int param
,
714 const char *key
, const char *value
);
715 void sql_insert_function_ptr(const char *fn
, const char *struct_name
);
716 void sql_insert_return_values(const char *return_values
);
717 void sql_insert_call_implies(int type
, int param
, const char *key
, const char *value
);
718 void sql_insert_function_type_size(const char *member
, const char *ranges
);
719 void sql_insert_local_values(const char *name
, const char *value
);
720 void sql_insert_function_type_value(const char *type
, const char *value
);
721 void sql_insert_function_type_info(int param
, const char *value
);
722 void sql_insert_data_info(struct expression
*data
, int type
, const char *value
);
724 void sql_select_return_states(const char *cols
, struct expression
*call
,
725 int (*callback
)(void*, int, char**, char**), void *info
);
726 void sql_select_caller_info(const char *cols
, struct symbol
*sym
,
727 int (*callback
)(void*, int, char**, char**));
728 void sql_select_call_implies(const char *cols
, struct expression
*call
,
729 int (*callback
)(void*, int, char**, char**));
731 void sql_exec(int (*callback
)(void*, int, char**, char**), void *data
, const char *sql
);
732 void sql_mem_exec(int (*callback
)(void*, int, char**, char**), void *data
, const char *sql
);
734 void open_smatch_db(void);
737 int open_data_file(const char *filename
);
738 struct token
*get_tokens_file(const char *filename
);
741 extern char *option_debug_check
;
742 extern char *option_project_str
;
743 extern char *data_dir
;
744 extern int option_no_data
;
745 extern int option_spammy
;
746 extern int option_full_path
;
747 extern int option_param_mapper
;
748 extern int option_call_tree
;
749 extern int num_checks
;
756 extern enum project_type option_project
;
757 const char *check_name(unsigned short id
);
760 /* smatch_buf_size.c */
761 int get_array_size(struct expression
*expr
);
762 int get_array_size_bytes(struct expression
*expr
);
763 int get_array_size_bytes_min(struct expression
*expr
);
764 int get_array_size_bytes_max(struct expression
*expr
);
765 struct range_list
*get_array_size_bytes_rl(struct expression
*expr
);
766 int get_real_array_size(struct expression
*expr
);
767 /* smatch_strlen.c */
768 int get_implied_strlen(struct expression
*expr
, struct range_list
**rl
);
769 int get_size_from_strlen(struct expression
*expr
);
771 /* smatch_capped.c */
772 int is_capped(struct expression
*expr
);
773 int is_capped_var_sym(const char *name
, struct symbol
*sym
);
775 /* check_user_data.c */
776 int is_user_macro(struct expression
*expr
);
777 int is_user_data(struct expression
*expr
);
778 int is_capped_user_data(struct expression
*expr
);
779 int implied_user_data(struct expression
*expr
, struct range_list
**rl
);
780 int get_user_rl(struct expression
*expr
, struct range_list
**rl
);
781 int get_user_rl_var_sym(const char *name
, struct symbol
*sym
, struct range_list
**rl
);
783 /* check_locking.c */
784 void print_held_locks();
786 /* check_assigned_expr.c */
787 struct expression
*get_assigned_expr(struct expression
*expr
);
788 struct expression
*get_assigned_expr_name_sym(const char *name
, struct symbol
*sym
);
790 /* smatch_comparison.c */
791 struct compare_data
{
793 struct var_sym_list
*vsl1
;
796 struct var_sym_list
*vsl2
;
798 int get_comparison(struct expression
*left
, struct expression
*right
);
799 int get_comparison_strings(const char *one
, const char *two
);
800 int possible_comparison(struct expression
*a
, int comparison
, struct expression
*b
);
801 struct state_list
*get_all_comparisons(struct expression
*expr
);
802 struct state_list
*get_all_possible_equal_comparisons(struct expression
*expr
);
803 void __add_comparison_info(struct expression
*expr
, struct expression
*call
, const char *range
);
804 char *name_sym_to_param_comparison(const char *name
, struct symbol
*sym
);
805 char *expr_equal_to_param(struct expression
*expr
, int ignore
);
806 char *expr_lte_to_param(struct expression
*expr
, int ignore
);
807 char *expr_param_comparison(struct expression
*expr
, int ignore
);
808 int flip_comparison(int op
);
809 int negate_comparison(int op
);
810 void filter_by_comparison(struct range_list
**rl
, int comparison
, struct range_list
*right
);
811 struct sm_state
*comparison_implication_hook(struct expression
*expr
,
812 struct stree_stack
**true_stack
,
813 struct stree_stack
**false_stack
);
816 sval_t
*sval_alloc(sval_t sval
);
817 sval_t
*sval_alloc_permanent(sval_t sval
);
818 sval_t
sval_blank(struct expression
*expr
);
819 sval_t
sval_type_val(struct symbol
*type
, long long val
);
820 sval_t
sval_from_val(struct expression
*expr
, long long val
);
821 int sval_unsigned(sval_t sval
);
822 int sval_signed(sval_t sval
);
823 int sval_bits(sval_t sval
);
824 int sval_positive_bits(sval_t sval
);
825 int sval_bits_used(sval_t sval
);
826 int sval_is_negative(sval_t sval
);
827 int sval_is_positive(sval_t sval
);
828 int sval_is_min(sval_t sval
);
829 int sval_is_max(sval_t sval
);
830 int sval_is_a_min(sval_t sval
);
831 int sval_is_a_max(sval_t sval
);
832 int sval_is_negative_min(sval_t sval
);
833 int sval_cmp(sval_t one
, sval_t two
);
834 int sval_cmp_t(struct symbol
*type
, sval_t one
, sval_t two
);
835 int sval_cmp_val(sval_t one
, long long val
);
836 sval_t
sval_min(sval_t one
, sval_t two
);
837 sval_t
sval_max(sval_t one
, sval_t two
);
838 int sval_too_low(struct symbol
*type
, sval_t sval
);
839 int sval_too_high(struct symbol
*type
, sval_t sval
);
840 int sval_fits(struct symbol
*type
, sval_t sval
);
841 sval_t
sval_cast(struct symbol
*type
, sval_t sval
);
842 sval_t
sval_preop(sval_t sval
, int op
);
843 sval_t
sval_binop(sval_t left
, int op
, sval_t right
);
844 int sval_binop_overflows(sval_t left
, int op
, sval_t right
);
845 unsigned long long fls_mask(unsigned long long uvalue
);
846 unsigned long long sval_fls_mask(sval_t sval
);
847 const char *sval_to_str(sval_t sval
);
848 const char *sval_to_numstr(sval_t sval
);
849 sval_t
ll_to_sval(long long val
);
851 /* smatch_string_list.c */
852 int list_has_string(struct string_list
*str_list
, const char *str
);
853 void insert_string(struct string_list
**str_list
, const char *str
);
854 struct string_list
*clone_str_list(struct string_list
*orig
);
855 struct string_list
*combine_string_lists(struct string_list
*one
, struct string_list
*two
);
857 /* smatch_start_states.c */
858 struct stree
*get_start_states(void);
860 /* smatch_recurse.c */
861 int has_symbol(struct expression
*expr
, struct symbol
*sym
);
862 int has_variable(struct expression
*expr
, struct expression
*var
);
863 int has_inc_dec(struct expression
*expr
);
865 /* smatch_stored_conditions.c */
866 struct smatch_state
*get_stored_condition(struct expression
*expr
);
867 struct sm_state
*stored_condition_implication_hook(struct expression
*expr
,
868 struct stree_stack
**true_stack
,
869 struct stree_stack
**false_stack
);
871 /* check_string_len.c */
872 int get_formatted_string_size(struct expression
*call
, int arg
);
874 /* smatch_param_set.c */
875 int param_was_set(struct expression
*expr
);
876 /* smatch_param_filter.c */
877 int param_has_filter_data(struct sm_state
*sm
);
880 void set_up_link_functions(int id
, int linkid
);
881 struct smatch_state
*merge_link_states(struct smatch_state
*s1
, struct smatch_state
*s2
);
882 void store_link(int link_id
, const char *name
, struct symbol
*sym
, const char *link_name
, struct symbol
*link_sym
);
884 /* smatch_auto_copy.c */
885 void set_auto_copy(int owner
);
887 /* check_buf_comparison */
888 struct expression
*get_size_variable(struct expression
*buf
);
890 /* smatch_untracked_param.c */
891 void add_untracked_param_hook(void (func
)(struct expression
*call
, int param
));
893 /* smatch_impossible.c */
894 int is_impossible_path(void);
896 /* smatch_strings.c */
897 struct state_list
*get_strings(struct expression
*expr
);
899 /* smatch_estate.c */
900 int estate_get_single_value(struct smatch_state
*state
, sval_t
*sval
);
902 /* smatch_address.c */
903 int get_address_rl(struct expression
*expr
, struct range_list
**rl
);
904 int get_member_offset(struct symbol
*type
, char *member_name
);
905 int get_member_offset_from_deref(struct expression
*expr
);
907 /* for now this is in smatch_used_parameter.c */
908 void __get_state_hook(int owner
, const char *name
, struct symbol
*sym
);
910 /* smatch_buf_comparison.c */
911 int db_var_is_array_limit(struct expression
*array
, const char *name
, struct var_sym_list
*vsl
);
913 #endif /* !SMATCH_H_ */