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_DB
,
112 CALL_ASSIGNMENT_HOOK
,
113 MACRO_ASSIGNMENT_HOOK
,
138 void add_hook(void *func
, enum hook_type type
);
139 typedef struct smatch_state
*(merge_func_t
)(struct smatch_state
*s1
, struct smatch_state
*s2
);
140 typedef struct smatch_state
*(unmatched_func_t
)(struct sm_state
*state
);
141 void add_merge_hook(int client_id
, merge_func_t
*func
);
142 void add_unmatched_state_hook(int client_id
, unmatched_func_t
*func
);
143 void add_pre_merge_hook(int client_id
, void (*hook
)(struct sm_state
*sm
));
144 typedef void (scope_hook
)(void *data
);
145 void add_scope_hook(scope_hook
*hook
, void *data
);
146 typedef void (func_hook
)(const char *fn
, struct expression
*expr
, void *data
);
147 typedef void (implication_hook
)(const char *fn
, struct expression
*call_expr
,
148 struct expression
*assign_expr
, void *data
);
149 typedef void (return_implies_hook
)(struct expression
*call_expr
,
150 int param
, char *key
, char *value
);
151 typedef int (implied_return_hook
)(struct expression
*call_expr
, void *info
, struct range_list
**rl
);
152 void add_function_hook(const char *look_for
, func_hook
*call_back
, void *data
);
154 void add_function_assign_hook(const char *look_for
, func_hook
*call_back
,
156 void add_implied_return_hook(const char *look_for
,
157 implied_return_hook
*call_back
,
159 void add_macro_assign_hook(const char *look_for
, func_hook
*call_back
,
161 void add_macro_assign_hook_extra(const char *look_for
, func_hook
*call_back
,
163 void return_implies_state(const char *look_for
, long long start
, long long end
,
164 implication_hook
*call_back
, void *info
);
165 void select_return_states_hook(int type
, return_implies_hook
*callback
);
166 void select_return_states_before(void (*fn
)(void));
167 void select_return_states_after(void (*fn
)(void));
168 int get_implied_return(struct expression
*expr
, struct range_list
**rl
);
169 void allocate_hook_memory(void);
171 struct modification_data
{
172 struct smatch_state
*prev
;
173 struct expression
*cur
;
176 typedef void (modification_hook
)(struct sm_state
*sm
, struct expression
*mod_expr
);
177 void add_modification_hook(int owner
, modification_hook
*call_back
);
178 void add_indirect_modification_hook(int owner
, modification_hook
*call_back
);
179 void add_modification_hook_late(int owner
, modification_hook
*call_back
);
180 void add_indirect_modification_hook_late(int owner
, modification_hook
*call_back
);
181 struct smatch_state
*get_modification_state(struct expression
*expr
);
183 int outside_of_function(void);
184 const char *get_filename(void);
185 const char *get_base_file(void);
186 char *get_function(void);
187 int get_lineno(void);
188 extern int final_pass
;
189 extern struct symbol
*cur_func_sym
;
190 extern int option_debug
;
191 extern int local_debug
;
192 extern int option_info
;
193 extern char *trace_variable
;
194 extern struct stree
*global_states
;
195 int is_silenced_function(void);
197 extern FILE *sm_outfd
;
198 #define sm_printf(msg...) do { if (final_pass || option_debug || local_debug) fprintf(sm_outfd, msg); } while (0)
200 static inline void sm_prefix(void)
202 sm_printf("%s:%d %s() ", get_filename(), get_lineno(), get_function());
205 static inline void print_implied_debug_msg();
207 #define sm_msg(msg...) \
209 print_implied_debug_msg(); \
210 if (!option_debug && !final_pass && !local_debug) \
212 if (!option_info && is_silenced_function()) \
219 #define local_debug(msg...) \
225 extern char *implied_debug_msg
;
226 static inline void print_implied_debug_msg(void)
228 static struct symbol
*last_printed
= NULL
;
230 if (!implied_debug_msg
)
232 if (last_printed
== cur_func_sym
)
234 last_printed
= cur_func_sym
;
235 sm_msg("%s", implied_debug_msg
);
238 #define sm_debug(msg...) do { if (option_debug) sm_printf(msg); } while (0)
240 #define sm_info(msg...) do { \
241 if (option_debug || (option_info && final_pass)) { \
243 sm_printf("info: "); \
249 #define ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1))
251 struct smatch_state
*get_state(int owner
, const char *name
, struct symbol
*sym
);
252 struct smatch_state
*get_state_expr(int owner
, struct expression
*expr
);
253 struct state_list
*get_possible_states(int owner
, const char *name
,
255 struct state_list
*get_possible_states_expr(int owner
, struct expression
*expr
);
256 struct sm_state
*set_state(int owner
, const char *name
, struct symbol
*sym
,
257 struct smatch_state
*state
);
258 struct sm_state
*set_state_expr(int owner
, struct expression
*expr
,
259 struct smatch_state
*state
);
260 void delete_state(int owner
, const char *name
, struct symbol
*sym
);
261 void delete_state_expr(int owner
, struct expression
*expr
);
262 void __delete_all_states_sym(struct symbol
*sym
);
263 void set_true_false_states(int owner
, const char *name
, struct symbol
*sym
,
264 struct smatch_state
*true_state
,
265 struct smatch_state
*false_state
);
266 void set_true_false_states_expr(int owner
, struct expression
*expr
,
267 struct smatch_state
*true_state
,
268 struct smatch_state
*false_state
);
270 struct stree
*get_all_states_from_stree(int owner
, struct stree
*source
);
271 struct stree
*get_all_states_stree(int id
);
272 struct stree
*__get_cur_stree(void);
273 int is_reachable(void);
275 /* smatch_helper.c */
276 char *alloc_string(const char *str
);
277 void free_string(char *str
);
278 void append(char *dest
, const char *data
, int buff_len
);
279 void remove_parens(char *str
);
280 struct smatch_state
*alloc_state_num(int num
);
281 struct smatch_state
*alloc_state_str(const char *name
);
282 struct expression
*get_argument_from_call_expr(struct expression_list
*args
,
285 char *expr_to_var(struct expression
*expr
);
286 struct symbol
*expr_to_sym(struct expression
*expr
);
287 char *expr_to_str(struct expression
*expr
);
288 char *expr_to_str_sym(struct expression
*expr
,
289 struct symbol
**sym_ptr
);
290 char *expr_to_var_sym(struct expression
*expr
,
291 struct symbol
**sym_ptr
);
292 char *expr_to_known_chunk_sym(struct expression
*expr
, struct symbol
**sym
);
293 char *expr_to_chunk_sym_vsl(struct expression
*expr
, struct symbol
**sym
, struct var_sym_list
**vsl
);
294 int get_complication_score(struct expression
*expr
);
296 int sym_name_is(const char *name
, struct expression
*expr
);
297 int get_const_value(struct expression
*expr
, sval_t
*sval
);
298 int get_value(struct expression
*expr
, sval_t
*val
);
299 int get_implied_value(struct expression
*expr
, sval_t
*val
);
300 int get_implied_min(struct expression
*expr
, sval_t
*sval
);
301 int get_implied_max(struct expression
*expr
, sval_t
*val
);
302 int get_hard_max(struct expression
*expr
, sval_t
*sval
);
303 int get_fuzzy_min(struct expression
*expr
, sval_t
*min
);
304 int get_fuzzy_max(struct expression
*expr
, sval_t
*max
);
305 int get_absolute_min(struct expression
*expr
, sval_t
*sval
);
306 int get_absolute_max(struct expression
*expr
, sval_t
*sval
);
307 int parse_call_math(struct expression
*expr
, char *math
, sval_t
*val
);
308 int parse_call_math_rl(struct expression
*call
, char *math
, struct range_list
**rl
);
309 char *get_value_in_terms_of_parameter_math(struct expression
*expr
);
310 char *get_value_in_terms_of_parameter_math_var_sym(const char *var
, struct symbol
*sym
);
311 int is_zero(struct expression
*expr
);
312 int known_condition_true(struct expression
*expr
);
313 int known_condition_false(struct expression
*expr
);
314 int implied_condition_true(struct expression
*expr
);
315 int implied_condition_false(struct expression
*expr
);
316 int can_integer_overflow(struct symbol
*type
, struct expression
*expr
);
318 int is_array(struct expression
*expr
);
319 struct expression
*get_array_base(struct expression
*expr
);
320 struct expression
*get_array_offset(struct expression
*expr
);
321 const char *show_state(struct smatch_state
*state
);
322 struct statement
*get_expression_statement(struct expression
*expr
);
323 struct expression
*strip_parens(struct expression
*expr
);
324 struct expression
*strip_expr(struct expression
*expr
);
325 void scoped_state(int my_id
, const char *name
, struct symbol
*sym
);
326 int is_error_return(struct expression
*expr
);
327 int getting_address(void);
328 char *get_member_name(struct expression
*expr
);
329 char *get_fnptr_name(struct expression
*expr
);
330 int cmp_pos(struct position pos1
, struct position pos2
);
331 int positions_eq(struct position pos1
, struct position pos2
);
332 struct statement
*get_current_statement(void);
333 struct statement
*get_prev_statement(void);
334 int get_param_num_from_sym(struct symbol
*sym
);
335 int get_param_num(struct expression
*expr
);
336 int ms_since(struct timeval
*start
);
337 int parent_is_gone_var_sym(const char *name
, struct symbol
*sym
);
338 int parent_is_gone(struct expression
*expr
);
339 int invert_op(int op
);
340 int expr_equiv(struct expression
*one
, struct expression
*two
);
343 struct symbol
*get_real_base_type(struct symbol
*sym
);
344 int type_bits(struct symbol
*type
);
345 int type_bytes(struct symbol
*type
);
346 int type_positive_bits(struct symbol
*type
);
347 struct symbol
*get_pointer_type(struct expression
*expr
);
348 struct symbol
*get_type(struct expression
*expr
);
349 int type_unsigned(struct symbol
*base_type
);
350 int type_signed(struct symbol
*base_type
);
351 int expr_unsigned(struct expression
*expr
);
352 int expr_signed(struct expression
*expr
);
353 int returns_unsigned(struct symbol
*base_type
);
354 int is_pointer(struct expression
*expr
);
355 int returns_pointer(struct symbol
*base_type
);
356 sval_t
sval_type_max(struct symbol
*base_type
);
357 sval_t
sval_type_min(struct symbol
*base_type
);
358 int nr_bits(struct expression
*expr
);
359 int is_void_pointer(struct expression
*expr
);
360 int is_char_pointer(struct expression
*expr
);
361 int is_string(struct expression
*expr
);
362 int is_static(struct expression
*expr
);
363 int is_local_variable(struct expression
*expr
);
364 int types_equiv(struct symbol
*one
, struct symbol
*two
);
366 const char *global_static();
367 struct symbol
*cur_func_return_type(void);
368 struct symbol
*get_arg_type(struct expression
*fn
, int arg
);
369 struct symbol
*get_member_type_from_key(struct expression
*expr
, char *key
);
370 int is_struct(struct expression
*expr
);
371 char *type_to_str(struct symbol
*type
);
373 /* smatch_ignore.c */
374 void add_ignore(int owner
, const char *name
, struct symbol
*sym
);
375 int is_ignored(int owner
, const char *name
, struct symbol
*sym
);
378 struct var_sym
*alloc_var_sym(const char *var
, struct symbol
*sym
);
379 struct var_sym_list
*expr_to_vsl(struct expression
*expr
);
380 void add_var_sym(struct var_sym_list
**list
, const char *var
, struct symbol
*sym
);
381 void add_var_sym_expr(struct var_sym_list
**list
, struct expression
*expr
);
382 void del_var_sym(struct var_sym_list
**list
, const char *var
, struct symbol
*sym
);
383 int in_var_sym_list(struct var_sym_list
*list
, const char *var
, struct symbol
*sym
);
384 struct var_sym_list
*clone_var_sym_list(struct var_sym_list
*from_vsl
);
385 void merge_var_sym_list(struct var_sym_list
**dest
, struct var_sym_list
*src
);
386 struct var_sym_list
*combine_var_sym_lists(struct var_sym_list
*one
, struct var_sym_list
*two
);
387 void free_var_sym_list(struct var_sym_list
**list
);
388 void free_var_syms_and_list(struct var_sym_list
**list
);
391 struct tracker
*alloc_tracker(int owner
, const char *name
, struct symbol
*sym
);
392 void add_tracker(struct tracker_list
**list
, int owner
, const char *name
,
394 void add_tracker_expr(struct tracker_list
**list
, int owner
, struct expression
*expr
);
395 void del_tracker(struct tracker_list
**list
, int owner
, const char *name
,
397 int in_tracker_list(struct tracker_list
*list
, int owner
, const char *name
,
399 void free_tracker_list(struct tracker_list
**list
);
400 void free_trackers_and_list(struct tracker_list
**list
);
402 /* smatch_conditions */
403 int in_condition(void);
407 extern int __in_fake_assign
;
408 void smatch (int argc
, char **argv
);
409 int inside_loop(void);
410 int definitely_inside_loop(void);
411 struct expression
*get_switch_expr(void);
412 int in_expression_statement(void);
413 void __process_post_op_stack(void);
414 void set_parent_expr(struct expression
*expr
, struct expression
*parent
);
415 void __split_expr(struct expression
*expr
);
416 void __split_label_stmt(struct statement
*stmt
);
417 void __split_stmt(struct statement
*stmt
);
418 extern int __in_function_def
;
419 extern int option_assume_loops
;
420 extern int option_two_passes
;
421 extern int option_no_db
;
422 extern int option_file_output
;
423 extern int option_time
;
424 extern struct expression_list
*big_expression_stack
;
425 extern struct expression_list
*big_condition_stack
;
426 extern struct statement_list
*big_statement_stack
;
427 int is_assigned_call(struct expression
*expr
);
428 int inlinable(struct expression
*expr
);
429 extern int __inline_call
;
430 extern struct expression
*__inline_fn
;
431 extern int __in_pre_condition
;
432 extern int __bail_on_rest_of_function
;
433 extern struct statement
*__prev_stmt
;
434 extern struct statement
*__cur_stmt
;
435 extern struct statement
*__next_stmt
;
437 /* smatch_struct_assignment.c */
438 struct expression
*get_faked_expression(void);
439 void __fake_struct_member_assignments(struct expression
*expr
);
441 /* smatch_project.c */
442 int is_no_inline_function(const char *function
);
444 /* smatch_conditions */
445 void __split_whole_condition(struct expression
*expr
);
446 void __handle_logic(struct expression
*expr
);
447 int is_condition(struct expression
*expr
);
448 int __handle_condition_assigns(struct expression
*expr
);
449 int __handle_select_assigns(struct expression
*expr
);
450 int __handle_expr_statement_assigns(struct expression
*expr
);
452 /* smatch_implied.c */
453 extern int option_debug_implied
;
454 extern int option_debug_related
;
455 struct range_list_stack
;
456 void param_limit_implications(struct expression
*expr
, int param
, char *key
, char *value
);
457 struct stree
*__implied_case_stree(struct expression
*switch_expr
,
458 struct range_list
*case_rl
,
459 struct range_list_stack
**remaining_cases
,
460 struct stree
**raw_stree
);
461 struct range_list
*__get_implied_values(struct expression
*switch_expr
);
462 void overwrite_states_using_pool(struct sm_state
*sm
);
463 void add_pool(struct stree_stack
**pools
, struct stree
*new);
464 int assume(struct expression
*expr
);
465 void end_assume(void);
467 /* smatch_extras.c */
468 #define SMATCH_EXTRA 1 /* this is my_id from smatch extra set in smatch.c */
475 extern long long valid_ptr_min
, valid_ptr_max
;
476 extern sval_t valid_ptr_min_sval
, valid_ptr_max_sval
;
477 static const sval_t array_min_sval
= {
481 static const sval_t array_max_sval
= {
485 static const sval_t text_seg_min
= {
487 {.value
= 100000000},
489 static const sval_t text_seg_max
= {
491 {.value
= 177777777},
493 static const sval_t data_seg_min
= {
495 {.value
= 200000000},
497 static const sval_t data_seg_max
= {
499 {.value
= 277777777},
501 static const sval_t bss_seg_min
= {
503 {.value
= 300000000},
505 static const sval_t bss_seg_max
= {
507 {.value
= 377777777},
509 static const sval_t stack_seg_min
= {
511 {.value
= 400000000},
513 static const sval_t stack_seg_max
= {
515 {.value
= 477777777},
517 static const sval_t kmalloc_seg_min
= {
519 {.value
= 500000000},
521 static const sval_t kmalloc_seg_max
= {
523 {.value
= 577777777},
525 static const sval_t vmalloc_seg_min
= {
527 {.value
= 600000000},
529 static const sval_t vmalloc_seg_max
= {
531 {.value
= 677777777},
534 #define STRLEN_MAX_RET 1010101
536 /* smatch_absolute.c */
537 int get_absolute_min_helper(struct expression
*expr
, sval_t
*sval
);
538 int get_absolute_max_helper(struct expression
*expr
, sval_t
*sval
);
540 /* smatch_local_values.c */
541 int get_local_rl(struct expression
*expr
, struct range_list
**rl
);
542 int get_local_max_helper(struct expression
*expr
, sval_t
*sval
);
543 int get_local_min_helper(struct expression
*expr
, sval_t
*sval
);
545 /* smatch_type_value.c */
546 int get_db_type_rl(struct expression
*expr
, struct range_list
**rl
);
548 /* smatch_states.c */
549 void __swap_cur_stree(struct stree
*stree
);
550 void __push_fake_cur_stree();
551 struct stree
*__pop_fake_cur_stree();
552 void __free_fake_cur_stree();
553 void __set_fake_cur_stree_fast(struct stree
*stree
);
554 void __pop_fake_cur_stree_fast(void);
555 void __merge_stree_into_cur(struct stree
*stree
);
557 int unreachable(void);
558 void __set_sm(struct sm_state
*sm
);
559 void __set_sm_cur_stree(struct sm_state
*sm
);
560 void __set_sm_fake_stree(struct sm_state
*sm
);
561 void __set_true_false_sm(struct sm_state
*true_state
,
562 struct sm_state
*false_state
);
563 void __set_true_false_sm_if_not_already_set(struct sm_state
*true_sm
, struct sm_state
*false_sm
);
564 void nullify_path(void);
565 void __match_nullify_path_hook(const char *fn
, struct expression
*expr
,
567 void __unnullify_path(void);
568 int __path_is_null(void);
569 void save_all_states(void);
570 void restore_all_states(void);
571 void free_goto_stack(void);
572 void clear_all_states(void);
574 struct sm_state
*get_sm_state(int owner
, const char *name
,
576 struct sm_state
*get_sm_state_expr(int owner
, struct expression
*expr
);
577 void __push_true_states(void);
578 void __use_false_states(void);
579 void __discard_false_states(void);
580 void __merge_false_states(void);
581 void __merge_true_states(void);
583 void __negate_cond_stacks(void);
584 void __use_pre_cond_states(void);
585 void __use_cond_true_states(void);
586 void __use_cond_false_states(void);
587 void __push_cond_stacks(void);
588 void __fold_in_set_states(void);
589 void __free_set_states(void);
590 struct stree
*__copy_cond_true_states(void);
591 struct stree
*__copy_cond_false_states(void);
592 struct stree
*__pop_cond_true_stack(void);
593 struct stree
*__pop_cond_false_stack(void);
594 void __and_cond_states(void);
595 void __or_cond_states(void);
596 void __save_pre_cond_states(void);
597 void __discard_pre_cond_states(void);
598 struct stree
*__get_true_states(void);
599 struct stree
*__get_false_states(void);
600 void __use_cond_states(void);
601 extern struct state_list
*__last_base_slist
;
603 void __push_continues(void);
604 void __discard_continues(void);
605 void __process_continues(void);
606 void __merge_continues(void);
608 void __push_breaks(void);
609 void __process_breaks(void);
610 int __has_breaks(void);
611 void __merge_breaks(void);
612 void __use_breaks(void);
614 void __save_switch_states(struct expression
*switch_expr
);
615 void __discard_switches(void);
616 void __merge_switches(struct expression
*switch_expr
, struct range_list
*case_rl
);
617 void __push_default(void);
618 void __set_default(void);
619 int __pop_default(void);
621 void __push_conditions(void);
622 void __discard_conditions(void);
624 void __save_gotos(const char *name
);
625 void __merge_gotos(const char *name
);
627 void __print_cur_stree(void);
630 void __pass_to_client(void *data
, enum hook_type type
);
631 void __pass_to_client_no_data(enum hook_type type
);
632 void __pass_case_to_client(struct expression
*switch_expr
,
633 struct expression
*case_expr
);
634 int __has_merge_function(int client_id
);
635 struct smatch_state
*__client_merge_function(int owner
,
636 struct smatch_state
*s1
,
637 struct smatch_state
*s2
);
638 struct smatch_state
*__client_unmatched_state_function(struct sm_state
*sm
);
639 void call_pre_merge_hook(struct sm_state
*sm
);
640 void __push_scope_hooks(void);
641 void __call_scope_hooks(void);
643 /* smatch_function_hooks.c */
644 void create_function_hook_hash(void);
645 void __match_initializer_call(struct symbol
*sym
);
651 * Changing these numbers is a pain. Don't do it. If you ever use a
652 * number it can't be re-used right away so there may be gaps.
653 * We select these in order by type so if the order matters, then give
654 * it a number below 100-999,9000-9999 ranges. */
668 LOCK_RELEASED
= 1009,
669 ABSOLUTE_LIMITS
= 1010,
679 UNTRACKED_PARAM
= 1023,
683 PARAM_COMPARE
= 1028,
685 /* put random temporary stuff in the 7000-7999 range for testing */
687 USER_DATA_SET
= 9018,
688 USER_DATA_LIMITED
= 9019,
691 void debug_sql(const char *sql
);
692 void debug_mem_sql(const char *sql
);
693 void select_caller_info_hook(void (*callback
)(const char *name
, struct symbol
*sym
, char *key
, char *value
), int type
);
694 void add_member_info_callback(int owner
, void (*callback
)(struct expression
*call
, int param
, char *printed_name
, struct sm_state
*sm
));
695 void add_split_return_callback(void (*fn
)(int return_id
, char *return_ranges
, struct expression
*returned_expr
));
696 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
));
697 void select_call_implies_hook(int type
, void (*callback
)(struct expression
*arg
, char *key
, char *value
));
698 struct range_list
*db_return_vals(struct expression
*expr
);
699 struct range_list
*db_return_vals_from_str(const char *fn_name
);
700 char *return_state_to_var_sym(struct expression
*expr
, int param
, char *key
, struct symbol
**sym
);
701 char *get_variable_from_key(struct expression
*arg
, char *key
, struct symbol
**sym
);
702 const char *get_param_name(struct sm_state
*sm
);
703 char *get_data_info_name(struct expression
*expr
);
705 #define run_sql(call_back, data, sql...) \
707 char sql_txt[1024]; \
710 snprintf(sql_txt, 1024, sql); \
711 debug_sql(sql_txt); \
712 sql_exec(call_back, data, sql_txt); \
715 /* like run_sql() but for the in-memory database */
716 #define mem_sql(call_back, data, sql...) \
718 char sql_txt[1024]; \
720 snprintf(sql_txt, sizeof(sql_txt), sql); \
721 sm_debug("in-mem: %s\n", sql_txt); \
722 debug_mem_sql(sql_txt); \
723 sql_mem_exec(call_back, data, sql_txt); \
726 char *get_static_filter(struct symbol
*sym
);
728 void sql_insert_return_states(int return_id
, const char *return_ranges
,
729 int type
, int param
, const char *key
, const char *value
);
730 void sql_insert_caller_info(struct expression
*call
, int type
, int param
,
731 const char *key
, const char *value
);
732 void sql_insert_function_ptr(const char *fn
, const char *struct_name
);
733 void sql_insert_return_values(const char *return_values
);
734 void sql_insert_call_implies(int type
, int param
, const char *key
, const char *value
);
735 void sql_insert_function_type_size(const char *member
, const char *ranges
);
736 void sql_insert_local_values(const char *name
, const char *value
);
737 void sql_insert_function_type_value(const char *type
, const char *value
);
738 void sql_insert_function_type_info(int param
, const char *value
);
739 void sql_insert_data_info(struct expression
*data
, int type
, const char *value
);
741 void sql_select_return_states(const char *cols
, struct expression
*call
,
742 int (*callback
)(void*, int, char**, char**), void *info
);
743 void sql_select_caller_info(const char *cols
, struct symbol
*sym
,
744 int (*callback
)(void*, int, char**, char**));
745 void sql_select_call_implies(const char *cols
, struct expression
*call
,
746 int (*callback
)(void*, int, char**, char**));
748 void sql_exec(int (*callback
)(void*, int, char**, char**), void *data
, const char *sql
);
749 void sql_mem_exec(int (*callback
)(void*, int, char**, char**), void *data
, const char *sql
);
751 void open_smatch_db(void);
754 int open_data_file(const char *filename
);
755 struct token
*get_tokens_file(const char *filename
);
758 extern char *option_debug_check
;
759 extern char *option_project_str
;
760 extern char *data_dir
;
761 extern int option_no_data
;
762 extern int option_spammy
;
763 extern int option_full_path
;
764 extern int option_param_mapper
;
765 extern int option_call_tree
;
766 extern int num_checks
;
773 extern enum project_type option_project
;
774 const char *check_name(unsigned short id
);
777 /* smatch_buf_size.c */
778 int get_array_size(struct expression
*expr
);
779 int get_array_size_bytes(struct expression
*expr
);
780 int get_array_size_bytes_min(struct expression
*expr
);
781 int get_array_size_bytes_max(struct expression
*expr
);
782 struct range_list
*get_array_size_bytes_rl(struct expression
*expr
);
783 int get_real_array_size(struct expression
*expr
);
784 /* smatch_strlen.c */
785 int get_implied_strlen(struct expression
*expr
, struct range_list
**rl
);
786 int get_size_from_strlen(struct expression
*expr
);
788 /* smatch_capped.c */
789 int is_capped(struct expression
*expr
);
790 int is_capped_var_sym(const char *name
, struct symbol
*sym
);
792 /* check_user_data.c */
793 int is_user_macro(struct expression
*expr
);
794 int is_user_data(struct expression
*expr
);
795 int is_capped_user_data(struct expression
*expr
);
796 int implied_user_data(struct expression
*expr
, struct range_list
**rl
);
797 int get_user_rl(struct expression
*expr
, struct range_list
**rl
);
798 int get_user_rl_var_sym(const char *name
, struct symbol
*sym
, struct range_list
**rl
);
800 /* check_locking.c */
801 void print_held_locks();
803 /* check_assigned_expr.c */
804 struct expression
*get_assigned_expr(struct expression
*expr
);
805 struct expression
*get_assigned_expr_name_sym(const char *name
, struct symbol
*sym
);
807 /* smatch_comparison.c */
808 struct compare_data
{
810 struct var_sym_list
*vsl1
;
813 struct var_sym_list
*vsl2
;
815 int get_comparison(struct expression
*left
, struct expression
*right
);
816 int get_comparison_strings(const char *one
, const char *two
);
817 int possible_comparison(struct expression
*a
, int comparison
, struct expression
*b
);
818 struct state_list
*get_all_comparisons(struct expression
*expr
);
819 struct state_list
*get_all_possible_equal_comparisons(struct expression
*expr
);
820 void __add_comparison_info(struct expression
*expr
, struct expression
*call
, const char *range
);
821 char *name_sym_to_param_comparison(const char *name
, struct symbol
*sym
);
822 char *expr_equal_to_param(struct expression
*expr
, int ignore
);
823 char *expr_lte_to_param(struct expression
*expr
, int ignore
);
824 char *expr_param_comparison(struct expression
*expr
, int ignore
);
825 int flip_comparison(int op
);
826 int negate_comparison(int op
);
827 void filter_by_comparison(struct range_list
**rl
, int comparison
, struct range_list
*right
);
828 struct sm_state
*comparison_implication_hook(struct expression
*expr
,
829 struct stree_stack
**true_stack
,
830 struct stree_stack
**false_stack
);
833 sval_t
*sval_alloc(sval_t sval
);
834 sval_t
*sval_alloc_permanent(sval_t sval
);
835 sval_t
sval_blank(struct expression
*expr
);
836 sval_t
sval_type_val(struct symbol
*type
, long long val
);
837 sval_t
sval_from_val(struct expression
*expr
, long long val
);
838 int sval_unsigned(sval_t sval
);
839 int sval_signed(sval_t sval
);
840 int sval_bits(sval_t sval
);
841 int sval_positive_bits(sval_t sval
);
842 int sval_bits_used(sval_t sval
);
843 int sval_is_negative(sval_t sval
);
844 int sval_is_positive(sval_t sval
);
845 int sval_is_min(sval_t sval
);
846 int sval_is_max(sval_t sval
);
847 int sval_is_a_min(sval_t sval
);
848 int sval_is_a_max(sval_t sval
);
849 int sval_is_negative_min(sval_t sval
);
850 int sval_cmp(sval_t one
, sval_t two
);
851 int sval_cmp_t(struct symbol
*type
, sval_t one
, sval_t two
);
852 int sval_cmp_val(sval_t one
, long long val
);
853 sval_t
sval_min(sval_t one
, sval_t two
);
854 sval_t
sval_max(sval_t one
, sval_t two
);
855 int sval_too_low(struct symbol
*type
, sval_t sval
);
856 int sval_too_high(struct symbol
*type
, sval_t sval
);
857 int sval_fits(struct symbol
*type
, sval_t sval
);
858 sval_t
sval_cast(struct symbol
*type
, sval_t sval
);
859 sval_t
sval_preop(sval_t sval
, int op
);
860 sval_t
sval_binop(sval_t left
, int op
, sval_t right
);
861 int sval_binop_overflows(sval_t left
, int op
, sval_t right
);
862 unsigned long long fls_mask(unsigned long long uvalue
);
863 unsigned long long sval_fls_mask(sval_t sval
);
864 const char *sval_to_str(sval_t sval
);
865 const char *sval_to_numstr(sval_t sval
);
866 sval_t
ll_to_sval(long long val
);
868 /* smatch_string_list.c */
869 int list_has_string(struct string_list
*str_list
, const char *str
);
870 void insert_string(struct string_list
**str_list
, const char *str
);
871 struct string_list
*clone_str_list(struct string_list
*orig
);
872 struct string_list
*combine_string_lists(struct string_list
*one
, struct string_list
*two
);
874 /* smatch_start_states.c */
875 struct stree
*get_start_states(void);
877 /* smatch_recurse.c */
878 int has_symbol(struct expression
*expr
, struct symbol
*sym
);
879 int has_variable(struct expression
*expr
, struct expression
*var
);
880 int has_inc_dec(struct expression
*expr
);
882 /* smatch_stored_conditions.c */
883 struct smatch_state
*get_stored_condition(struct expression
*expr
);
884 struct sm_state
*stored_condition_implication_hook(struct expression
*expr
,
885 struct stree_stack
**true_stack
,
886 struct stree_stack
**false_stack
);
888 /* check_string_len.c */
889 int get_formatted_string_size(struct expression
*call
, int arg
);
891 /* smatch_param_set.c */
892 int param_was_set(struct expression
*expr
);
893 /* smatch_param_filter.c */
894 int param_has_filter_data(struct sm_state
*sm
);
897 void set_up_link_functions(int id
, int linkid
);
898 struct smatch_state
*merge_link_states(struct smatch_state
*s1
, struct smatch_state
*s2
);
899 void store_link(int link_id
, const char *name
, struct symbol
*sym
, const char *link_name
, struct symbol
*link_sym
);
901 /* smatch_auto_copy.c */
902 void set_auto_copy(int owner
);
904 /* check_buf_comparison */
905 struct expression
*get_size_variable(struct expression
*buf
);
907 /* smatch_untracked_param.c */
908 void add_untracked_param_hook(void (func
)(struct expression
*call
, int param
));
910 /* smatch_impossible.c */
911 int is_impossible_path(void);
913 /* smatch_strings.c */
914 struct state_list
*get_strings(struct expression
*expr
);
916 /* smatch_estate.c */
917 int estate_get_single_value(struct smatch_state
*state
, sval_t
*sval
);
919 /* smatch_address.c */
920 int get_address_rl(struct expression
*expr
, struct range_list
**rl
);
921 int get_member_offset(struct symbol
*type
, char *member_name
);
922 int get_member_offset_from_deref(struct expression
*expr
);
924 /* for now this is in smatch_used_parameter.c */
925 void __get_state_hook(int owner
, const char *name
, struct symbol
*sym
);
927 /* smatch_buf_comparison.c */
928 int db_var_is_array_limit(struct expression
*array
, const char *name
, struct var_sym_list
*vsl
);
930 #endif /* !SMATCH_H_ */