nospec: store functions that return nospec indexes
[smatch.git] / smatch.h
blob6ddf155c038a612c4f83af05a6cd3c82cb1a1b6d
1 /*
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
18 #ifndef SMATCH_H_
19 # define SMATCH_H_
21 #include <stdio.h>
22 #include <string.h>
23 #include <limits.h>
24 #include <sys/time.h>
25 #include <sqlite3.h>
26 #include "lib.h"
27 #include "allocate.h"
28 #include "scope.h"
29 #include "parse.h"
30 #include "expression.h"
31 #include "avl.h"
33 typedef struct {
34 struct symbol *type;
35 union {
36 long long value;
37 unsigned long long uvalue;
39 } sval_t;
41 typedef long long mtag_t;
43 struct smatch_state {
44 const char *name;
45 void *data;
47 #define STATE(_x) static struct smatch_state _x = { .name = #_x }
48 extern struct smatch_state undefined;
49 extern struct smatch_state ghost;
50 extern struct smatch_state merged;
51 extern struct smatch_state true_state;
52 extern struct smatch_state false_state;
53 DECLARE_ALLOCATOR(smatch_state);
55 static inline void *INT_PTR(int i)
57 return (void *)(long)i;
60 static inline int PTR_INT(void *p)
62 return (int)(long)p;
65 struct tracker {
66 char *name;
67 struct symbol *sym;
68 unsigned short owner;
70 DECLARE_ALLOCATOR(tracker);
71 DECLARE_PTR_LIST(tracker_list, struct tracker);
72 DECLARE_PTR_LIST(stree_stack, struct stree);
74 /* The first 3 struct members must match struct tracker */
75 struct sm_state {
76 const char *name;
77 struct symbol *sym;
78 unsigned short owner;
79 unsigned short merged:1;
80 unsigned short skip_implications:1;
81 unsigned int nr_children;
82 unsigned int line;
83 struct smatch_state *state;
84 struct stree *pool;
85 struct sm_state *left;
86 struct sm_state *right;
87 struct state_list *possible;
90 struct var_sym {
91 char *var;
92 struct symbol *sym;
94 DECLARE_ALLOCATOR(var_sym);
95 DECLARE_PTR_LIST(var_sym_list, struct var_sym);
97 struct constraint {
98 int op;
99 int id;
101 DECLARE_PTR_LIST(constraint_list, struct constraint);
103 enum hook_type {
104 EXPR_HOOK,
105 STMT_HOOK,
106 STMT_HOOK_AFTER,
107 SYM_HOOK,
108 STRING_HOOK,
109 DECLARATION_HOOK,
110 ASSIGNMENT_HOOK,
111 ASSIGNMENT_HOOK_AFTER,
112 RAW_ASSIGNMENT_HOOK,
113 GLOBAL_ASSIGNMENT_HOOK,
114 LOGIC_HOOK,
115 CONDITION_HOOK,
116 PRELOOP_HOOK,
117 SELECT_HOOK,
118 WHOLE_CONDITION_HOOK,
119 FUNCTION_CALL_HOOK_BEFORE,
120 FUNCTION_CALL_HOOK,
121 CALL_HOOK_AFTER_INLINE,
122 FUNCTION_CALL_HOOK_AFTER_DB,
123 CALL_ASSIGNMENT_HOOK,
124 MACRO_ASSIGNMENT_HOOK,
125 BINOP_HOOK,
126 OP_HOOK,
127 DEREF_HOOK,
128 CASE_HOOK,
129 ASM_HOOK,
130 CAST_HOOK,
131 SIZEOF_HOOK,
132 BASE_HOOK,
133 FUNC_DEF_HOOK,
134 AFTER_DEF_HOOK,
135 END_FUNC_HOOK,
136 AFTER_FUNC_HOOK,
137 RETURN_HOOK,
138 INLINE_FN_START,
139 INLINE_FN_END,
140 END_FILE_HOOK,
141 NUM_HOOKS,
144 #define TRUE 1
145 #define FALSE 0
147 struct range_list;
149 void add_hook(void *func, enum hook_type type);
150 typedef struct smatch_state *(merge_func_t)(struct smatch_state *s1, struct smatch_state *s2);
151 typedef struct smatch_state *(unmatched_func_t)(struct sm_state *state);
152 void add_merge_hook(int client_id, merge_func_t *func);
153 void add_unmatched_state_hook(int client_id, unmatched_func_t *func);
154 void add_pre_merge_hook(int client_id, void (*hook)(struct sm_state *sm));
155 typedef void (scope_hook)(void *data);
156 void add_scope_hook(scope_hook *hook, void *data);
157 typedef void (func_hook)(const char *fn, struct expression *expr, void *data);
158 typedef void (implication_hook)(const char *fn, struct expression *call_expr,
159 struct expression *assign_expr, void *data);
160 typedef void (return_implies_hook)(struct expression *call_expr,
161 int param, char *key, char *value);
162 typedef int (implied_return_hook)(struct expression *call_expr, void *info, struct range_list **rl);
163 void add_function_hook(const char *look_for, func_hook *call_back, void *data);
165 void add_function_assign_hook(const char *look_for, func_hook *call_back,
166 void *info);
167 void add_implied_return_hook(const char *look_for,
168 implied_return_hook *call_back,
169 void *info);
170 void add_macro_assign_hook(const char *look_for, func_hook *call_back,
171 void *info);
172 void add_macro_assign_hook_extra(const char *look_for, func_hook *call_back,
173 void *info);
174 void return_implies_state(const char *look_for, long long start, long long end,
175 implication_hook *call_back, void *info);
176 void select_return_states_hook(int type, return_implies_hook *callback);
177 void select_return_states_before(void (*fn)(void));
178 void select_return_states_after(void (*fn)(void));
179 int get_implied_return(struct expression *expr, struct range_list **rl);
180 void allocate_hook_memory(void);
182 struct modification_data {
183 struct smatch_state *prev;
184 struct expression *cur;
187 typedef void (modification_hook)(struct sm_state *sm, struct expression *mod_expr);
188 void add_modification_hook(int owner, modification_hook *call_back);
189 void add_modification_hook_late(int owner, modification_hook *call_back);
190 struct smatch_state *get_modification_state(struct expression *expr);
192 int outside_of_function(void);
193 const char *get_filename(void);
194 const char *get_base_file(void);
195 char *get_function(void);
196 int get_lineno(void);
197 extern int final_pass;
198 extern struct symbol *cur_func_sym;
199 extern int option_debug;
200 extern int local_debug;
201 extern int option_info;
202 extern int option_spammy;
203 extern char *trace_variable;
204 extern struct stree *global_states;
205 int is_silenced_function(void);
207 /* smatch_impossible.c */
208 int is_impossible_path(void);
209 void set_path_impossible(void);
211 extern FILE *sm_outfd;
212 extern FILE *sql_outfd;
213 extern FILE *caller_info_fd;
214 #define sm_printf(msg...) do { if (final_pass || option_debug || local_debug) fprintf(sm_outfd, msg); } while (0)
216 static inline void sm_prefix(void)
218 sm_printf("%s:%d %s() ", get_filename(), get_lineno(), get_function());
221 static inline void print_implied_debug_msg();
223 extern bool __silence_warnings_for_stmt;
225 #define sm_msg(msg...) \
226 do { \
227 print_implied_debug_msg(); \
228 if (!final_pass && !option_debug && !local_debug) \
229 break; \
230 if (__silence_warnings_for_stmt && !option_debug && !local_debug) \
231 break; \
232 if (!option_info && is_silenced_function()) \
233 break; \
234 sm_prefix(); \
235 sm_printf(msg); \
236 sm_printf("\n"); \
237 } while (0)
239 #define local_debug(msg...) \
240 do { \
241 if (local_debug) \
242 sm_msg(msg); \
243 } while (0)
245 extern char *implied_debug_msg;
246 static inline void print_implied_debug_msg(void)
248 static struct symbol *last_printed = NULL;
250 if (!implied_debug_msg)
251 return;
252 if (last_printed == cur_func_sym)
253 return;
254 last_printed = cur_func_sym;
255 sm_msg("%s", implied_debug_msg);
258 #define sm_debug(msg...) do { if (option_debug) sm_printf(msg); } while (0)
260 #define sm_info(msg...) do { \
261 if (option_debug || (option_info && final_pass)) { \
262 sm_prefix(); \
263 sm_printf("info: "); \
264 sm_printf(msg); \
265 sm_printf("\n"); \
267 } while(0)
269 #define ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1))
271 struct smatch_state *__get_state(int owner, const char *name, struct symbol *sym);
272 struct smatch_state *get_state(int owner, const char *name, struct symbol *sym);
273 struct smatch_state *get_state_expr(int owner, struct expression *expr);
274 struct state_list *get_possible_states(int owner, const char *name,
275 struct symbol *sym);
276 struct state_list *get_possible_states_expr(int owner, struct expression *expr);
277 struct sm_state *set_state(int owner, const char *name, struct symbol *sym,
278 struct smatch_state *state);
279 struct sm_state *set_state_expr(int owner, struct expression *expr,
280 struct smatch_state *state);
281 void delete_state(int owner, const char *name, struct symbol *sym);
282 void delete_state_expr(int owner, struct expression *expr);
283 void __delete_all_states_sym(struct symbol *sym);
284 void set_true_false_states(int owner, const char *name, struct symbol *sym,
285 struct smatch_state *true_state,
286 struct smatch_state *false_state);
287 void set_true_false_states_expr(int owner, struct expression *expr,
288 struct smatch_state *true_state,
289 struct smatch_state *false_state);
291 struct stree *get_all_states_from_stree(int owner, struct stree *source);
292 struct stree *get_all_states_stree(int id);
293 struct stree *__get_cur_stree(void);
294 int is_reachable(void);
295 void add_get_state_hook(void (*fn)(int owner, const char *name, struct symbol *sym));
297 /* smatch_helper.c */
298 DECLARE_PTR_LIST(int_stack, int);
299 char *alloc_string(const char *str);
300 void free_string(char *str);
301 void append(char *dest, const char *data, int buff_len);
302 void remove_parens(char *str);
303 struct smatch_state *alloc_state_num(int num);
304 struct smatch_state *alloc_state_str(const char *name);
305 struct smatch_state *alloc_state_expr(struct expression *expr);
306 struct expression *get_argument_from_call_expr(struct expression_list *args,
307 int num);
309 char *expr_to_var(struct expression *expr);
310 struct symbol *expr_to_sym(struct expression *expr);
311 char *expr_to_str(struct expression *expr);
312 char *expr_to_str_sym(struct expression *expr,
313 struct symbol **sym_ptr);
314 char *expr_to_var_sym(struct expression *expr,
315 struct symbol **sym_ptr);
316 char *expr_to_known_chunk_sym(struct expression *expr, struct symbol **sym);
317 char *expr_to_chunk_sym_vsl(struct expression *expr, struct symbol **sym, struct var_sym_list **vsl);
318 int get_complication_score(struct expression *expr);
320 int sym_name_is(const char *name, struct expression *expr);
321 int get_const_value(struct expression *expr, sval_t *sval);
322 int get_value(struct expression *expr, sval_t *val);
323 int get_implied_value(struct expression *expr, sval_t *val);
324 int get_implied_min(struct expression *expr, sval_t *sval);
325 int get_implied_max(struct expression *expr, sval_t *val);
326 int get_hard_max(struct expression *expr, sval_t *sval);
327 int get_fuzzy_min(struct expression *expr, sval_t *min);
328 int get_fuzzy_max(struct expression *expr, sval_t *max);
329 int get_absolute_min(struct expression *expr, sval_t *sval);
330 int get_absolute_max(struct expression *expr, sval_t *sval);
331 int parse_call_math(struct expression *expr, char *math, sval_t *val);
332 int parse_call_math_rl(struct expression *call, char *math, struct range_list **rl);
333 char *get_value_in_terms_of_parameter_math(struct expression *expr);
334 char *get_value_in_terms_of_parameter_math_var_sym(const char *var, struct symbol *sym);
335 int is_zero(struct expression *expr);
336 int known_condition_true(struct expression *expr);
337 int known_condition_false(struct expression *expr);
338 int implied_condition_true(struct expression *expr);
339 int implied_condition_false(struct expression *expr);
340 int can_integer_overflow(struct symbol *type, struct expression *expr);
341 void clear_math_cache(void);
343 int is_array(struct expression *expr);
344 struct expression *get_array_base(struct expression *expr);
345 struct expression *get_array_offset(struct expression *expr);
346 const char *show_state(struct smatch_state *state);
347 struct statement *get_expression_statement(struct expression *expr);
348 struct expression *strip_parens(struct expression *expr);
349 struct expression *strip_expr(struct expression *expr);
350 struct expression *strip_expr_set_parent(struct expression *expr);
351 void scoped_state(int my_id, const char *name, struct symbol *sym);
352 int is_error_return(struct expression *expr);
353 int getting_address(void);
354 int get_struct_and_member(struct expression *expr, const char **type, const char **member);
355 char *get_member_name(struct expression *expr);
356 char *get_fnptr_name(struct expression *expr);
357 int cmp_pos(struct position pos1, struct position pos2);
358 int positions_eq(struct position pos1, struct position pos2);
359 struct statement *get_current_statement(void);
360 struct statement *get_prev_statement(void);
361 struct expression *get_last_expr_from_expression_stmt(struct expression *expr);
362 int get_param_num_from_sym(struct symbol *sym);
363 int get_param_num(struct expression *expr);
364 int ms_since(struct timeval *start);
365 int parent_is_gone_var_sym(const char *name, struct symbol *sym);
366 int parent_is_gone(struct expression *expr);
367 int invert_op(int op);
368 int expr_equiv(struct expression *one, struct expression *two);
369 void push_int(struct int_stack **stack, int num);
370 int pop_int(struct int_stack **stack);
372 /* smatch_type.c */
373 struct symbol *get_real_base_type(struct symbol *sym);
374 int type_bytes(struct symbol *type);
375 int array_bytes(struct symbol *type);
376 struct symbol *get_pointer_type(struct expression *expr);
377 struct symbol *get_type(struct expression *expr);
378 struct symbol *get_final_type(struct expression *expr);
379 struct symbol *get_promoted_type(struct symbol *left, struct symbol *right);
380 int type_signed(struct symbol *base_type);
381 int expr_unsigned(struct expression *expr);
382 int expr_signed(struct expression *expr);
383 int returns_unsigned(struct symbol *base_type);
384 int is_pointer(struct expression *expr);
385 int returns_pointer(struct symbol *base_type);
386 sval_t sval_type_max(struct symbol *base_type);
387 sval_t sval_type_min(struct symbol *base_type);
388 int nr_bits(struct expression *expr);
389 int is_void_pointer(struct expression *expr);
390 int is_char_pointer(struct expression *expr);
391 int is_string(struct expression *expr);
392 int is_static(struct expression *expr);
393 int is_local_variable(struct expression *expr);
394 int types_equiv(struct symbol *one, struct symbol *two);
395 int fn_static(void);
396 const char *global_static();
397 struct symbol *cur_func_return_type(void);
398 struct symbol *get_arg_type(struct expression *fn, int arg);
399 struct symbol *get_member_type_from_key(struct expression *expr, const char *key);
400 int is_struct(struct expression *expr);
401 char *type_to_str(struct symbol *type);
403 /* smatch_ignore.c */
404 void add_ignore(int owner, const char *name, struct symbol *sym);
405 int is_ignored(int owner, const char *name, struct symbol *sym);
406 void add_ignore_expr(int owner, struct expression *expr);
407 int is_ignored_expr(int owner, struct expression *expr);
409 /* smatch_var_sym */
410 struct var_sym *alloc_var_sym(const char *var, struct symbol *sym);
411 struct var_sym_list *expr_to_vsl(struct expression *expr);
412 void add_var_sym(struct var_sym_list **list, const char *var, struct symbol *sym);
413 void add_var_sym_expr(struct var_sym_list **list, struct expression *expr);
414 void del_var_sym(struct var_sym_list **list, const char *var, struct symbol *sym);
415 int in_var_sym_list(struct var_sym_list *list, const char *var, struct symbol *sym);
416 struct var_sym_list *clone_var_sym_list(struct var_sym_list *from_vsl);
417 void merge_var_sym_list(struct var_sym_list **dest, struct var_sym_list *src);
418 struct var_sym_list *combine_var_sym_lists(struct var_sym_list *one, struct var_sym_list *two);
419 int var_sym_lists_equiv(struct var_sym_list *one, struct var_sym_list *two);
420 void free_var_sym_list(struct var_sym_list **list);
421 void free_var_syms_and_list(struct var_sym_list **list);
423 /* smatch_tracker */
424 struct tracker *alloc_tracker(int owner, const char *name, struct symbol *sym);
425 void add_tracker(struct tracker_list **list, int owner, const char *name,
426 struct symbol *sym);
427 void add_tracker_expr(struct tracker_list **list, int owner, struct expression *expr);
428 void del_tracker(struct tracker_list **list, int owner, const char *name,
429 struct symbol *sym);
430 int in_tracker_list(struct tracker_list *list, int owner, const char *name,
431 struct symbol *sym);
432 void free_tracker_list(struct tracker_list **list);
433 void free_trackers_and_list(struct tracker_list **list);
435 /* smatch_conditions */
436 int in_condition(void);
438 /* smatch_flow.c */
440 extern int __in_fake_assign;
441 extern int __in_fake_struct_assign;
442 extern int in_fake_env;
443 void smatch (int argc, char **argv);
444 int inside_loop(void);
445 int definitely_inside_loop(void);
446 struct expression *get_switch_expr(void);
447 int in_expression_statement(void);
448 void __process_post_op_stack(void);
449 void __split_expr(struct expression *expr);
450 void __split_label_stmt(struct statement *stmt);
451 void __split_stmt(struct statement *stmt);
452 extern int __in_function_def;
453 extern int option_assume_loops;
454 extern int option_two_passes;
455 extern int option_no_db;
456 extern int option_file_output;
457 extern int option_time;
458 extern struct expression_list *big_expression_stack;
459 extern struct expression_list *big_condition_stack;
460 extern struct statement_list *big_statement_stack;
461 int is_assigned_call(struct expression *expr);
462 int inlinable(struct expression *expr);
463 extern int __inline_call;
464 extern struct expression *__inline_fn;
465 extern int __in_pre_condition;
466 extern int __bail_on_rest_of_function;
467 extern struct statement *__prev_stmt;
468 extern struct statement *__cur_stmt;
469 extern struct statement *__next_stmt;
470 void init_fake_env(void);
471 void end_fake_env(void);
472 int time_parsing_function(void);
474 /* smatch_struct_assignment.c */
475 struct expression *get_faked_expression(void);
476 void __fake_struct_member_assignments(struct expression *expr);
478 /* smatch_project.c */
479 int is_no_inline_function(const char *function);
481 /* smatch_conditions */
482 void __split_whole_condition(struct expression *expr);
483 void __handle_logic(struct expression *expr);
484 int is_condition(struct expression *expr);
485 int __handle_condition_assigns(struct expression *expr);
486 int __handle_select_assigns(struct expression *expr);
487 int __handle_expr_statement_assigns(struct expression *expr);
489 /* smatch_implied.c */
490 extern int option_debug_implied;
491 extern int option_debug_related;
492 struct range_list_stack;
493 void param_limit_implications(struct expression *expr, int param, char *key, char *value);
494 struct stree *__implied_case_stree(struct expression *switch_expr,
495 struct range_list *case_rl,
496 struct range_list_stack **remaining_cases,
497 struct stree **raw_stree);
498 void overwrite_states_using_pool(struct sm_state *gate_sm, struct sm_state *pool_sm);
499 int assume(struct expression *expr);
500 void end_assume(void);
501 int impossible_assumption(struct expression *left, int op, sval_t sval);
503 /* smatch_extras.c */
504 #define SMATCH_EXTRA 5 /* this is my_id from smatch extra set in smatch.c */
505 extern int RETURN_ID;
507 struct data_range {
508 sval_t min;
509 sval_t max;
512 #define MTAG_ALIAS_BIT (1ULL << 63)
513 #define MTAG_OFFSET_MASK 0xfffULL
515 extern long long valid_ptr_min, valid_ptr_max;
516 extern sval_t valid_ptr_min_sval, valid_ptr_max_sval;
517 extern struct range_list *valid_ptr_rl;
518 static const sval_t array_min_sval = {
519 .type = &ptr_ctype,
520 {.value = 100000},
522 static const sval_t array_max_sval = {
523 .type = &ptr_ctype,
524 {.value = 199999},
526 static const sval_t text_seg_min = {
527 .type = &ptr_ctype,
528 {.value = 100000000},
530 static const sval_t text_seg_max = {
531 .type = &ptr_ctype,
532 {.value = 177777777},
534 static const sval_t data_seg_min = {
535 .type = &ptr_ctype,
536 {.value = 200000000},
538 static const sval_t data_seg_max = {
539 .type = &ptr_ctype,
540 {.value = 277777777},
542 static const sval_t bss_seg_min = {
543 .type = &ptr_ctype,
544 {.value = 300000000},
546 static const sval_t bss_seg_max = {
547 .type = &ptr_ctype,
548 {.value = 377777777},
550 static const sval_t stack_seg_min = {
551 .type = &ptr_ctype,
552 {.value = 400000000},
554 static const sval_t stack_seg_max = {
555 .type = &ptr_ctype,
556 {.value = 477777777},
558 static const sval_t kmalloc_seg_min = {
559 .type = &ptr_ctype,
560 {.value = 500000000},
562 static const sval_t kmalloc_seg_max = {
563 .type = &ptr_ctype,
564 {.value = 577777777},
566 static const sval_t vmalloc_seg_min = {
567 .type = &ptr_ctype,
568 {.value = 600000000},
570 static const sval_t vmalloc_seg_max = {
571 .type = &ptr_ctype,
572 {.value = 677777777},
574 static const sval_t fn_ptr_min = {
575 .type = &ptr_ctype,
576 {.value = 700000000},
578 static const sval_t fn_ptr_max = {
579 .type = &ptr_ctype,
580 {.value = 777777777},
583 char *get_other_name_sym(const char *name, struct symbol *sym, struct symbol **new_sym);
584 char *map_call_to_other_name_sym(const char *name, struct symbol *sym, struct symbol **new_sym);
585 char *map_long_to_short_name_sym(const char *name, struct symbol *sym, struct symbol **new_sym);
586 char *map_long_to_short_name_sym_nostack(const char *name, struct symbol *sym, struct symbol **new_sym);
588 #define STRLEN_MAX_RET 1010101
590 /* smatch_absolute.c */
591 int get_absolute_min_helper(struct expression *expr, sval_t *sval);
592 int get_absolute_max_helper(struct expression *expr, sval_t *sval);
594 /* smatch_local_values.c */
595 int get_local_rl(struct expression *expr, struct range_list **rl);
596 int get_local_max_helper(struct expression *expr, sval_t *sval);
597 int get_local_min_helper(struct expression *expr, sval_t *sval);
599 /* smatch_type_value.c */
600 int get_db_type_rl(struct expression *expr, struct range_list **rl);
601 /* smatch_data_val.c */
602 int get_mtag_rl(struct expression *expr, struct range_list **rl);
604 /* smatch_states.c */
605 void __swap_cur_stree(struct stree *stree);
606 void __push_fake_cur_stree();
607 struct stree *__pop_fake_cur_stree();
608 void __free_fake_cur_stree();
609 void __set_fake_cur_stree_fast(struct stree *stree);
610 void __pop_fake_cur_stree_fast(void);
611 void __merge_stree_into_cur(struct stree *stree);
613 int unreachable(void);
614 void __set_sm(struct sm_state *sm);
615 void __set_sm_cur_stree(struct sm_state *sm);
616 void __set_sm_fake_stree(struct sm_state *sm);
617 void __set_true_false_sm(struct sm_state *true_state,
618 struct sm_state *false_state);
619 void nullify_path(void);
620 void __match_nullify_path_hook(const char *fn, struct expression *expr,
621 void *unused);
622 void __unnullify_path(void);
623 int __path_is_null(void);
624 void save_all_states(void);
625 void restore_all_states(void);
626 void free_goto_stack(void);
627 void clear_all_states(void);
629 struct sm_state *get_sm_state(int owner, const char *name,
630 struct symbol *sym);
631 struct sm_state *get_sm_state_expr(int owner, struct expression *expr);
632 void __push_true_states(void);
633 void __use_false_states(void);
634 void __discard_false_states(void);
635 void __merge_false_states(void);
636 void __merge_true_states(void);
638 void __negate_cond_stacks(void);
639 void __use_pre_cond_states(void);
640 void __use_cond_true_states(void);
641 void __use_cond_false_states(void);
642 void __push_cond_stacks(void);
643 void __fold_in_set_states(void);
644 void __free_set_states(void);
645 struct stree *__copy_cond_true_states(void);
646 struct stree *__copy_cond_false_states(void);
647 struct stree *__pop_cond_true_stack(void);
648 struct stree *__pop_cond_false_stack(void);
649 void __and_cond_states(void);
650 void __or_cond_states(void);
651 void __save_pre_cond_states(void);
652 void __discard_pre_cond_states(void);
653 struct stree *__get_true_states(void);
654 struct stree *__get_false_states(void);
655 void __use_cond_states(void);
656 extern struct state_list *__last_base_slist;
658 void __push_continues(void);
659 void __discard_continues(void);
660 void __process_continues(void);
661 void __merge_continues(void);
663 void __push_breaks(void);
664 void __process_breaks(void);
665 int __has_breaks(void);
666 void __merge_breaks(void);
667 void __use_breaks(void);
669 void __save_switch_states(struct expression *switch_expr);
670 void __discard_switches(void);
671 int have_remaining_cases(void);
672 void __merge_switches(struct expression *switch_expr, struct range_list *case_rl);
673 void __push_default(void);
674 void __set_default(void);
675 int __pop_default(void);
677 void __push_conditions(void);
678 void __discard_conditions(void);
680 void __save_gotos(const char *name, struct symbol *sym);
681 void __merge_gotos(const char *name, struct symbol *sym);
683 void __print_cur_stree(void);
685 /* smatch_hooks.c */
686 void __pass_to_client(void *data, enum hook_type type);
687 void __pass_to_client_no_data(enum hook_type type);
688 void __pass_case_to_client(struct expression *switch_expr,
689 struct range_list *rl);
690 int __has_merge_function(int client_id);
691 struct smatch_state *__client_merge_function(int owner,
692 struct smatch_state *s1,
693 struct smatch_state *s2);
694 struct smatch_state *__client_unmatched_state_function(struct sm_state *sm);
695 void call_pre_merge_hook(struct sm_state *sm);
696 void __push_scope_hooks(void);
697 void __call_scope_hooks(void);
699 /* smatch_function_hooks.c */
700 void create_function_hook_hash(void);
701 void __match_initializer_call(struct symbol *sym);
703 /* smatch_db.c */
704 enum info_type {
705 INTERNAL = 0,
707 * Changing these numbers is a pain. Don't do it. If you ever use a
708 * number it can't be re-used right away so there may be gaps.
709 * We select these in order by type so if the order matters, then give
710 * it a number below 100-999,9000-9999 ranges. */
712 PARAM_CLEARED = 101,
713 PARAM_LIMIT = 103,
714 PARAM_FILTER = 104,
716 PARAM_VALUE = 1001,
717 BUF_SIZE = 1002,
718 USER_DATA = 1003,
719 CAPPED_DATA = 1004,
720 RETURN_VALUE = 1005,
721 DEREFERENCE = 1006,
722 RANGE_CAP = 1007,
723 LOCK_HELD = 1008,
724 LOCK_RELEASED = 1009,
725 ABSOLUTE_LIMITS = 1010,
726 PARAM_ADD = 1012,
727 PARAM_FREED = 1013,
728 DATA_SOURCE = 1014,
729 FUZZY_MAX = 1015,
730 STR_LEN = 1016,
731 ARRAY_LEN = 1017,
732 CAPABLE = 1018,
733 NS_CAPABLE = 1019,
734 CONTAINER = 1020,
735 CASTED_CALL = 1021,
736 TYPE_LINK = 1022,
737 UNTRACKED_PARAM = 1023,
738 CULL_PATH = 1024,
739 PARAM_SET = 1025,
740 PARAM_USED = 1026,
741 BYTE_UNITS = 1027,
742 COMPARE_LIMIT = 1028,
743 PARAM_COMPARE = 1029,
744 CONSTRAINT = 1031,
745 PASSES_TYPE = 1032,
746 CONSTRAINT_REQUIRED = 1033,
747 NOSPEC = 1035,
749 /* put random temporary stuff in the 7000-7999 range for testing */
750 USER_DATA3 = 8017,
751 USER_DATA3_SET = 9017,
752 NO_OVERFLOW = 8018,
753 NO_OVERFLOW_SIMPLE = 8019,
754 LOCKED = 8020,
755 UNLOCKED = 8021,
756 SET_FS = 8022,
757 ATOMIC_INC = 8023,
758 ATOMIC_DEC = 8024,
759 NO_SIDE_EFFECT = 8025,
760 FN_ARG_LINK = 8028,
761 DATA_VALUE = 8029,
762 ARRAYSIZE_ARG = 8033,
763 SIZEOF_ARG = 8034,
764 MEMORY_TAG = 8036,
765 MTAG_ASSIGN = 8035,
768 extern struct sqlite3 *smatch_db;
769 extern struct sqlite3 *mem_db;
770 extern struct sqlite3 *cache_db;
772 void debug_sql(struct sqlite3 *db, const char *sql);
773 void db_ignore_states(int id);
774 void select_caller_info_hook(void (*callback)(const char *name, struct symbol *sym, char *key, char *value), int type);
775 void add_member_info_callback(int owner, void (*callback)(struct expression *call, int param, char *printed_name, struct sm_state *sm));
776 void add_split_return_callback(void (*fn)(int return_id, char *return_ranges, struct expression *returned_expr));
777 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));
778 void select_call_implies_hook(int type, void (*callback)(struct expression *call, struct expression *arg, char *key, char *value));
779 void select_return_implies_hook(int type, void (*callback)(struct expression *call, struct expression *arg, char *key, char *value));
780 struct range_list *db_return_vals(struct expression *expr);
781 struct range_list *db_return_vals_from_str(const char *fn_name);
782 char *return_state_to_var_sym(struct expression *expr, int param, const char *key, struct symbol **sym);
783 char *get_chunk_from_key(struct expression *arg, char *key, struct symbol **sym, struct var_sym_list **vsl);
784 char *get_variable_from_key(struct expression *arg, const char *key, struct symbol **sym);
785 const char *state_name_to_param_name(const char *state_name, const char *param_name);
786 const char *get_param_name_var_sym(const char *name, struct symbol *sym);
787 const char *get_param_name(struct sm_state *sm);
788 const char *get_mtag_name_var_sym(const char *state_name, struct symbol *sym);
789 const char *get_mtag_name_expr(struct expression *expr);
790 char *get_data_info_name(struct expression *expr);
792 void sql_exec(struct sqlite3 *db, int (*callback)(void*, int, char**, char**), void *data, const char *sql);
794 #define sql_helper(db, call_back, data, sql...) \
795 do { \
796 char sql_txt[1024]; \
798 snprintf(sql_txt, sizeof(sql_txt), sql); \
799 sm_debug("debug: %s\n", sql_txt); \
800 debug_sql(db, sql_txt); \
801 sql_exec(db, call_back, data, sql_txt); \
802 } while (0)
805 #define run_sql(call_back, data, sql...) \
806 do { \
807 if (option_no_db) \
808 break; \
809 sql_helper(smatch_db, call_back, data, sql); \
810 } while (0)
812 #define mem_sql(call_back, data, sql...) \
813 sql_helper(mem_db, call_back, data, sql)
815 #define cache_sql(call_back, data, sql...) \
816 sql_helper(cache_db, call_back, data, sql)
818 #define sql_insert_helper(table, db, ignore, late, values...) \
819 do { \
820 struct sqlite3 *_db = db; \
822 if (__inline_fn && !_db) \
823 _db = mem_db; \
824 if (_db) { \
825 char buf[1024]; \
826 char *err, *p = buf; \
827 int rc; \
829 p += snprintf(p, buf + sizeof(buf) - p, \
830 "insert %sinto %s values (", \
831 ignore ? "or ignore " : "", #table); \
832 p += snprintf(p, buf + sizeof(buf) - p, values); \
833 p += snprintf(p, buf + sizeof(buf) - p, ");"); \
834 sm_debug("mem-db: %s\n", buf); \
835 rc = sqlite3_exec(_db, buf, NULL, NULL, &err); \
836 if (rc != SQLITE_OK) { \
837 fprintf(stderr, "SQL error #2: %s\n", err); \
838 fprintf(stderr, "SQL: '%s'\n", buf); \
839 parse_error = 1; \
841 break; \
843 if (option_info) { \
844 FILE *tmp_fd = sm_outfd; \
845 sm_outfd = sql_outfd; \
846 sm_prefix(); \
847 sm_printf("SQL%s: insert %sinto " #table " values(", \
848 late ? "_late" : "", ignore ? "or ignore " : ""); \
849 sm_printf(values); \
850 sm_printf(");\n"); \
851 sm_outfd = tmp_fd; \
853 } while (0)
855 #define sql_insert(table, values...) sql_insert_helper(table, 0, 0, 0, values);
856 #define sql_insert_or_ignore(table, values...) sql_insert_helper(table, 0, 1, 0, values);
857 #define sql_insert_late(table, values...) sql_insert_helper(table, 0, 0, 1, values);
858 #define sql_insert_cache(table, values...) sql_insert_helper(table, cache_db, 1, 0, values);
860 char *get_static_filter(struct symbol *sym);
862 void sql_insert_return_states(int return_id, const char *return_ranges,
863 int type, int param, const char *key, const char *value);
864 void sql_insert_caller_info(struct expression *call, int type, int param,
865 const char *key, const char *value);
866 void sql_insert_function_ptr(const char *fn, const char *struct_name);
867 void sql_insert_return_values(const char *return_values);
868 void sql_insert_return_implies(int type, int param, const char *key, const char *value);
869 void sql_insert_function_type_size(const char *member, const char *ranges);
870 void sql_insert_function_type_info(int type, const char *struct_type, const char *member, const char *value);
871 void sql_insert_type_info(int type, const char *member, const char *value);
872 void sql_insert_local_values(const char *name, const char *value);
873 void sql_insert_function_type_value(const char *type, const char *value);
874 void sql_insert_function_type(int param, const char *value);
875 void sql_insert_parameter_name(int param, const char *value);
876 void sql_insert_data_info(struct expression *data, int type, const char *value);
877 void sql_insert_data_info_var_sym(const char *var, struct symbol *sym, int type, const char *value);
878 void sql_save_constraint(const char *con);
879 void sql_save_constraint_required(const char *data, int op, const char *limit);
880 void sql_copy_constraint_required(const char *new_limit, const char *old_limit);
881 void sql_insert_fn_ptr_data_link(const char *ptr, const char *data);
882 void sql_insert_fn_data_link(struct expression *fn, int type, int param, const char *key, const char *value);
883 void sql_insert_mtag_about(mtag_t tag, const char *left_name, const char *right_name);
884 void insert_mtag_data(sval_t sval, struct range_list *rl);
885 void sql_insert_mtag_map(mtag_t tag, int offset, mtag_t container);
886 void sql_insert_mtag_alias(mtag_t orig, mtag_t alias);
887 int mtag_map_select_container(mtag_t tag, int offset, mtag_t *container);
888 int mtag_map_select_tag(mtag_t container, int offset, mtag_t *tag);
890 void sql_select_return_states(const char *cols, struct expression *call,
891 int (*callback)(void*, int, char**, char**), void *info);
892 void sql_select_call_implies(const char *cols, struct expression *call,
893 int (*callback)(void*, int, char**, char**));
895 void open_smatch_db(char *db_file);
897 /* smatch_files.c */
898 int open_data_file(const char *filename);
899 int open_schema_file(const char *schema);
900 struct token *get_tokens_file(const char *filename);
902 /* smatch.c */
903 extern char *option_debug_check;
904 extern char *option_project_str;
905 extern char *bin_dir;
906 extern char *data_dir;
907 extern int option_no_data;
908 extern int option_full_path;
909 extern int option_param_mapper;
910 extern int option_call_tree;
911 extern int num_checks;
913 enum project_type {
914 PROJ_NONE,
915 PROJ_KERNEL,
916 PROJ_WINE,
917 PROJ_UNKNOWN,
919 extern enum project_type option_project;
920 const char *check_name(unsigned short id);
921 int id_from_name(const char *name);
924 /* smatch_buf_size.c */
925 int get_array_size(struct expression *expr);
926 int get_array_size_bytes(struct expression *expr);
927 int get_array_size_bytes_min(struct expression *expr);
928 int get_array_size_bytes_max(struct expression *expr);
929 struct range_list *get_array_size_bytes_rl(struct expression *expr);
930 int get_real_array_size(struct expression *expr);
931 int last_member_is_resizable(struct symbol *type);
932 /* smatch_strlen.c */
933 int get_implied_strlen(struct expression *expr, struct range_list **rl);
934 int get_size_from_strlen(struct expression *expr);
936 /* smatch_capped.c */
937 int is_capped(struct expression *expr);
938 int is_capped_var_sym(const char *name, struct symbol *sym);
940 /* check_user_data.c */
941 int is_user_macro(struct expression *expr);
942 int is_user_data(struct expression *expr);
943 int is_capped_user_data(struct expression *expr);
944 int implied_user_data(struct expression *expr, struct range_list **rl);
945 int get_user_rl(struct expression *expr, struct range_list **rl);
946 int get_user_rl_spammy(struct expression *expr, struct range_list **rl);
947 int is_user_rl(struct expression *expr);
948 int get_user_rl_var_sym(const char *name, struct symbol *sym, struct range_list **rl);
950 /* check_locking.c */
951 void print_held_locks();
953 /* check_assigned_expr.c */
954 struct expression *get_assigned_expr(struct expression *expr);
955 struct expression *get_assigned_expr_name_sym(const char *name, struct symbol *sym);
956 /* smatch_return_to_param.c */
957 void __add_return_to_param_mapping(struct expression *assign, const char *return_string);
958 char *map_call_to_param_name_sym(struct expression *expr, struct symbol **sym);
960 /* smatch_comparison.c */
961 struct compare_data {
962 /* The ->left and ->right expression pointers might be NULL (I'm lazy) */
963 struct expression *left;
964 const char *left_var;
965 struct var_sym_list *left_vsl;
966 int comparison;
967 struct expression *right;
968 const char *right_var;
969 struct var_sym_list *right_vsl;
971 DECLARE_ALLOCATOR(compare_data);
972 struct smatch_state *alloc_compare_state(
973 struct expression *left,
974 const char *left_var, struct var_sym_list *left_vsl,
975 int comparison,
976 struct expression *right,
977 const char *right_var, struct var_sym_list *right_vsl);
978 int filter_comparison(int orig, int op);
979 int merge_comparisons(int one, int two);
980 int combine_comparisons(int left_compare, int right_compare);
981 int state_to_comparison(struct smatch_state *state);
982 struct smatch_state *merge_compare_states(struct smatch_state *s1, struct smatch_state *s2);
983 int get_comparison(struct expression *left, struct expression *right);
984 int get_comparison_strings(const char *one, const char *two);
985 int possible_comparison(struct expression *a, int comparison, struct expression *b);
986 struct state_list *get_all_comparisons(struct expression *expr);
987 struct state_list *get_all_possible_equal_comparisons(struct expression *expr);
988 void __add_return_comparison(struct expression *call, const char *range);
989 void __add_comparison_info(struct expression *expr, struct expression *call, const char *range);
990 char *get_printed_param_name(struct expression *call, const char *param_name, struct symbol *param_sym);
991 char *name_sym_to_param_comparison(const char *name, struct symbol *sym);
992 char *expr_equal_to_param(struct expression *expr, int ignore);
993 char *expr_lte_to_param(struct expression *expr, int ignore);
994 char *expr_param_comparison(struct expression *expr, int ignore);
995 int flip_comparison(int op);
996 int negate_comparison(int op);
997 int remove_unsigned_from_comparison(int op);
998 int param_compare_limit_is_impossible(struct expression *expr, int left_param, char *left_key, char *value);
999 void filter_by_comparison(struct range_list **rl, int comparison, struct range_list *right);
1000 struct sm_state *comparison_implication_hook(struct expression *expr,
1001 struct state_list **true_stack,
1002 struct state_list **false_stack);
1003 void __compare_param_limit_hook(struct expression *left_expr, struct expression *right_expr,
1004 const char *state_name,
1005 struct smatch_state *true_state, struct smatch_state *false_state);
1006 int impossibly_high_comparison(struct expression *expr);
1008 /* smatch_sval.c */
1009 sval_t *sval_alloc(sval_t sval);
1010 sval_t *sval_alloc_permanent(sval_t sval);
1011 sval_t sval_blank(struct expression *expr);
1012 sval_t sval_type_val(struct symbol *type, long long val);
1013 sval_t sval_from_val(struct expression *expr, long long val);
1014 int sval_is_ptr(sval_t sval);
1015 int sval_unsigned(sval_t sval);
1016 int sval_signed(sval_t sval);
1017 int sval_bits(sval_t sval);
1018 int sval_bits_used(sval_t sval);
1019 int sval_is_negative(sval_t sval);
1020 int sval_is_positive(sval_t sval);
1021 int sval_is_min(sval_t sval);
1022 int sval_is_max(sval_t sval);
1023 int sval_is_a_min(sval_t sval);
1024 int sval_is_a_max(sval_t sval);
1025 int sval_is_negative_min(sval_t sval);
1026 int sval_cmp_t(struct symbol *type, sval_t one, sval_t two);
1027 int sval_cmp_val(sval_t one, long long val);
1028 sval_t sval_min(sval_t one, sval_t two);
1029 sval_t sval_max(sval_t one, sval_t two);
1030 int sval_too_low(struct symbol *type, sval_t sval);
1031 int sval_too_high(struct symbol *type, sval_t sval);
1032 int sval_fits(struct symbol *type, sval_t sval);
1033 sval_t sval_cast(struct symbol *type, sval_t sval);
1034 sval_t sval_preop(sval_t sval, int op);
1035 sval_t sval_binop(sval_t left, int op, sval_t right);
1036 int sval_binop_overflows(sval_t left, int op, sval_t right);
1037 unsigned long long fls_mask(unsigned long long uvalue);
1038 unsigned long long sval_fls_mask(sval_t sval);
1039 const char *sval_to_str(sval_t sval);
1040 const char *sval_to_numstr(sval_t sval);
1041 sval_t ll_to_sval(long long val);
1043 /* smatch_string_list.c */
1044 int list_has_string(struct string_list *str_list, const char *str);
1045 void insert_string(struct string_list **str_list, const char *str);
1046 struct string_list *clone_str_list(struct string_list *orig);
1047 struct string_list *combine_string_lists(struct string_list *one, struct string_list *two);
1049 /* smatch_start_states.c */
1050 struct stree *get_start_states(void);
1052 /* smatch_recurse.c */
1053 int has_symbol(struct expression *expr, struct symbol *sym);
1054 int has_variable(struct expression *expr, struct expression *var);
1055 int has_inc_dec(struct expression *expr);
1057 /* smatch_stored_conditions.c */
1058 struct smatch_state *get_stored_condition(struct expression *expr);
1059 struct expression_list *get_conditions(struct expression *expr);
1060 struct sm_state *stored_condition_implication_hook(struct expression *expr,
1061 struct state_list **true_stack,
1062 struct state_list **false_stack);
1064 /* check_string_len.c */
1065 int get_formatted_string_size(struct expression *call, int arg);
1067 /* smatch_param_set.c */
1068 int param_was_set(struct expression *expr);
1069 int param_was_set_var_sym(const char *name, struct symbol *sym);
1070 /* smatch_param_filter.c */
1071 int param_has_filter_data(struct sm_state *sm);
1073 /* smatch_links.c */
1074 void set_up_link_functions(int id, int linkid);
1075 struct smatch_state *merge_link_states(struct smatch_state *s1, struct smatch_state *s2);
1076 void store_link(int link_id, const char *name, struct symbol *sym, const char *link_name, struct symbol *link_sym);
1078 /* smatch_auto_copy.c */
1079 void set_auto_copy(int owner);
1081 /* check_buf_comparison */
1082 struct expression *get_size_variable(struct expression *buf);
1083 struct expression *get_array_variable(struct expression *size);
1085 /* smatch_untracked_param.c */
1086 void mark_untracked(struct expression *expr, int param, const char *key, const char *value);
1087 void add_untracked_param_hook(void (func)(struct expression *call, int param));
1088 void mark_all_params_untracked(int return_id, char *return_ranges, struct expression *expr);
1090 /* smatch_strings.c */
1091 struct state_list *get_strings(struct expression *expr);
1093 /* smatch_estate.c */
1094 int estate_get_single_value(struct smatch_state *state, sval_t *sval);
1096 /* smatch_address.c */
1097 int get_address_rl(struct expression *expr, struct range_list **rl);
1098 int get_member_offset(struct symbol *type, const char *member_name);
1099 int get_member_offset_from_deref(struct expression *expr);
1101 /* for now this is in smatch_used_parameter.c */
1102 void __get_state_hook(int owner, const char *name, struct symbol *sym);
1104 /* smatch_buf_comparison.c */
1105 int db_var_is_array_limit(struct expression *array, const char *name, struct var_sym_list *vsl);
1107 struct stree *get_all_return_states(void);
1108 struct stree_stack *get_all_return_strees(void);
1109 int on_atomic_dec_path(void);
1110 int was_inced(const char *name, struct symbol *sym);
1112 /* smatch_constraints.c */
1113 char *get_constraint_str(struct expression *expr);
1114 struct constraint_list *get_constraints(struct expression *expr);
1115 char *unmet_constraint(struct expression *data, struct expression *offset);
1116 char *get_required_constraint(const char *data_str);
1118 /* smatch_container_of.c */
1119 int get_param_from_container_of(struct expression *expr);
1120 int get_offset_from_container_of(struct expression *expr);
1122 /* smatch_mtag.c */
1123 int get_toplevel_mtag(struct symbol *sym, mtag_t *tag);
1124 int get_mtag(struct expression *expr, mtag_t *tag);
1125 int get_mtag_offset(struct expression *expr, mtag_t *tag, int *offset);
1126 int create_mtag_alias(mtag_t tag, struct expression *expr, mtag_t *new);
1127 int expr_to_mtag_offset(struct expression *expr, mtag_t *tag, int *offset);
1128 void update_mtag_data(struct expression *expr);
1129 int get_mtag_sval(struct expression *expr, sval_t *sval);
1130 int get_mtag_addr_sval(struct expression *expr, sval_t *sval);
1132 /* smatch_mem_tracker.c */
1133 extern int option_mem;
1134 unsigned long get_max_memory(void);
1136 /* check_is_nospec.c */
1137 bool is_nospec(struct expression *expr);
1139 static inline int type_bits(struct symbol *type)
1141 if (!type)
1142 return 0;
1143 if (type->type == SYM_PTR) /* Sparse doesn't set this for &pointers */
1144 return bits_in_pointer;
1145 if (type->type == SYM_ARRAY)
1146 return bits_in_pointer;
1147 if (!type->examined)
1148 examine_symbol_type(type);
1149 return type->bit_size;
1152 static inline bool type_is_ptr(struct symbol *type)
1154 return type && (type->type == SYM_PTR || type->type == SYM_ARRAY);
1157 static inline int type_unsigned(struct symbol *base_type)
1159 if (!base_type)
1160 return 0;
1161 if (base_type->ctype.modifiers & MOD_UNSIGNED)
1162 return 1;
1163 return 0;
1166 static inline int type_positive_bits(struct symbol *type)
1168 if (!type)
1169 return 0;
1170 if (type->type == SYM_ARRAY)
1171 return bits_in_pointer - 1;
1172 if (type_unsigned(type))
1173 return type_bits(type);
1174 return type_bits(type) - 1;
1177 static inline int sval_positive_bits(sval_t sval)
1179 return type_positive_bits(sval.type);
1183 * Returns -1 if one is smaller, 0 if they are the same and 1 if two is larger.
1185 static inline int sval_cmp(sval_t one, sval_t two)
1187 struct symbol *type;
1189 type = one.type;
1190 if (sval_positive_bits(two) > sval_positive_bits(one))
1191 type = two.type;
1192 if (type_bits(type) < 31)
1193 type = &int_ctype;
1195 one = sval_cast(type, one);
1196 two = sval_cast(type, two);
1198 if (type_unsigned(type)) {
1199 if (one.uvalue < two.uvalue)
1200 return -1;
1201 if (one.uvalue == two.uvalue)
1202 return 0;
1203 return 1;
1205 /* fix me handle type promotion and unsigned values */
1206 if (one.value < two.value)
1207 return -1;
1208 if (one.value == two.value)
1209 return 0;
1210 return 1;
1213 #endif /* !SMATCH_H_ */