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
31 #include "expression.h"
33 #include "smatch_constants.h"
35 typedef long long mtag_t
;
41 #define STATE(_x) static struct smatch_state _x = { .name = #_x }
42 extern struct smatch_state undefined
;
43 extern struct smatch_state merged
;
44 extern struct smatch_state true_state
;
45 extern struct smatch_state false_state
;
46 DECLARE_ALLOCATOR(smatch_state
);
48 static inline void *INT_PTR(int i
)
50 return (void *)(long)i
;
53 static inline int PTR_INT(void *p
)
63 DECLARE_ALLOCATOR(tracker
);
64 DECLARE_PTR_LIST(tracker_list
, struct tracker
);
65 DECLARE_PTR_LIST(stree_stack
, struct stree
);
67 /* The first 3 struct members must match struct tracker */
72 unsigned short merged
:1;
74 struct smatch_state
*state
;
76 struct sm_state
*left
;
77 struct sm_state
*right
;
78 struct state_list
*possible
;
85 DECLARE_ALLOCATOR(var_sym
);
86 DECLARE_PTR_LIST(var_sym_list
, struct var_sym
);
92 DECLARE_PTR_LIST(constraint_list
, struct constraint
);
98 extern struct alloc_info
*alloc_funcs
;
101 unsigned long long set
;
102 unsigned long long possible
;
113 DECLARATION_HOOK_AFTER
,
115 ASSIGNMENT_HOOK_AFTER
,
117 GLOBAL_ASSIGNMENT_HOOK
,
122 WHOLE_CONDITION_HOOK
,
123 FUNCTION_CALL_HOOK_BEFORE
,
125 CALL_HOOK_AFTER_INLINE
,
126 FUNCTION_CALL_HOOK_AFTER_DB
,
127 CALL_ASSIGNMENT_HOOK
,
128 MACRO_ASSIGNMENT_HOOK
,
153 void add_hook(void *func
, enum hook_type type
);
154 typedef struct smatch_state
*(merge_func_t
)(struct smatch_state
*s1
, struct smatch_state
*s2
);
155 typedef struct smatch_state
*(unmatched_func_t
)(struct sm_state
*state
);
156 void add_merge_hook(int client_id
, merge_func_t
*func
);
157 void add_unmatched_state_hook(int client_id
, unmatched_func_t
*func
);
158 void add_pre_merge_hook(int client_id
, void (*hook
)(struct sm_state
*cur
, struct sm_state
*other
));
159 typedef void (scope_hook
)(void *data
);
160 void add_scope_hook(scope_hook
*hook
, void *data
);
161 typedef void (param_key_hook
)(struct expression
*expr
, const char *name
, struct symbol
*sym
, void *data
);
162 typedef void (func_hook
)(const char *fn
, struct expression
*expr
, void *data
);
163 typedef void (implication_hook
)(const char *fn
, struct expression
*call_expr
,
164 struct expression
*assign_expr
, void *data
);
165 typedef void (return_implies_hook
)(struct expression
*call_expr
,
166 int param
, char *key
, char *value
);
167 typedef int (implied_return_hook
)(struct expression
*call_expr
, void *info
, struct range_list
**rl
);
168 void add_function_hook(const char *look_for
, func_hook
*call_back
, void *data
);
169 void add_function_hook_late(const char *look_for
, func_hook
*call_back
, void *info
);
171 void add_function_assign_hook(const char *look_for
, func_hook
*call_back
,
173 void register_func_hooks_from_file(const char *file
,
174 func_hook
*call_back
, void *info
);
175 void register_assign_hooks_from_file(const char *file
,
176 func_hook
*call_back
, void *info
);
177 void add_implied_return_hook(const char *look_for
,
178 implied_return_hook
*call_back
,
180 void add_macro_assign_hook(const char *look_for
, func_hook
*call_back
,
182 void add_macro_assign_hook_extra(const char *look_for
, func_hook
*call_back
,
184 void return_implies_state(const char *look_for
, long long start
, long long end
,
185 implication_hook
*call_back
, void *info
);
186 void return_implies_state_sval(const char *look_for
, sval_t start
, sval_t end
,
187 implication_hook
*call_back
, void *info
);
188 void return_implies_exact(const char *look_for
, sval_t start
, sval_t end
,
189 implication_hook
*call_back
, void *info
);
190 struct range_list
*get_range_implications(const char *fn
);
191 void select_return_states_hook(int type
, return_implies_hook
*callback
);
192 void select_return_states_before(void (*fn
)(void));
193 void select_return_states_after(void (*fn
)(void));
194 void add_function_param_key_hook(const char *look_for
, param_key_hook
*call_back
,
195 int param
, const char *key
, void *info
);
196 void add_function_param_key_hook_late(const char *look_for
, param_key_hook
*call_back
,
197 int param
, const char *key
, void *info
);
198 void return_implies_param_key(const char *look_for
, sval_t start
, sval_t end
,
199 param_key_hook
*call_back
,
200 int param
, const char *key
, void *info
);
201 void return_implies_param_key_exact(const char *look_for
, sval_t start
, sval_t end
,
202 param_key_hook
*call_back
,
203 int param
, const char *key
, void *info
);
204 void select_return_param_key(int type
, param_key_hook
*callback
);
205 int get_implied_return(struct expression
*expr
, struct range_list
**rl
);
206 void allocate_hook_memory(void);
207 void allocate_tracker_array(int num_checks
);
209 struct modification_data
{
210 struct smatch_state
*prev
;
211 struct expression
*cur
;
214 typedef void (modification_hook
)(struct sm_state
*sm
, struct expression
*mod_expr
);
215 bool is_sub_member(const char *name
, struct symbol
*sym
, struct sm_state
*sm
);
216 void add_modification_hook(int owner
, modification_hook
*call_back
);
217 void add_modification_hook_late(int owner
, modification_hook
*call_back
);
218 struct smatch_state
*get_modification_state(struct expression
*expr
);
220 int outside_of_function(void);
221 const char *get_filename(void);
222 const char *get_base_file(void);
223 char *get_function(void);
224 int get_lineno(void);
225 extern int final_pass
;
226 extern struct symbol
*cur_func_sym
;
227 extern int option_debug
;
228 extern int local_debug
;
230 extern bool implied_debug
;
231 bool debug_implied(void);
232 bool debug_on(const char *check_name
, const char *var
);
233 extern int option_info
;
234 extern int option_spammy
;
235 extern int option_pedantic
;
236 extern int option_print_names
;
237 extern char *trace_variable
;
238 extern struct stree
*global_states
;
239 void set_function_skipped(void);
240 int is_skipped_function(void);
241 int is_silenced_function(void);
242 extern bool implications_off
;
244 /* smatch_impossible.c */
245 int is_impossible_path(void);
246 void set_path_impossible(void);
248 extern FILE *sm_outfd
;
249 extern FILE *sql_outfd
;
250 extern FILE *caller_info_fd
;
251 extern int sm_nr_checks
;
252 extern int sm_nr_errors
;
255 * How to use these routines:
257 * sm_fatal(): an internal error of some kind that should immediately exit
258 * sm_ierror(): an internal error
259 * sm_perror(): an internal error from parsing input source
260 * sm_error(): an error from input source
261 * sm_warning(): a warning from input source
262 * sm_info(): info message (from option_info)
263 * sm_debug(): debug message
264 * sm_msg(): other message (please avoid using this)
267 #define sm_printf(msg...) do { \
268 if (final_pass || option_debug || local_debug || debug_db) \
269 fprintf(sm_outfd, msg); \
272 static inline void sm_prefix(void)
274 sm_printf("%s:%d %s() ", get_filename(), get_lineno(), get_function());
275 if (option_info
|| !option_print_names
)
277 sm_printf("[smatch.%s] ", __CHECKNAME__
);
280 static inline void print_implied_debug_msg();
282 extern bool __silence_warnings_for_stmt
;
284 #define sm_print_msg(type, msg...) \
286 print_implied_debug_msg(); \
287 if (!final_pass && !option_debug && !local_debug && !debug_db) \
289 if (__silence_warnings_for_stmt && !option_debug && !local_debug) \
291 if (!option_info && is_silenced_function()) \
295 sm_printf("warn: "); \
297 } else if (type == 2) { \
298 sm_printf("error: "); \
300 } else if (type == 3) { \
301 sm_printf("parse error: "); \
308 #define sm_msg(msg...) do { sm_print_msg(0, msg); } while (0)
310 extern char *implied_debug_msg
;
311 static inline void print_implied_debug_msg(void)
313 static struct symbol
*last_printed
= NULL
;
315 if (!implied_debug_msg
)
317 if (last_printed
== cur_func_sym
)
319 last_printed
= cur_func_sym
;
320 sm_msg("%s", implied_debug_msg
);
323 #define sm_debug(msg...) do { if (option_debug) sm_printf(msg); } while (0)
324 #define db_debug(msg...) do { if (option_debug || debug_db) sm_printf(msg); } while (0)
326 #define sm_info(msg...) do { \
327 if (option_debug || (option_info && final_pass)) { \
329 sm_printf("info: "); \
335 #define sm_warning(msg...) do { sm_print_msg(1, msg); } while (0)
336 #define sm_warning_line(line, msg...) do { \
337 int __orig = __smatch_lineno; \
338 __smatch_lineno = line; \
339 sm_print_msg(1, msg); \
340 __smatch_lineno = __orig; \
342 #define sm_error(msg...) do { sm_print_msg(2, msg); } while (0)
343 #define sm_perror(msg...) do { sm_print_msg(3, msg); } while (0)
344 #define sm_spam(msg...) do { if (option_pedantic) sm_print_msg(1, msg); } while (0)
346 static inline void sm_fatal(const char *fmt
, ...)
351 vfprintf(sm_outfd
, fmt
, args
);
354 fprintf(sm_outfd
, "\n");
359 static inline void sm_ierror(const char *fmt
, ...)
365 fprintf(sm_outfd
, "internal error: ");
368 vfprintf(sm_outfd
, fmt
, args
);
371 fprintf(sm_outfd
, "\n");
373 #define ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1))
375 bool has_states(struct stree
*stree
, int owner
);
376 struct smatch_state
*__get_state(int owner
, const char *name
, struct symbol
*sym
);
377 struct smatch_state
*get_state(int owner
, const char *name
, struct symbol
*sym
);
378 struct smatch_state
*get_state_expr(int owner
, struct expression
*expr
);
379 bool has_possible_state(int owner
, const char *name
, struct symbol
*sym
, struct smatch_state
*state
);
380 bool expr_has_possible_state(int owner
, struct expression
*expr
, struct smatch_state
*state
);
381 struct state_list
*get_possible_states(int owner
, const char *name
,
383 struct state_list
*get_possible_states_expr(int owner
, struct expression
*expr
);
384 struct sm_state
*set_state(int owner
, const char *name
, struct symbol
*sym
,
385 struct smatch_state
*state
);
386 struct sm_state
*set_state_expr(int owner
, struct expression
*expr
,
387 struct smatch_state
*state
);
388 void __delete_state(int owner
, const char *name
, struct symbol
*sym
);
389 void __delete_all_states_sym(struct symbol
*sym
);
390 void set_true_false_states(int owner
, const char *name
, struct symbol
*sym
,
391 struct smatch_state
*true_state
,
392 struct smatch_state
*false_state
);
393 void set_true_false_states_expr(int owner
, struct expression
*expr
,
394 struct smatch_state
*true_state
,
395 struct smatch_state
*false_state
);
397 struct stree
*get_all_states_from_stree(int owner
, struct stree
*source
);
398 struct stree
*get_all_states_stree(int id
);
399 struct stree
*__get_cur_stree(void);
400 int is_reachable(void);
401 void add_get_state_hook(void (*fn
)(int owner
, const char *name
, struct symbol
*sym
));
404 char *ssa_name(const char *name
);
405 void set_ssa_state(int owner
, const char *name
, struct symbol
*sym
, struct smatch_state
*state
);
406 void update_ssa_state(int owner
, const char *name
, struct symbol
*sym
,
407 struct smatch_state
*state
);
408 void set_ssa_state_expr(int owner
, struct expression
*expr
, struct smatch_state
*state
);
409 struct sm_state
*get_ssa_sm_state(int owner
, const char *name
, struct symbol
*sym
);
410 struct sm_state
*get_ssa_sm_state_expr(int owner
, struct expression
*expr
);
411 struct smatch_state
*get_ssa_state(int owner
, const char *name
, struct symbol
*sym
);
412 struct smatch_state
*get_ssa_state_expr(int owner
, struct expression
*expr
);
414 /* smatch_helper.c */
415 DECLARE_PTR_LIST(int_stack
, int);
416 char *alloc_string(const char *str
);
417 char *alloc_string_newline(const char *str
);
418 void free_string(char *str
);
419 void remove_parens(char *str
);
420 struct smatch_state
*alloc_state_num(int num
);
421 struct smatch_state
*alloc_state_str(const char *name
);
422 struct smatch_state
*merge_str_state(struct smatch_state
*s1
, struct smatch_state
*s2
);
423 struct smatch_state
*alloc_state_expr(struct expression
*expr
);
424 struct expression
*get_argument_from_call_expr(struct expression_list
*args
,
426 struct expression
*get_array_expr(struct expression
*expr
);
428 char *expr_to_var(struct expression
*expr
);
429 struct symbol
*expr_to_sym(struct expression
*expr
);
430 char *expr_to_str(struct expression
*expr
);
431 char *expr_to_str_sym(struct expression
*expr
,
432 struct symbol
**sym_ptr
);
433 char *expr_to_var_sym(struct expression
*expr
,
434 struct symbol
**sym_ptr
);
435 char *expr_to_known_chunk_sym(struct expression
*expr
, struct symbol
**sym
);
436 char *expr_to_chunk_sym_vsl(struct expression
*expr
, struct symbol
**sym
, struct var_sym_list
**vsl
);
437 int get_complication_score(struct expression
*expr
);
439 int sym_name_is(const char *name
, struct expression
*expr
);
440 int get_const_value(struct expression
*expr
, sval_t
*sval
);
441 int get_value(struct expression
*expr
, sval_t
*val
);
442 int get_implied_value(struct expression
*expr
, sval_t
*val
);
443 int get_implied_value_fast(struct expression
*expr
, sval_t
*sval
);
444 int get_implied_min(struct expression
*expr
, sval_t
*sval
);
445 int get_implied_max(struct expression
*expr
, sval_t
*val
);
446 int get_hard_max(struct expression
*expr
, sval_t
*sval
);
447 int get_fuzzy_min(struct expression
*expr
, sval_t
*min
);
448 int get_fuzzy_max(struct expression
*expr
, sval_t
*max
);
449 int get_absolute_min(struct expression
*expr
, sval_t
*sval
);
450 int get_absolute_max(struct expression
*expr
, sval_t
*sval
);
451 int parse_call_math(struct expression
*expr
, char *math
, sval_t
*val
);
452 int parse_call_math_rl(struct expression
*call
, const char *math
, struct range_list
**rl
);
453 const char *get_allocation_math(struct expression
*expr
);
454 char *get_value_in_terms_of_parameter_math(struct expression
*expr
);
455 char *get_value_in_terms_of_parameter_math_var_sym(const char *var
, struct symbol
*sym
);
456 int expr_is_zero(struct expression
*expr
);
457 int known_condition_true(struct expression
*expr
);
458 int known_condition_false(struct expression
*expr
);
459 int implied_condition_true(struct expression
*expr
);
460 int implied_condition_false(struct expression
*expr
);
461 int can_integer_overflow(struct symbol
*type
, struct expression
*expr
);
462 void clear_math_cache(void);
463 void set_fast_math_only(void);
464 void clear_fast_math_only(void);
466 int is_array(struct expression
*expr
);
467 struct expression
*get_array_base(struct expression
*expr
);
468 struct expression
*get_array_offset(struct expression
*expr
);
469 const char *show_state(struct smatch_state
*state
);
470 struct statement
*get_expression_statement(struct expression
*expr
);
471 struct expression
*strip_parens(struct expression
*expr
);
472 struct expression
*strip_expr(struct expression
*expr
);
473 struct expression
*strip_expr_set_parent(struct expression
*expr
);
474 void scoped_state(int my_id
, const char *name
, struct symbol
*sym
);
475 int is_error_return(struct expression
*expr
);
476 int getting_address(struct expression
*expr
);
477 int get_struct_and_member(struct expression
*expr
, const char **type
, const char **member
);
478 char *get_member_name(struct expression
*expr
);
479 char *get_fnptr_name(struct expression
*expr
);
480 int cmp_pos(struct position pos1
, struct position pos2
);
481 int positions_eq(struct position pos1
, struct position pos2
);
482 struct statement
*get_current_statement(void);
483 struct statement
*get_prev_statement(void);
484 struct expression
*get_last_expr_from_expression_stmt(struct expression
*expr
);
486 #define RETURN_VAR -1
487 #define LOCAL_SCOPE -2
488 #define FILE_SCOPE -3
489 #define GLOBAL_SCOPE -4
490 #define UNKNOWN_SCOPE -5
492 char *swap_names(const char *orig
, const char *remove
, const char *add
);
493 char *get_param_var_sym_var_sym(const char *name
, struct symbol
*sym
, struct expression
*ret_expr
, struct symbol
**sym_p
);
494 char *get_param_name_sym(struct expression
*expr
, struct symbol
**sym_p
);
495 int get_param_key_from_var_sym(const char *name
, struct symbol
*sym
,
496 struct expression
*ret_expr
,
498 int get_param_key_from_sm(struct sm_state
*sm
, struct expression
*ret_expr
,
500 int map_to_param(const char *name
, struct symbol
*sym
);
501 int get_param_num_from_sym(struct symbol
*sym
);
502 int get_param_num(struct expression
*expr
);
503 struct symbol
*get_param_sym_from_num(int num
);
505 int ms_since(struct timeval
*start
);
506 int parent_is_gone_var_sym(const char *name
, struct symbol
*sym
);
507 int parent_is_gone(struct expression
*expr
);
508 bool is_noderef_ptr(struct expression
*expr
);
509 int invert_op(int op
);
510 int op_remove_assign(int op
);
511 int expr_equiv(struct expression
*one
, struct expression
*two
);
512 void push_int(struct int_stack
**stack
, int num
);
513 int pop_int(struct int_stack
**stack
);
516 struct symbol
*get_real_base_type(struct symbol
*sym
);
517 int type_bytes(struct symbol
*type
);
518 int array_bytes(struct symbol
*type
);
519 struct symbol
*get_pointer_type(struct expression
*expr
);
520 struct symbol
*get_type(struct expression
*expr
);
521 struct symbol
*get_comparison_type(struct expression
*expr
);
522 struct symbol
*get_final_type(struct expression
*expr
);
523 struct symbol
*get_promoted_type(struct symbol
*left
, struct symbol
*right
);
524 int type_signed(struct symbol
*base_type
);
525 int expr_unsigned(struct expression
*expr
);
526 int expr_signed(struct expression
*expr
);
527 int returns_unsigned(struct symbol
*base_type
);
528 int is_pointer(struct expression
*expr
);
529 int returns_pointer(struct symbol
*base_type
);
530 sval_t
sval_type_max(struct symbol
*base_type
);
531 sval_t
sval_type_min(struct symbol
*base_type
);
532 int nr_bits(struct expression
*expr
);
533 int is_void_pointer(struct expression
*expr
);
534 int is_char_pointer(struct expression
*expr
);
535 int is_string(struct expression
*expr
);
536 bool is_struct_ptr(struct symbol
*type
);
537 int is_static(struct expression
*expr
);
538 bool is_local_variable(struct expression
*expr
);
539 int types_equiv(struct symbol
*one
, struct symbol
*two
);
540 bool type_fits(struct symbol
*type
, struct symbol
*test
);
542 const char *global_static();
543 struct symbol
*cur_func_return_type(void);
544 struct symbol
*get_arg_type(struct expression
*fn
, int arg
);
545 struct symbol
*get_member_type_from_key(struct expression
*expr
, const char *key
);
546 struct symbol
*get_arg_type_from_key(struct expression
*fn
, int param
, struct expression
*arg
, const char *key
);
547 int is_struct(struct expression
*expr
);
548 char *type_to_str(struct symbol
*type
);
550 /* smatch_ignore.c */
551 void add_ignore(int owner
, const char *name
, struct symbol
*sym
);
552 int is_ignored(int owner
, const char *name
, struct symbol
*sym
);
553 void add_ignore_expr(int owner
, struct expression
*expr
);
554 int is_ignored_expr(int owner
, struct expression
*expr
);
557 struct smatch_state
*alloc_var_sym_state(const char *var
, struct symbol
*sym
);
558 struct var_sym
*alloc_var_sym(const char *var
, struct symbol
*sym
);
559 struct var_sym_list
*expr_to_vsl(struct expression
*expr
);
560 void add_var_sym(struct var_sym_list
**list
, const char *var
, struct symbol
*sym
);
561 void add_var_sym_expr(struct var_sym_list
**list
, struct expression
*expr
);
562 void del_var_sym(struct var_sym_list
**list
, const char *var
, struct symbol
*sym
);
563 int in_var_sym_list(struct var_sym_list
*list
, const char *var
, struct symbol
*sym
);
564 struct var_sym_list
*clone_var_sym_list(struct var_sym_list
*from_vsl
);
565 void merge_var_sym_list(struct var_sym_list
**dest
, struct var_sym_list
*src
);
566 struct var_sym_list
*combine_var_sym_lists(struct var_sym_list
*one
, struct var_sym_list
*two
);
567 int var_sym_lists_equiv(struct var_sym_list
*one
, struct var_sym_list
*two
);
568 void free_var_sym_list(struct var_sym_list
**list
);
569 void free_var_syms_and_list(struct var_sym_list
**list
);
572 struct tracker
*alloc_tracker(int owner
, const char *name
, struct symbol
*sym
);
573 void add_tracker(struct tracker_list
**list
, int owner
, const char *name
,
575 void add_tracker_expr(struct tracker_list
**list
, int owner
, struct expression
*expr
);
576 void del_tracker(struct tracker_list
**list
, int owner
, const char *name
,
578 int in_tracker_list(struct tracker_list
*list
, int owner
, const char *name
,
580 void free_tracker_list(struct tracker_list
**list
);
581 void free_trackers_and_list(struct tracker_list
**list
);
583 /* smatch_conditions */
584 int in_condition(void);
588 extern int __in_fake_assign
;
589 extern int __in_fake_parameter_assign
;
590 extern int __in_fake_struct_assign
;
591 extern int __in_fake_var_assign
;
592 extern int __fake_state_cnt
;
593 extern int in_fake_env
;
594 void smatch (struct string_list
*filelist
);
595 int inside_loop(void);
596 int definitely_inside_loop(void);
597 struct expression
*get_switch_expr(void);
598 int in_expression_statement(void);
599 void __process_post_op_stack(void);
600 void __split_expr(struct expression
*expr
);
601 void __split_label_stmt(struct statement
*stmt
);
602 void __split_stmt(struct statement
*stmt
);
603 extern int __in_function_def
;
604 extern int __in_unmatched_hook
;
605 extern int option_assume_loops
;
606 extern int option_two_passes
;
607 extern int option_no_db
;
608 extern int option_file_output
;
609 extern int option_time
;
610 extern int option_time_stmt
;
611 extern struct expression_list
*big_expression_stack
;
612 extern struct expression_list
*big_condition_stack
;
613 extern struct statement_list
*big_statement_stack
;
614 int is_assigned_call(struct expression
*expr
);
615 int is_fake_assigned_call(struct expression
*expr
);
616 void add_function_data(unsigned long *fn_data
);
617 int inlinable(struct expression
*expr
);
618 extern int __inline_call
;
619 extern struct expression
*__inline_fn
;
620 extern int __in_pre_condition
;
621 extern int __bail_on_rest_of_function
;
622 extern struct statement
*__prev_stmt
;
623 extern struct statement
*__cur_stmt
;
624 extern struct statement
*__next_stmt
;
625 void init_fake_env(void);
626 void end_fake_env(void);
627 int time_parsing_function(void);
628 bool taking_too_long(void);
629 struct statement
*get_last_stmt(void);
630 int is_last_stmt(struct statement
*cur_stmt
);
632 /* smatch_struct_assignment.c */
633 struct expression
*get_faked_expression(void);
634 void __fake_struct_member_assignments(struct expression
*expr
);
636 /* smatch_project.c */
637 int is_no_inline_function(const char *function
);
639 /* smatch_conditions */
640 void __split_whole_condition(struct expression
*expr
);
641 void __handle_logic(struct expression
*expr
);
642 int is_condition(struct expression
*expr
);
643 int __handle_condition_assigns(struct expression
*expr
);
644 int __handle_select_assigns(struct expression
*expr
);
645 int __handle_expr_statement_assigns(struct expression
*expr
);
647 /* smatch_implied.c */
648 struct range_list_stack
;
649 void param_limit_implications(struct expression
*expr
, int param
, char *key
, char *value
, struct stree
**implied
);
650 struct stree
*__implied_case_stree(struct expression
*switch_expr
,
651 struct range_list
*case_rl
,
652 struct range_list_stack
**remaining_cases
,
653 struct stree
**raw_stree
);
654 void overwrite_states_using_pool(struct sm_state
*gate_sm
, struct sm_state
*pool_sm
);
655 int assume(struct expression
*expr
);
656 void end_assume(void);
657 int impossible_assumption(struct expression
*left
, int op
, sval_t sval
);
660 bool has_dynamic_states(unsigned short owner
);
661 void set_dynamic_states(unsigned short owner
);
663 /* smatch_extras.c */
664 int in_warn_on_macro(void);
665 #define SMATCH_EXTRA 5 /* this is my_id from smatch extra set in smatch.c */
666 extern int RETURN_ID
;
673 char *get_other_name_sym(const char *name
, struct symbol
*sym
, struct symbol
**new_sym
);
674 char *map_call_to_other_name_sym(const char *name
, struct symbol
*sym
, struct symbol
**new_sym
);
675 char *map_long_to_short_name_sym(const char *name
, struct symbol
*sym
, struct symbol
**new_sym
, bool use_stack
);
677 #define STRLEN_MAX_RET 1010101
679 /* smatch_absolute.c */
680 int get_absolute_min_helper(struct expression
*expr
, sval_t
*sval
);
681 int get_absolute_max_helper(struct expression
*expr
, sval_t
*sval
);
683 /* smatch_type_value.c */
684 void clear_type_value_cache(void);
685 int get_db_type_rl(struct expression
*expr
, struct range_list
**rl
);
687 /* smatch_data_val.c */
688 int get_mtag_rl(struct expression
*expr
, struct range_list
**rl
);
689 /* smatch_array_values.c */
690 int get_array_rl(struct expression
*expr
, struct range_list
**rl
);
692 /* smatch_states.c */
693 struct stree
*__swap_cur_stree(struct stree
*stree
);
694 void __push_fake_cur_stree();
695 struct stree
*__pop_fake_cur_stree();
696 void __free_fake_cur_stree();
697 void __set_fake_cur_stree_fast(struct stree
*stree
);
698 void __pop_fake_cur_stree_fast(void);
699 void __merge_stree_into_cur(struct stree
*stree
);
701 int unreachable(void);
702 void __set_cur_stree_readonly(void);
703 void __set_cur_stree_writable(void);
704 void __set_sm(struct sm_state
*sm
);
705 void __set_sm_cur_stree(struct sm_state
*sm
);
706 void __set_true_false_sm(struct sm_state
*true_state
,
707 struct sm_state
*false_state
);
708 void nullify_path(void);
709 void __match_nullify_path_hook(const char *fn
, struct expression
*expr
,
711 void __unnullify_path(void);
712 int __path_is_null(void);
713 void save_all_states(void);
714 void restore_all_states(void);
715 void free_goto_stack(void);
716 void clear_all_states(void);
718 struct sm_state
*get_sm_state(int owner
, const char *name
,
720 struct sm_state
*get_sm_state_expr(int owner
, struct expression
*expr
);
721 void __push_true_states(void);
722 void __use_false_states(void);
723 void __discard_false_states(void);
724 void __merge_false_states(void);
725 void __merge_true_states(void);
727 void __negate_cond_stacks(void);
728 void __use_pre_cond_states(void);
729 void __use_cond_true_states(void);
730 void __use_cond_false_states(void);
731 void __push_cond_stacks(void);
732 void __fold_in_set_states(void);
733 void __free_set_states(void);
734 struct stree
*__copy_cond_true_states(void);
735 struct stree
*__copy_cond_false_states(void);
736 struct stree
*__pop_cond_true_stack(void);
737 struct stree
*__pop_cond_false_stack(void);
738 void __and_cond_states(void);
739 void __or_cond_states(void);
740 void __save_pre_cond_states(void);
741 void __discard_pre_cond_states(void);
742 struct stree
*__get_true_states(void);
743 struct stree
*__get_false_states(void);
744 void __use_cond_states(void);
745 extern struct state_list
*__last_base_slist
;
747 void __push_continues(void);
748 void __discard_continues(void);
749 void __process_continues(void);
750 void __merge_continues(void);
752 void __push_breaks(void);
753 void __process_breaks(void);
754 int __has_breaks(void);
755 void __merge_breaks(void);
756 void __use_breaks(void);
758 void __save_switch_states(struct expression
*switch_expr
);
759 void __discard_switches(void);
760 int have_remaining_cases(void);
761 void __merge_switches(struct expression
*switch_expr
, struct range_list
*case_rl
);
762 void __push_default(void);
763 void __set_default(void);
764 int __pop_default(void);
766 void __push_conditions(void);
767 void __discard_conditions(void);
769 void __save_gotos(const char *name
, struct symbol
*sym
);
770 void __merge_gotos(const char *name
, struct symbol
*sym
);
772 void __discard_fake_states(struct expression
*call
);
774 void __print_cur_stree(void);
775 bool __print_states(const char *owner
);
776 typedef void (check_tracker_hook
)(int owner
, const char *name
, struct symbol
*sym
, struct smatch_state
*state
);
777 void add_check_tracker(const char *check_name
, check_tracker_hook
*fn
);
780 void __pass_to_client(void *data
, enum hook_type type
);
781 void __pass_case_to_client(struct expression
*switch_expr
,
782 struct range_list
*rl
);
783 int __has_merge_function(int client_id
);
784 struct smatch_state
*__client_merge_function(int owner
,
785 struct smatch_state
*s1
,
786 struct smatch_state
*s2
);
787 struct smatch_state
*__client_unmatched_state_function(struct sm_state
*sm
);
788 void call_pre_merge_hook(struct sm_state
*cur
, struct sm_state
*other
);
789 void __push_scope_hooks(void);
790 void __call_scope_hooks(void);
791 void add_array_initialized_hook(void (*hook
)(struct expression
*array
, int nr
));
792 void __call_array_initialized_hooks(struct expression
*array
, int nr
);
794 /* smatch_function_hooks.c */
795 void create_function_hook_hash(void);
796 void __match_initializer_call(struct symbol
*sym
);
802 * Changing these numbers is a pain. Don't do it. If you ever use a
803 * number it can't be re-used right away so there may be gaps.
804 * We select these in order by type so if the order matters, then give
805 * it a number below 100-999,9000-9999 ranges. */
817 ABSOLUTE_LIMITS
= 1010,
831 UNTRACKED_PARAM
= 1023,
837 COMPARE_LIMIT
= 1028,
838 PARAM_COMPARE
= 1029,
841 CONSTRAINT_REQUIRED
= 1033,
851 /* put random temporary stuff in the 7000-7999 range for testing */
853 USER_DATA_SET
= 9017,
857 NO_OVERFLOW_SIMPLE
= 8019,
863 KNOWN_UNLOCKED
= 9025,
869 NO_SIDE_EFFECT
= 8025,
872 ARRAYSIZE_ARG
= 8033,
887 extern struct sqlite3
*smatch_db
;
888 extern struct sqlite3
*mem_db
;
889 extern struct sqlite3
*cache_db
;
891 bool db_incomplete(void);
892 void db_ignore_states(int id
);
893 typedef bool (delete_hook
)(struct expression
*expr
);
894 void add_delete_return_hook(delete_hook
*hook
);
895 void select_caller_info_hook(void (*callback
)(const char *name
, struct symbol
*sym
, char *key
, char *value
), int type
);
896 void select_caller_name_sym(void (*fn
)(const char *name
, struct symbol
*sym
, char *value
), int type
);
897 void add_member_info_callback(int owner
, void (*callback
)(struct expression
*call
, int param
, char *printed_name
, struct sm_state
*sm
));
898 void add_caller_info_callback(int owner
, void (*callback
)(struct expression
*call
, int param
, char *printed_name
, struct sm_state
*sm
));
899 void add_return_info_callback(int owner
,
900 void (*callback
)(int return_id
, char *return_ranges
,
901 struct expression
*returned_expr
,
903 const char *printed_name
,
904 struct sm_state
*sm
));
905 void add_split_return_callback(void (*fn
)(int return_id
, char *return_ranges
, struct expression
*returned_expr
));
906 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
));
907 void select_call_implies_hook(int type
, void (*callback
)(struct expression
*call
, struct expression
*arg
, char *key
, char *value
));
908 void select_return_implies_hook(int type
, void (*callback
)(struct expression
*call
, struct expression
*arg
, char *key
, char *value
));
909 struct range_list
*db_return_vals(struct expression
*expr
);
910 struct range_list
*db_return_vals_from_str(const char *fn_name
);
911 struct range_list
*db_return_vals_no_args(struct expression
*expr
);
912 char *get_chunk_from_key(struct expression
*arg
, char *key
, struct symbol
**sym
, struct var_sym_list
**vsl
);
913 char *get_variable_from_key(struct expression
*arg
, const char *key
, struct symbol
**sym
);
914 char *get_name_sym_from_key(struct expression
*expr
, int param
, const char *key
, struct symbol
**sym
);
915 char *get_param_name_var_sym(const char *name
, struct symbol
*sym
);
916 char *get_param_name(struct sm_state
*sm
);
917 const char *get_mtag_name_var_sym(const char *state_name
, struct symbol
*sym
);
918 const char *get_mtag_name_expr(struct expression
*expr
);
919 char *get_data_info_name(struct expression
*expr
);
920 char *sm_to_arg_name(struct expression
*expr
, struct sm_state
*sm
);
921 int is_recursive_member(const char *param_name
);
923 char *escape_newlines(const char *str
);
924 void sql_exec(struct sqlite3
*db
, int (*callback
)(void*, int, char**, char**), void *data
, const char *sql
);
926 #define sql_helper(db, call_back, data, sql...) \
928 char sql_txt[1024]; \
930 sqlite3_snprintf(sizeof(sql_txt), sql_txt, sql); \
931 db_debug("debug: %s\n", sql_txt); \
932 sql_exec(db, call_back, data, sql_txt); \
936 #define run_sql(call_back, data, sql...) \
940 sql_helper(smatch_db, call_back, data, sql); \
943 #define mem_sql(call_back, data, sql...) \
944 sql_helper(mem_db, call_back, data, sql)
946 #define cache_sql(call_back, data, sql...) \
947 sql_helper(cache_db, call_back, data, sql)
949 #define sql_insert_helper(table, db, ignore, late, values...) \
951 struct sqlite3 *_db = db; \
953 if (__inline_fn && !_db) \
957 char *err, *p = buf; \
960 p += snprintf(p, buf + sizeof(buf) - p, \
961 "insert %sinto %s values (", \
962 ignore ? "or ignore " : "", #table); \
963 p += snprintf(p, buf + sizeof(buf) - p, values); \
964 p += snprintf(p, buf + sizeof(buf) - p, ");"); \
965 db_debug("mem-db: %s\n", buf); \
966 rc = sqlite3_exec(_db, buf, NULL, NULL, &err); \
967 if (rc != SQLITE_OK) { \
968 sm_ierror("SQL error #2: %s", err); \
969 sm_ierror("SQL: '%s'", buf); \
975 FILE *tmp_fd = sm_outfd; \
976 sm_outfd = sql_outfd; \
978 sm_printf("SQL%s: insert %sinto " #table " values(", \
979 late ? "_late" : "", ignore ? "or ignore " : ""); \
986 #define sql_insert(table, values...) sql_insert_helper(table, 0, 0, 0, values);
987 #define sql_insert_or_ignore(table, values...) sql_insert_helper(table, 0, 1, 0, values);
988 #define sql_insert_late(table, values...) sql_insert_helper(table, 0, 0, 1, values);
989 #define sql_insert_cache(table, values...) sql_insert_helper(table, cache_db, 1, 0, values);
991 char *get_static_filter(struct symbol
*sym
);
993 void sql_insert_return_states(int return_id
, const char *return_ranges
,
994 int type
, int param
, const char *key
, const char *value
);
995 void sql_insert_caller_info(struct expression
*call
, int type
, int param
,
996 const char *key
, const char *value
);
997 void sql_insert_function_ptr(const char *fn
, const char *struct_name
);
998 void sql_insert_return_values(const char *return_values
);
999 void sql_insert_return_implies(int type
, int param
, const char *key
, const char *value
);
1000 void sql_insert_function_type_size(const char *member
, const char *ranges
);
1001 void sql_insert_function_type_info(int type
, const char *struct_type
, const char *member
, const char *value
);
1002 void sql_insert_type_info(int type
, const char *member
, const char *value
);
1003 void sql_insert_local_values(const char *name
, const char *value
);
1004 void sql_insert_function_type_value(const char *type
, const char *value
);
1005 void sql_insert_function_type(int param
, const char *value
);
1006 void sql_insert_parameter_name(int param
, const char *value
);
1007 void sql_insert_data_info(struct expression
*data
, int type
, const char *value
);
1008 void sql_insert_data_info_var_sym(const char *var
, struct symbol
*sym
, int type
, const char *value
);
1009 void sql_save_constraint(const char *con
);
1010 void sql_save_constraint_required(const char *data
, int op
, const char *limit
);
1011 void sql_copy_constraint_required(const char *new_limit
, const char *old_limit
);
1012 void sql_insert_fn_ptr_data_link(const char *ptr
, const char *data
);
1013 void sql_insert_fn_data_link(struct expression
*fn
, int type
, int param
, const char *key
, const char *value
);
1014 void sql_insert_mtag_about(mtag_t tag
, const char *left_name
, const char *right_name
);
1015 void sql_insert_mtag_info(mtag_t tag
, int type
, const char *value
);
1016 void sql_insert_mtag_map(mtag_t container
, int container_offset
, mtag_t tag
, int tag_offset
);
1017 void sql_insert_mtag_alias(mtag_t orig
, mtag_t alias
);
1018 int mtag_map_select_container(mtag_t tag
, int container_offset
, mtag_t
*container
);
1019 int mtag_map_select_tag(mtag_t container
, int offset
, mtag_t
*tag
);
1020 struct smatch_state
*get_mtag_return(struct expression
*expr
, struct smatch_state
*state
);
1021 struct range_list
*swap_mtag_seed(struct expression
*expr
, struct range_list
*rl
);
1023 bool is_fn_ptr(struct expression
*fn
);
1024 void sql_select_return_states(const char *cols
, struct expression
*call
,
1025 int (*callback
)(void*, int, char**, char**), void *info
);
1026 void sql_select_call_implies(const char *cols
, struct expression
*call
,
1027 int (*callback
)(void*, int, char**, char**));
1029 void open_smatch_db(char *db_file
);
1031 /* smatch_files.c */
1032 int open_data_file(const char *filename
);
1033 int open_schema_file(const char *schema
);
1034 struct token
*get_tokens_file(const char *filename
);
1035 struct string_list
*load_strings_from_file(const char *project
, const char *filename
);
1038 extern char *option_debug_check
;
1039 extern char *option_debug_var
;
1040 extern char *option_project_str
;
1041 extern char *bin_dir
;
1042 extern char *data_dir
;
1043 extern int option_no_data
;
1044 extern int option_full_path
;
1045 extern int option_call_tree
;
1046 extern int num_checks
;
1052 PROJ_ILLUMOS_KERNEL
,
1056 extern enum project_type option_project
;
1057 const char *check_name(unsigned short id
);
1058 int id_from_name(const char *name
);
1061 /* smatch_buf_size.c */
1062 int get_array_size(struct expression
*expr
);
1063 int get_array_size_bytes(struct expression
*expr
);
1064 int get_array_size_bytes_min(struct expression
*expr
);
1065 int get_array_size_bytes_max(struct expression
*expr
);
1066 struct range_list
*get_array_size_bytes_rl(struct expression
*expr
);
1067 int get_real_array_size(struct expression
*expr
);
1068 int last_member_is_resizable(struct symbol
*type
);
1069 /* smatch_strlen.c */
1070 int get_implied_strlen(struct expression
*expr
, struct range_list
**rl
);
1071 int get_size_from_strlen(struct expression
*expr
);
1073 /* smatch_capped.c */
1074 int is_capped(struct expression
*expr
);
1075 int is_capped_var_sym(const char *name
, struct symbol
*sym
);
1077 /* smatch_kernel_user_data.c */
1078 int is_user_macro(struct expression
*expr
);
1079 int is_capped_user_data(struct expression
*expr
);
1080 int implied_user_data(struct expression
*expr
, struct range_list
**rl
);
1081 struct stree
*get_user_stree(void);
1082 int get_user_rl(struct expression
*expr
, struct range_list
**rl
);
1083 int is_user_rl(struct expression
*expr
);
1084 int get_user_rl_var_sym(const char *name
, struct symbol
*sym
, struct range_list
**rl
);
1085 bool user_rl_capped(struct expression
*expr
);
1086 struct range_list
*var_user_rl(struct expression
*expr
);
1087 bool we_pass_user_data(struct expression
*call
);
1088 /* smatch_points_to_user_data.c */
1089 bool is_user_data_fn(struct symbol
*fn
);
1090 bool is_skb_data(struct expression
*expr
);
1091 bool points_to_user_data(struct expression
*expr
);
1092 void set_points_to_user_data(struct expression
*expr
);
1094 /* check_locking.c */
1095 void print_held_locks();
1097 /* check_assigned_expr.c */
1098 extern int check_assigned_expr_id
;
1099 struct expression
*get_assigned_expr(struct expression
*expr
);
1100 struct sm_state
*get_assigned_sm(struct expression
*expr
);
1101 struct expression
*get_assigned_expr_recurse(struct expression
*expr
);
1102 struct expression
*get_assigned_expr_name_sym(const char *name
, struct symbol
*sym
);
1103 struct expression
*get_assigned_expr_name_sym_recurse(const char *name
, struct symbol
*sym
);
1105 /* smatch_return_to_param.c */
1106 void __add_return_to_param_mapping(struct expression
*assign
, const char *return_string
);
1107 char *map_call_to_param_name_sym(struct expression
*expr
, struct symbol
**sym
);
1109 /* smatch_comparison.c */
1110 extern int comparison_id
;
1111 #define UNKNOWN_COMPARISON 0
1112 #define IMPOSSIBLE_COMPARISON -1
1113 struct compare_data
{
1114 /* The ->left and ->right expression pointers might be NULL (I'm lazy) */
1115 struct expression
*left
;
1116 const char *left_var
;
1117 struct var_sym_list
*left_vsl
;
1119 struct expression
*right
;
1120 const char *right_var
;
1121 struct var_sym_list
*right_vsl
;
1123 DECLARE_ALLOCATOR(compare_data
);
1124 struct smatch_state
*alloc_compare_state(
1125 struct expression
*left
,
1126 const char *left_var
, struct var_sym_list
*left_vsl
,
1128 struct expression
*right
,
1129 const char *right_var
, struct var_sym_list
*right_vsl
);
1130 int comparison_intersection(int orig
, int op
);
1131 int merge_comparisons(int one
, int two
);
1132 int combine_comparisons(int left_compare
, int right_compare
);
1133 int state_to_comparison(struct smatch_state
*state
);
1134 struct smatch_state
*merge_compare_states(struct smatch_state
*s1
, struct smatch_state
*s2
);
1135 int get_comparison(struct expression
*left
, struct expression
*right
);
1136 int get_comparison_no_extra(struct expression
*a
, struct expression
*b
);
1137 int get_comparison_strings(const char *one
, const char *two
);
1138 int possible_comparison(struct expression
*a
, int comparison
, struct expression
*b
);
1139 struct state_list
*get_all_comparisons(struct expression
*expr
);
1140 struct state_list
*get_all_possible_equal_comparisons(struct expression
*expr
);
1141 void __add_return_comparison(struct expression
*call
, const char *range
);
1142 void __add_comparison_info(struct expression
*expr
, struct expression
*call
, const char *range
);
1143 char *get_printed_param_name(struct expression
*call
, const char *param_name
, struct symbol
*param_sym
);
1144 char *name_sym_to_param_comparison(const char *name
, struct symbol
*sym
);
1145 char *expr_equal_to_param(struct expression
*expr
, int ignore
);
1146 char *expr_lte_to_param(struct expression
*expr
, int ignore
);
1147 char *expr_param_comparison(struct expression
*expr
, int ignore
);
1148 int flip_comparison(int op
);
1149 int negate_comparison(int op
);
1150 int remove_unsigned_from_comparison(int op
);
1151 int param_compare_limit_is_impossible(struct expression
*expr
, int left_param
, char *left_key
, char *value
);
1152 void filter_by_comparison(struct range_list
**rl
, int comparison
, struct range_list
*right
);
1153 void __compare_param_limit_hook(struct expression
*left_expr
, struct expression
*right_expr
,
1154 const char *state_name
,
1155 struct smatch_state
*true_state
, struct smatch_state
*false_state
);
1156 int impossibly_high_comparison(struct expression
*expr
);
1159 sval_t
*sval_alloc(sval_t sval
);
1160 sval_t
*sval_alloc_permanent(sval_t sval
);
1161 sval_t
sval_blank(struct expression
*expr
);
1162 sval_t
sval_type_val(struct symbol
*type
, long long val
);
1163 sval_t
sval_type_fval(struct symbol
*type
, long double fval
);
1164 sval_t
sval_from_val(struct expression
*expr
, long long val
);
1165 sval_t
sval_from_fval(struct expression
*expr
, long double fval
);
1166 int sval_is_ptr(sval_t sval
);
1167 bool sval_is_fp(sval_t sval
);
1168 int sval_unsigned(sval_t sval
);
1169 int sval_signed(sval_t sval
);
1170 int sval_bits(sval_t sval
);
1171 int sval_bits_used(sval_t sval
);
1172 int sval_is_negative(sval_t sval
);
1173 int sval_is_positive(sval_t sval
);
1174 int sval_is_min(sval_t sval
);
1175 int sval_is_max(sval_t sval
);
1176 int sval_is_a_min(sval_t sval
);
1177 int sval_is_a_max(sval_t sval
);
1178 int sval_is_negative_min(sval_t sval
);
1179 int sval_cmp_t(struct symbol
*type
, sval_t one
, sval_t two
);
1180 int sval_cmp_val(sval_t one
, long long val
);
1181 sval_t
sval_min(sval_t one
, sval_t two
);
1182 sval_t
sval_min_nonneg(sval_t one
, sval_t two
);
1183 sval_t
sval_max(sval_t one
, sval_t two
);
1184 int sval_too_low(struct symbol
*type
, sval_t sval
);
1185 int sval_too_high(struct symbol
*type
, sval_t sval
);
1186 int sval_fits(struct symbol
*type
, sval_t sval
);
1187 sval_t
sval_cast(struct symbol
*type
, sval_t sval
);
1188 sval_t
sval_preop(sval_t sval
, int op
);
1189 sval_t
sval_binop(sval_t left
, int op
, sval_t right
);
1190 int sval_binop_overflows(sval_t left
, int op
, sval_t right
);
1191 int sval_binop_overflows_no_sign(sval_t left
, int op
, sval_t right
);
1192 int find_first_zero_bit(unsigned long long uvalue
);
1193 int sm_fls64(unsigned long long uvalue
);
1194 unsigned long long fls_mask(unsigned long long uvalue
);
1195 unsigned long long sval_fls_mask(sval_t sval
);
1196 const char *sval_to_str(sval_t sval
);
1197 const char *sval_to_str_or_err_ptr(sval_t sval
);
1198 const char *sval_to_numstr(sval_t sval
);
1199 sval_t
ll_to_sval(long long val
);
1201 /* smatch_string_list.c */
1202 int list_has_string(struct string_list
*str_list
, const char *str
);
1203 int insert_string(struct string_list
**str_list
, const char *str
);
1204 struct string_list
*clone_str_list(struct string_list
*orig
);
1205 struct string_list
*combine_string_lists(struct string_list
*one
, struct string_list
*two
);
1207 /* smatch_start_states.c */
1208 struct stree
*get_start_states(void);
1210 /* smatch_recurse.c */
1211 int has_symbol(struct expression
*expr
, struct symbol
*sym
);
1212 int has_variable(struct expression
*expr
, struct expression
*var
);
1213 int has_inc_dec(struct expression
*expr
);
1215 /* smatch_stored_conditions.c */
1216 struct smatch_state
*get_stored_condition(struct expression
*expr
);
1217 struct expression_list
*get_conditions(struct expression
*expr
);
1218 struct sm_state
*stored_condition_implication_hook(struct expression
*expr
,
1219 struct state_list
**true_stack
,
1220 struct state_list
**false_stack
);
1221 /* smatch_parsed_conditions.c */
1222 struct sm_state
*parsed_condition_implication_hook(struct expression
*expr
,
1223 struct state_list
**true_stack
,
1224 struct state_list
**false_stack
);
1225 /* smatch_comparison.c */
1226 struct sm_state
*comparison_implication_hook(struct expression
*expr
,
1227 struct state_list
**true_stack
,
1228 struct state_list
**false_stack
);
1230 /* check_string_len.c */
1231 int get_formatted_string_size(struct expression
*call
, int arg
);
1232 int get_formatted_string_min_size(struct expression
*call
, int arg
);
1234 /* smatch_param_set.c */
1235 int param_was_set(struct expression
*expr
);
1236 int param_was_set_var_sym(const char *name
, struct symbol
*sym
);
1237 void print_limited_param_set(int return_id
, char *return_ranges
, struct expression
*expr
);
1239 bool parent_was_PARAM_CLEAR(const char *name
, struct symbol
*sym
);
1240 bool parent_was_PARAM_CLEAR_ZERO(const char *name
, struct symbol
*sym
);
1242 /* smatch_param_filter.c */
1243 int param_has_filter_data(struct sm_state
*sm
);
1245 /* smatch_links.c */
1246 void set_up_link_functions(int id
, int linkid
);
1247 struct smatch_state
*merge_link_states(struct smatch_state
*s1
, struct smatch_state
*s2
);
1248 void store_link(int link_id
, const char *name
, struct symbol
*sym
, const char *link_name
, struct symbol
*link_sym
);
1250 /* check_buf_comparison */
1251 const char *limit_type_str(unsigned int limit_type
);
1252 struct expression
*get_size_variable(struct expression
*buf
, int *limit_type
);
1253 struct expression
*get_array_variable(struct expression
*size
);
1254 int buf_comparison_index_ok(struct expression
*expr
);
1256 /* smatch_untracked_param.c */
1257 void mark_untracked(struct expression
*expr
, int param
, const char *key
, const char *value
);
1258 void add_untracked_param_hook(void (func
)(struct expression
*call
, int param
));
1259 void add_lost_param_hook(void (func
)(struct expression
*call
, int param
));
1260 void mark_all_params_untracked(int return_id
, char *return_ranges
, struct expression
*expr
);
1262 /* smatch_strings.c */
1263 struct state_list
*get_strings(struct expression
*expr
);
1264 struct expression
*fake_string_from_mtag(mtag_t tag
);
1266 /* smatch_estate.c */
1267 int estate_get_single_value(struct smatch_state
*state
, sval_t
*sval
);
1269 /* smatch_address.c */
1270 int get_address_rl(struct expression
*expr
, struct range_list
**rl
);
1271 int get_member_offset(struct symbol
*type
, const char *member_name
);
1272 int get_member_offset_from_deref(struct expression
*expr
);
1274 /* for now this is in smatch_used_parameter.c */
1275 void __get_state_hook(int owner
, const char *name
, struct symbol
*sym
);
1276 extern int __ignore_param_used
;
1278 /* smatch_buf_comparison.c */
1279 int db_var_is_array_limit(struct expression
*array
, const char *name
, struct var_sym_list
*vsl
);
1281 struct range_list
*get_fs(void);
1283 struct stree
*get_all_return_states(void);
1284 struct stree_stack
*get_all_return_strees(void);
1285 int on_atomic_dec_path(void);
1286 int was_inced(const char *name
, struct symbol
*sym
);
1287 void set_refcount_inc(char *name
, struct symbol
*sym
);
1288 void set_refcount_dec(char *name
, struct symbol
*sym
);
1290 /* smatch_constraints.c */
1291 char *get_constraint_str(struct expression
*expr
);
1292 struct constraint_list
*get_constraints(struct expression
*expr
);
1293 char *unmet_constraint(struct expression
*data
, struct expression
*offset
);
1294 char *get_required_constraint(const char *data_str
);
1296 /* smatch_container_of.c */
1297 int get_param_from_container_of(struct expression
*expr
);
1298 int get_offset_from_container_of(struct expression
*expr
);
1299 char *get_container_name(struct expression
*container
, struct expression
*expr
);
1302 mtag_t
str_to_mtag(const char *str
);
1303 int get_string_mtag(struct expression
*expr
, mtag_t
*tag
);
1304 int get_toplevel_mtag(struct symbol
*sym
, mtag_t
*tag
);
1305 int create_mtag_alias(mtag_t tag
, struct expression
*expr
, mtag_t
*new);
1306 int expr_to_mtag_offset(struct expression
*expr
, mtag_t
*tag
, int *offset
);
1307 void update_mtag_data(struct expression
*expr
, struct smatch_state
*state
);
1308 int get_mtag_sval(struct expression
*expr
, sval_t
*sval
);
1310 /* Trinity fuzzer stuff */
1311 const char *get_syscall_arg_type(struct symbol
*sym
);
1313 /* smatch_bit_info.c */
1314 struct bit_info
*rl_to_binfo(struct range_list
*rl
);
1315 struct bit_info
*get_bit_info(struct expression
*expr
);
1316 struct bit_info
*get_bit_info_var_sym(const char *name
, struct symbol
*sym
);
1317 /* smatch_mem_tracker.c */
1318 extern int option_mem
;
1319 unsigned long get_mem_kb(void);
1320 unsigned long get_max_memory(void);
1322 /* check_is_nospec.c */
1323 bool is_nospec(struct expression
*expr
);
1324 long get_stmt_cnt(void);
1326 /* smatch_nul_terminator.c */
1327 bool is_nul_terminated_var_sym(const char *name
, struct symbol
*sym
);
1328 bool is_nul_terminated(struct expression
*expr
);
1329 /* check_kernel.c */
1330 bool is_ignored_kernel_data(const char *name
);
1331 int get_gfp_param(struct expression
*expr
);
1333 bool is_fresh_alloc_var_sym(const char *var
, struct symbol
*sym
);
1334 bool is_fresh_alloc(struct expression
*expr
);
1335 bool is_freed_var_sym(const char *name
, struct symbol
*sym
);
1336 void track_freed_param(struct expression
*expr
, struct smatch_state
*state
);
1337 void track_freed_param_var_sym(const char *name
, struct symbol
*sym
,
1338 struct smatch_state
*state
);
1340 static inline bool type_is_ptr(struct symbol
*type
)
1343 (type
->type
== SYM_PTR
||
1344 type
->type
== SYM_ARRAY
||
1345 type
->type
== SYM_FN
);
1348 static inline bool type_is_fp(struct symbol
*type
)
1351 (type
== &float_ctype
||
1352 type
== &double_ctype
||
1353 type
== &ldouble_ctype
);
1356 static inline int type_bits(struct symbol
*type
)
1360 if (type_is_ptr(type
))
1361 return bits_in_pointer
;
1362 if (!type
->examined
)
1363 examine_symbol_type(type
);
1364 return type
->bit_size
;
1367 static inline int type_unsigned(struct symbol
*base_type
)
1371 if (is_ptr_type(base_type
))
1373 if (base_type
->ctype
.modifiers
& MOD_UNSIGNED
)
1378 static inline int type_positive_bits(struct symbol
*type
)
1382 if (is_ptr_type(type
))
1383 return bits_in_pointer
;
1384 if (type_unsigned(type
))
1385 return type_bits(type
);
1386 return type_bits(type
) - 1;
1389 static inline int sval_positive_bits(sval_t sval
)
1391 return type_positive_bits(sval
.type
);
1395 * Returns -1 if one is smaller, 0 if they are the same and 1 if two is larger.
1398 static inline int fp_cmp(sval_t one
, sval_t two
)
1400 struct symbol
*type
;
1402 if (sval_is_fp(one
) && sval_is_fp(two
))
1403 type
= type_bits(one
.type
) > type_bits(two
.type
) ? one
.type
: two
.type
;
1404 else if (sval_is_fp(one
))
1409 one
= sval_cast(type
, one
);
1410 two
= sval_cast(type
, two
);
1412 if (one
.type
== &float_ctype
) {
1413 if (one
.fvalue
< two
.fvalue
)
1415 if (one
.fvalue
== two
.fvalue
)
1419 if (one
.type
== &double_ctype
) {
1420 if (one
.dvalue
< two
.dvalue
)
1422 if (one
.dvalue
== two
.dvalue
)
1426 if (one
.type
== &ldouble_ctype
) {
1427 if (one
.ldvalue
< two
.ldvalue
)
1429 if (one
.ldvalue
== two
.ldvalue
)
1433 sm_perror("bad type in fp_cmp(): %s", type_to_str(type
));
1437 static inline int sval_cmp(sval_t one
, sval_t two
)
1439 struct symbol
*type
;
1441 if (sval_is_fp(one
) || sval_is_fp(two
))
1442 return fp_cmp(one
, two
);
1445 if (sval_positive_bits(two
) > sval_positive_bits(one
))
1447 if (type_bits(type
) < 31)
1450 one
= sval_cast(type
, one
);
1451 two
= sval_cast(type
, two
);
1453 if (type_unsigned(type
)) {
1454 if (one
.uvalue
< two
.uvalue
)
1456 if (one
.uvalue
== two
.uvalue
)
1460 /* fix me handle type promotion and unsigned values */
1461 if (one
.value
< two
.value
)
1463 if (one
.value
== two
.value
)
1468 #endif /* !SMATCH_H_ */