11f5207b7SJohn Levon /* 21f5207b7SJohn Levon * Copyright (C) 2006 Dan Carpenter. 31f5207b7SJohn Levon * 41f5207b7SJohn Levon * This program is free software; you can redistribute it and/or 51f5207b7SJohn Levon * modify it under the terms of the GNU General Public License 61f5207b7SJohn Levon * as published by the Free Software Foundation; either version 2 71f5207b7SJohn Levon * of the License, or (at your option) any later version. 81f5207b7SJohn Levon * 91f5207b7SJohn Levon * This program is distributed in the hope that it will be useful, 101f5207b7SJohn Levon * but WITHOUT ANY WARRANTY; without even the implied warranty of 111f5207b7SJohn Levon * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 121f5207b7SJohn Levon * GNU General Public License for more details. 131f5207b7SJohn Levon * 141f5207b7SJohn Levon * You should have received a copy of the GNU General Public License 151f5207b7SJohn Levon * along with this program; if not, see http://www.gnu.org/copyleft/gpl.txt 167ae7577cSJohn Levon * 177ae7577cSJohn Levon * Copyright 2019 Joyent, Inc. 181f5207b7SJohn Levon */ 191f5207b7SJohn Levon 201f5207b7SJohn Levon #ifndef SMATCH_H_ 211f5207b7SJohn Levon # define SMATCH_H_ 221f5207b7SJohn Levon 231f5207b7SJohn Levon #include <stdio.h> 241f5207b7SJohn Levon #include <string.h> 251f5207b7SJohn Levon #include <limits.h> 265a0e240fSJohn Levon #include <float.h> 271f5207b7SJohn Levon #include <sys/time.h> 281f5207b7SJohn Levon #include <sqlite3.h> 291f5207b7SJohn Levon #include "lib.h" 301f5207b7SJohn Levon #include "allocate.h" 311f5207b7SJohn Levon #include "scope.h" 321f5207b7SJohn Levon #include "parse.h" 331f5207b7SJohn Levon #include "expression.h" 341f5207b7SJohn Levon #include "avl.h" 351f5207b7SJohn Levon 361f5207b7SJohn Levon typedef struct { 371f5207b7SJohn Levon struct symbol *type; 381f5207b7SJohn Levon union { 391f5207b7SJohn Levon long long value; 401f5207b7SJohn Levon unsigned long long uvalue; 415a0e240fSJohn Levon float fvalue; 425a0e240fSJohn Levon double dvalue; 435a0e240fSJohn Levon long double ldvalue; 441f5207b7SJohn Levon }; 451f5207b7SJohn Levon } sval_t; 461f5207b7SJohn Levon 471f5207b7SJohn Levon typedef long long mtag_t; 481f5207b7SJohn Levon 491f5207b7SJohn Levon struct smatch_state { 501f5207b7SJohn Levon const char *name; 511f5207b7SJohn Levon void *data; 521f5207b7SJohn Levon }; 531f5207b7SJohn Levon #define STATE(_x) static struct smatch_state _x = { .name = #_x } 541f5207b7SJohn Levon extern struct smatch_state undefined; 551f5207b7SJohn Levon extern struct smatch_state ghost; 561f5207b7SJohn Levon extern struct smatch_state merged; 571f5207b7SJohn Levon extern struct smatch_state true_state; 581f5207b7SJohn Levon extern struct smatch_state false_state; 591f5207b7SJohn Levon DECLARE_ALLOCATOR(smatch_state); 601f5207b7SJohn Levon 611f5207b7SJohn Levon static inline void *INT_PTR(int i) 621f5207b7SJohn Levon { 631f5207b7SJohn Levon return (void *)(long)i; 641f5207b7SJohn Levon } 651f5207b7SJohn Levon 661f5207b7SJohn Levon static inline int PTR_INT(void *p) 671f5207b7SJohn Levon { 681f5207b7SJohn Levon return (int)(long)p; 691f5207b7SJohn Levon } 701f5207b7SJohn Levon 711f5207b7SJohn Levon struct tracker { 721f5207b7SJohn Levon char *name; 731f5207b7SJohn Levon struct symbol *sym; 741f5207b7SJohn Levon unsigned short owner; 751f5207b7SJohn Levon }; 761f5207b7SJohn Levon DECLARE_ALLOCATOR(tracker); 771f5207b7SJohn Levon DECLARE_PTR_LIST(tracker_list, struct tracker); 781f5207b7SJohn Levon DECLARE_PTR_LIST(stree_stack, struct stree); 791f5207b7SJohn Levon 801f5207b7SJohn Levon /* The first 3 struct members must match struct tracker */ 811f5207b7SJohn Levon struct sm_state { 821f5207b7SJohn Levon const char *name; 831f5207b7SJohn Levon struct symbol *sym; 841f5207b7SJohn Levon unsigned short owner; 851f5207b7SJohn Levon unsigned short merged:1; 861f5207b7SJohn Levon unsigned int line; 871f5207b7SJohn Levon struct smatch_state *state; 881f5207b7SJohn Levon struct stree *pool; 891f5207b7SJohn Levon struct sm_state *left; 901f5207b7SJohn Levon struct sm_state *right; 911f5207b7SJohn Levon struct state_list *possible; 921f5207b7SJohn Levon }; 931f5207b7SJohn Levon 941f5207b7SJohn Levon struct var_sym { 951f5207b7SJohn Levon char *var; 961f5207b7SJohn Levon struct symbol *sym; 971f5207b7SJohn Levon }; 981f5207b7SJohn Levon DECLARE_ALLOCATOR(var_sym); 991f5207b7SJohn Levon DECLARE_PTR_LIST(var_sym_list, struct var_sym); 1001f5207b7SJohn Levon 1011f5207b7SJohn Levon struct constraint { 1021f5207b7SJohn Levon int op; 1031f5207b7SJohn Levon int id; 1041f5207b7SJohn Levon }; 1051f5207b7SJohn Levon DECLARE_PTR_LIST(constraint_list, struct constraint); 1061f5207b7SJohn Levon 107*31ad075eSJohn Levon struct alloc_info { 108*31ad075eSJohn Levon const char *fn; 109*31ad075eSJohn Levon int size_param, nr; 110*31ad075eSJohn Levon }; 111*31ad075eSJohn Levon extern struct alloc_info *alloc_funcs; 112*31ad075eSJohn Levon 113efe51d0cSJohn Levon struct bit_info { 114efe51d0cSJohn Levon unsigned long long set; 115efe51d0cSJohn Levon unsigned long long possible; 116efe51d0cSJohn Levon }; 117efe51d0cSJohn Levon 1181f5207b7SJohn Levon enum hook_type { 1191f5207b7SJohn Levon EXPR_HOOK, 120c85f09ccSJohn Levon EXPR_HOOK_AFTER, 1211f5207b7SJohn Levon STMT_HOOK, 1221f5207b7SJohn Levon STMT_HOOK_AFTER, 1231f5207b7SJohn Levon SYM_HOOK, 1241f5207b7SJohn Levon STRING_HOOK, 1251f5207b7SJohn Levon DECLARATION_HOOK, 1261f5207b7SJohn Levon ASSIGNMENT_HOOK, 1271f5207b7SJohn Levon ASSIGNMENT_HOOK_AFTER, 1281f5207b7SJohn Levon RAW_ASSIGNMENT_HOOK, 1291f5207b7SJohn Levon GLOBAL_ASSIGNMENT_HOOK, 1301f5207b7SJohn Levon LOGIC_HOOK, 1311f5207b7SJohn Levon CONDITION_HOOK, 1321f5207b7SJohn Levon PRELOOP_HOOK, 1331f5207b7SJohn Levon SELECT_HOOK, 1341f5207b7SJohn Levon WHOLE_CONDITION_HOOK, 1351f5207b7SJohn Levon FUNCTION_CALL_HOOK_BEFORE, 1361f5207b7SJohn Levon FUNCTION_CALL_HOOK, 1371f5207b7SJohn Levon CALL_HOOK_AFTER_INLINE, 1381f5207b7SJohn Levon FUNCTION_CALL_HOOK_AFTER_DB, 1391f5207b7SJohn Levon CALL_ASSIGNMENT_HOOK, 1401f5207b7SJohn Levon MACRO_ASSIGNMENT_HOOK, 1411f5207b7SJohn Levon BINOP_HOOK, 1421f5207b7SJohn Levon OP_HOOK, 1431f5207b7SJohn Levon DEREF_HOOK, 1441f5207b7SJohn Levon CASE_HOOK, 1451f5207b7SJohn Levon ASM_HOOK, 1461f5207b7SJohn Levon CAST_HOOK, 1471f5207b7SJohn Levon SIZEOF_HOOK, 1481f5207b7SJohn Levon BASE_HOOK, 1491f5207b7SJohn Levon FUNC_DEF_HOOK, 1501f5207b7SJohn Levon AFTER_DEF_HOOK, 1511f5207b7SJohn Levon END_FUNC_HOOK, 1521f5207b7SJohn Levon AFTER_FUNC_HOOK, 1531f5207b7SJohn Levon RETURN_HOOK, 1541f5207b7SJohn Levon INLINE_FN_START, 1551f5207b7SJohn Levon INLINE_FN_END, 1561f5207b7SJohn Levon END_FILE_HOOK, 1571f5207b7SJohn Levon NUM_HOOKS, 1581f5207b7SJohn Levon }; 1591f5207b7SJohn Levon 1601f5207b7SJohn Levon #define TRUE 1 1611f5207b7SJohn Levon #define FALSE 0 1621f5207b7SJohn Levon 1631f5207b7SJohn Levon struct range_list; 1641f5207b7SJohn Levon 1651f5207b7SJohn Levon void add_hook(void *func, enum hook_type type); 1661f5207b7SJohn Levon typedef struct smatch_state *(merge_func_t)(struct smatch_state *s1, struct smatch_state *s2); 1671f5207b7SJohn Levon typedef struct smatch_state *(unmatched_func_t)(struct sm_state *state); 1681f5207b7SJohn Levon void add_merge_hook(int client_id, merge_func_t *func); 1691f5207b7SJohn Levon void add_unmatched_state_hook(int client_id, unmatched_func_t *func); 170c85f09ccSJohn Levon void add_pre_merge_hook(int client_id, void (*hook)(struct sm_state *cur, struct sm_state *other)); 1711f5207b7SJohn Levon typedef void (scope_hook)(void *data); 1721f5207b7SJohn Levon void add_scope_hook(scope_hook *hook, void *data); 1731f5207b7SJohn Levon typedef void (func_hook)(const char *fn, struct expression *expr, void *data); 1741f5207b7SJohn Levon typedef void (implication_hook)(const char *fn, struct expression *call_expr, 1751f5207b7SJohn Levon struct expression *assign_expr, void *data); 1761f5207b7SJohn Levon typedef void (return_implies_hook)(struct expression *call_expr, 1771f5207b7SJohn Levon int param, char *key, char *value); 1781f5207b7SJohn Levon typedef int (implied_return_hook)(struct expression *call_expr, void *info, struct range_list **rl); 1791f5207b7SJohn Levon void add_function_hook(const char *look_for, func_hook *call_back, void *data); 1801f5207b7SJohn Levon 1811f5207b7SJohn Levon void add_function_assign_hook(const char *look_for, func_hook *call_back, 1821f5207b7SJohn Levon void *info); 1831f5207b7SJohn Levon void add_implied_return_hook(const char *look_for, 1841f5207b7SJohn Levon implied_return_hook *call_back, 1851f5207b7SJohn Levon void *info); 1861f5207b7SJohn Levon void add_macro_assign_hook(const char *look_for, func_hook *call_back, 1871f5207b7SJohn Levon void *info); 1881f5207b7SJohn Levon void add_macro_assign_hook_extra(const char *look_for, func_hook *call_back, 1891f5207b7SJohn Levon void *info); 1901f5207b7SJohn Levon void return_implies_state(const char *look_for, long long start, long long end, 1911f5207b7SJohn Levon implication_hook *call_back, void *info); 192efe51d0cSJohn Levon void return_implies_state_sval(const char *look_for, sval_t start, sval_t end, 193efe51d0cSJohn Levon implication_hook *call_back, void *info); 1941f5207b7SJohn Levon void select_return_states_hook(int type, return_implies_hook *callback); 1951f5207b7SJohn Levon void select_return_states_before(void (*fn)(void)); 1961f5207b7SJohn Levon void select_return_states_after(void (*fn)(void)); 1971f5207b7SJohn Levon int get_implied_return(struct expression *expr, struct range_list **rl); 1981f5207b7SJohn Levon void allocate_hook_memory(void); 1991f5207b7SJohn Levon 2001f5207b7SJohn Levon struct modification_data { 2011f5207b7SJohn Levon struct smatch_state *prev; 2021f5207b7SJohn Levon struct expression *cur; 2031f5207b7SJohn Levon }; 2041f5207b7SJohn Levon 2051f5207b7SJohn Levon typedef void (modification_hook)(struct sm_state *sm, struct expression *mod_expr); 2061f5207b7SJohn Levon void add_modification_hook(int owner, modification_hook *call_back); 2071f5207b7SJohn Levon void add_modification_hook_late(int owner, modification_hook *call_back); 2081f5207b7SJohn Levon struct smatch_state *get_modification_state(struct expression *expr); 2091f5207b7SJohn Levon 2101f5207b7SJohn Levon int outside_of_function(void); 2111f5207b7SJohn Levon const char *get_filename(void); 2121f5207b7SJohn Levon const char *get_base_file(void); 2131f5207b7SJohn Levon char *get_function(void); 2141f5207b7SJohn Levon int get_lineno(void); 2151f5207b7SJohn Levon extern int final_pass; 2161f5207b7SJohn Levon extern struct symbol *cur_func_sym; 2171f5207b7SJohn Levon extern int option_debug; 2181f5207b7SJohn Levon extern int local_debug; 2195a0e240fSJohn Levon extern int debug_db; 220c85f09ccSJohn Levon bool debug_implied(void); 2211f5207b7SJohn Levon extern int option_info; 2221f5207b7SJohn Levon extern int option_spammy; 2237ae7577cSJohn Levon extern int option_timeout; 2241f5207b7SJohn Levon extern char *trace_variable; 2251f5207b7SJohn Levon extern struct stree *global_states; 2261f5207b7SJohn Levon int is_skipped_function(void); 2271f5207b7SJohn Levon int is_silenced_function(void); 228efe51d0cSJohn Levon extern bool implications_off; 2291f5207b7SJohn Levon 2301f5207b7SJohn Levon /* smatch_impossible.c */ 2311f5207b7SJohn Levon int is_impossible_path(void); 2321f5207b7SJohn Levon void set_path_impossible(void); 2331f5207b7SJohn Levon 2341f5207b7SJohn Levon extern FILE *sm_outfd; 2351f5207b7SJohn Levon extern FILE *sql_outfd; 2361f5207b7SJohn Levon extern FILE *caller_info_fd; 2371f5207b7SJohn Levon extern int sm_nr_checks; 2381f5207b7SJohn Levon extern int sm_nr_errors; 2391f5207b7SJohn Levon extern const char *progname; 2401f5207b7SJohn Levon 2411f5207b7SJohn Levon /* 2421f5207b7SJohn Levon * How to use these routines: 2431f5207b7SJohn Levon * 2441f5207b7SJohn Levon * sm_fatal(): an internal error of some kind that should immediately exit 2451f5207b7SJohn Levon * sm_ierror(): an internal error 2461f5207b7SJohn Levon * sm_perror(): an internal error from parsing input source 2471f5207b7SJohn Levon * sm_error(): an error from input source 2481f5207b7SJohn Levon * sm_warning(): a warning from input source 2491f5207b7SJohn Levon * sm_info(): info message (from option_info) 2501f5207b7SJohn Levon * sm_debug(): debug message 2511f5207b7SJohn Levon * sm_msg(): other message (please avoid using this) 2521f5207b7SJohn Levon */ 2531f5207b7SJohn Levon 2545a0e240fSJohn Levon #define sm_printf(msg...) do { \ 2555a0e240fSJohn Levon if (final_pass || option_debug || local_debug || debug_db) \ 2565a0e240fSJohn Levon fprintf(sm_outfd, msg); \ 2575a0e240fSJohn Levon } while (0) 2581f5207b7SJohn Levon 2591f5207b7SJohn Levon static inline void sm_prefix(void) 2601f5207b7SJohn Levon { 2611f5207b7SJohn Levon sm_printf("%s: %s:%d %s() ", progname, get_filename(), get_lineno(), get_function()); 2621f5207b7SJohn Levon } 2631f5207b7SJohn Levon 2641f5207b7SJohn Levon static inline void print_implied_debug_msg(); 2651f5207b7SJohn Levon 2661f5207b7SJohn Levon extern bool __silence_warnings_for_stmt; 2671f5207b7SJohn Levon 2681f5207b7SJohn Levon #define sm_print_msg(type, msg...) \ 2691f5207b7SJohn Levon do { \ 2701f5207b7SJohn Levon print_implied_debug_msg(); \ 2715a0e240fSJohn Levon if (!final_pass && !option_debug && !local_debug && !debug_db) \ 2721f5207b7SJohn Levon break; \ 2731f5207b7SJohn Levon if (__silence_warnings_for_stmt && !option_debug && !local_debug) \ 2741f5207b7SJohn Levon break; \ 2751f5207b7SJohn Levon if (!option_info && is_silenced_function()) \ 2761f5207b7SJohn Levon break; \ 2771f5207b7SJohn Levon sm_prefix(); \ 2781f5207b7SJohn Levon if (type == 1) { \ 2791f5207b7SJohn Levon sm_printf("warn: "); \ 2801f5207b7SJohn Levon sm_nr_checks++; \ 2811f5207b7SJohn Levon } else if (type == 2) { \ 2821f5207b7SJohn Levon sm_printf("error: "); \ 2831f5207b7SJohn Levon sm_nr_checks++; \ 2841f5207b7SJohn Levon } else if (type == 3) { \ 2851f5207b7SJohn Levon sm_printf("parse error: "); \ 2861f5207b7SJohn Levon sm_nr_errors++; \ 2871f5207b7SJohn Levon } \ 2881f5207b7SJohn Levon sm_printf(msg); \ 2891f5207b7SJohn Levon sm_printf("\n"); \ 2901f5207b7SJohn Levon } while (0) 2911f5207b7SJohn Levon 2921f5207b7SJohn Levon #define sm_msg(msg...) do { sm_print_msg(0, msg); } while (0) 2931f5207b7SJohn Levon 2941f5207b7SJohn Levon extern char *implied_debug_msg; 2951f5207b7SJohn Levon static inline void print_implied_debug_msg(void) 2961f5207b7SJohn Levon { 2971f5207b7SJohn Levon static struct symbol *last_printed = NULL; 2981f5207b7SJohn Levon 2991f5207b7SJohn Levon if (!implied_debug_msg) 3001f5207b7SJohn Levon return; 3011f5207b7SJohn Levon if (last_printed == cur_func_sym) 3021f5207b7SJohn Levon return; 3031f5207b7SJohn Levon last_printed = cur_func_sym; 3041f5207b7SJohn Levon sm_msg("%s", implied_debug_msg); 3051f5207b7SJohn Levon } 3061f5207b7SJohn Levon 3071f5207b7SJohn Levon #define sm_debug(msg...) do { if (option_debug) sm_printf(msg); } while (0) 3085a0e240fSJohn Levon #define db_debug(msg...) do { if (option_debug || debug_db) sm_printf(msg); } while (0) 3091f5207b7SJohn Levon 3101f5207b7SJohn Levon #define sm_info(msg...) do { \ 3111f5207b7SJohn Levon if (option_debug || (option_info && final_pass)) { \ 3121f5207b7SJohn Levon sm_prefix(); \ 3131f5207b7SJohn Levon sm_printf("info: "); \ 3141f5207b7SJohn Levon sm_printf(msg); \ 3151f5207b7SJohn Levon sm_printf("\n"); \ 3161f5207b7SJohn Levon } \ 3171f5207b7SJohn Levon } while(0) 3181f5207b7SJohn Levon 3191f5207b7SJohn Levon #define sm_warning(msg...) do { sm_print_msg(1, msg); } while (0) 3201f5207b7SJohn Levon #define sm_error(msg...) do { sm_print_msg(2, msg); } while (0) 3211f5207b7SJohn Levon #define sm_perror(msg...) do { sm_print_msg(3, msg); } while (0) 3221f5207b7SJohn Levon 3231f5207b7SJohn Levon static inline void sm_fatal(const char *fmt, ...) 3241f5207b7SJohn Levon { 3251f5207b7SJohn Levon va_list args; 3261f5207b7SJohn Levon 3271f5207b7SJohn Levon va_start(args, fmt); 3281f5207b7SJohn Levon vfprintf(sm_outfd, fmt, args); 3291f5207b7SJohn Levon va_end(args); 3301f5207b7SJohn Levon 3311f5207b7SJohn Levon fprintf(sm_outfd, "\n"); 3321f5207b7SJohn Levon 3331f5207b7SJohn Levon exit(1); 3341f5207b7SJohn Levon } 3351f5207b7SJohn Levon 3361f5207b7SJohn Levon static inline void sm_ierror(const char *fmt, ...) 3371f5207b7SJohn Levon { 3381f5207b7SJohn Levon va_list args; 3391f5207b7SJohn Levon 3401f5207b7SJohn Levon sm_nr_errors++; 3411f5207b7SJohn Levon 3421f5207b7SJohn Levon fprintf(sm_outfd, "internal error: "); 3431f5207b7SJohn Levon 3441f5207b7SJohn Levon va_start(args, fmt); 3451f5207b7SJohn Levon vfprintf(sm_outfd, fmt, args); 3461f5207b7SJohn Levon va_end(args); 3471f5207b7SJohn Levon 3481f5207b7SJohn Levon fprintf(sm_outfd, "\n"); 3491f5207b7SJohn Levon } 3501f5207b7SJohn Levon #define ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1)) 3511f5207b7SJohn Levon 3521f5207b7SJohn Levon struct smatch_state *__get_state(int owner, const char *name, struct symbol *sym); 3531f5207b7SJohn Levon struct smatch_state *get_state(int owner, const char *name, struct symbol *sym); 3541f5207b7SJohn Levon struct smatch_state *get_state_expr(int owner, struct expression *expr); 3551f5207b7SJohn Levon struct state_list *get_possible_states(int owner, const char *name, 3561f5207b7SJohn Levon struct symbol *sym); 3571f5207b7SJohn Levon struct state_list *get_possible_states_expr(int owner, struct expression *expr); 3581f5207b7SJohn Levon struct sm_state *set_state(int owner, const char *name, struct symbol *sym, 3591f5207b7SJohn Levon struct smatch_state *state); 3601f5207b7SJohn Levon struct sm_state *set_state_expr(int owner, struct expression *expr, 3611f5207b7SJohn Levon struct smatch_state *state); 3621f5207b7SJohn Levon void delete_state(int owner, const char *name, struct symbol *sym); 3631f5207b7SJohn Levon void delete_state_expr(int owner, struct expression *expr); 3641f5207b7SJohn Levon void __delete_all_states_sym(struct symbol *sym); 3651f5207b7SJohn Levon void set_true_false_states(int owner, const char *name, struct symbol *sym, 3661f5207b7SJohn Levon struct smatch_state *true_state, 3671f5207b7SJohn Levon struct smatch_state *false_state); 3681f5207b7SJohn Levon void set_true_false_states_expr(int owner, struct expression *expr, 3691f5207b7SJohn Levon struct smatch_state *true_state, 3701f5207b7SJohn Levon struct smatch_state *false_state); 3711f5207b7SJohn Levon 3721f5207b7SJohn Levon struct stree *get_all_states_from_stree(int owner, struct stree *source); 3731f5207b7SJohn Levon struct stree *get_all_states_stree(int id); 3741f5207b7SJohn Levon struct stree *__get_cur_stree(void); 3751f5207b7SJohn Levon int is_reachable(void); 3761f5207b7SJohn Levon void add_get_state_hook(void (*fn)(int owner, const char *name, struct symbol *sym)); 3771f5207b7SJohn Levon 3781f5207b7SJohn Levon /* smatch_helper.c */ 3791f5207b7SJohn Levon DECLARE_PTR_LIST(int_stack, int); 3801f5207b7SJohn Levon char *alloc_string(const char *str); 381c85f09ccSJohn Levon char *alloc_string_newline(const char *str); 3821f5207b7SJohn Levon void free_string(char *str); 3831f5207b7SJohn Levon void append(char *dest, const char *data, int buff_len); 3841f5207b7SJohn Levon void remove_parens(char *str); 3851f5207b7SJohn Levon struct smatch_state *alloc_state_num(int num); 3861f5207b7SJohn Levon struct smatch_state *alloc_state_str(const char *name); 387efe51d0cSJohn Levon struct smatch_state *merge_str_state(struct smatch_state *s1, struct smatch_state *s2); 3881f5207b7SJohn Levon struct smatch_state *alloc_state_expr(struct expression *expr); 3891f5207b7SJohn Levon struct expression *get_argument_from_call_expr(struct expression_list *args, 3901f5207b7SJohn Levon int num); 3911f5207b7SJohn Levon 3921f5207b7SJohn Levon char *expr_to_var(struct expression *expr); 3931f5207b7SJohn Levon struct symbol *expr_to_sym(struct expression *expr); 3941f5207b7SJohn Levon char *expr_to_str(struct expression *expr); 3951f5207b7SJohn Levon char *expr_to_str_sym(struct expression *expr, 3961f5207b7SJohn Levon struct symbol **sym_ptr); 3971f5207b7SJohn Levon char *expr_to_var_sym(struct expression *expr, 3981f5207b7SJohn Levon struct symbol **sym_ptr); 3991f5207b7SJohn Levon char *expr_to_known_chunk_sym(struct expression *expr, struct symbol **sym); 4001f5207b7SJohn Levon char *expr_to_chunk_sym_vsl(struct expression *expr, struct symbol **sym, struct var_sym_list **vsl); 4011f5207b7SJohn Levon int get_complication_score(struct expression *expr); 4021f5207b7SJohn Levon 4031f5207b7SJohn Levon int sym_name_is(const char *name, struct expression *expr); 4041f5207b7SJohn Levon int get_const_value(struct expression *expr, sval_t *sval); 4051f5207b7SJohn Levon int get_value(struct expression *expr, sval_t *val); 4061f5207b7SJohn Levon int get_implied_value(struct expression *expr, sval_t *val); 407*31ad075eSJohn Levon int get_implied_value_fast(struct expression *expr, sval_t *sval); 4081f5207b7SJohn Levon int get_implied_min(struct expression *expr, sval_t *sval); 4091f5207b7SJohn Levon int get_implied_max(struct expression *expr, sval_t *val); 4101f5207b7SJohn Levon int get_hard_max(struct expression *expr, sval_t *sval); 4111f5207b7SJohn Levon int get_fuzzy_min(struct expression *expr, sval_t *min); 4121f5207b7SJohn Levon int get_fuzzy_max(struct expression *expr, sval_t *max); 4131f5207b7SJohn Levon int get_absolute_min(struct expression *expr, sval_t *sval); 4141f5207b7SJohn Levon int get_absolute_max(struct expression *expr, sval_t *sval); 4151f5207b7SJohn Levon int parse_call_math(struct expression *expr, char *math, sval_t *val); 416efe51d0cSJohn Levon int parse_call_math_rl(struct expression *call, const char *math, struct range_list **rl); 417c85f09ccSJohn Levon const char *get_allocation_math(struct expression *expr); 4181f5207b7SJohn Levon char *get_value_in_terms_of_parameter_math(struct expression *expr); 4191f5207b7SJohn Levon char *get_value_in_terms_of_parameter_math_var_sym(const char *var, struct symbol *sym); 420c85f09ccSJohn Levon int expr_is_zero(struct expression *expr); 4211f5207b7SJohn Levon int known_condition_true(struct expression *expr); 4221f5207b7SJohn Levon int known_condition_false(struct expression *expr); 4231f5207b7SJohn Levon int implied_condition_true(struct expression *expr); 4241f5207b7SJohn Levon int implied_condition_false(struct expression *expr); 4251f5207b7SJohn Levon int can_integer_overflow(struct symbol *type, struct expression *expr); 4261f5207b7SJohn Levon void clear_math_cache(void); 427c85f09ccSJohn Levon void set_fast_math_only(void); 428c85f09ccSJohn Levon void clear_fast_math_only(void); 4291f5207b7SJohn Levon 4301f5207b7SJohn Levon int is_array(struct expression *expr); 4311f5207b7SJohn Levon struct expression *get_array_base(struct expression *expr); 4321f5207b7SJohn Levon struct expression *get_array_offset(struct expression *expr); 4331f5207b7SJohn Levon const char *show_state(struct smatch_state *state); 4341f5207b7SJohn Levon struct statement *get_expression_statement(struct expression *expr); 4351f5207b7SJohn Levon struct expression *strip_parens(struct expression *expr); 4361f5207b7SJohn Levon struct expression *strip_expr(struct expression *expr); 4371f5207b7SJohn Levon struct expression *strip_expr_set_parent(struct expression *expr); 4381f5207b7SJohn Levon void scoped_state(int my_id, const char *name, struct symbol *sym); 4391f5207b7SJohn Levon int is_error_return(struct expression *expr); 440c85f09ccSJohn Levon int getting_address(struct expression *expr); 4411f5207b7SJohn Levon int get_struct_and_member(struct expression *expr, const char **type, const char **member); 4421f5207b7SJohn Levon char *get_member_name(struct expression *expr); 4431f5207b7SJohn Levon char *get_fnptr_name(struct expression *expr); 4441f5207b7SJohn Levon int cmp_pos(struct position pos1, struct position pos2); 4451f5207b7SJohn Levon int positions_eq(struct position pos1, struct position pos2); 4461f5207b7SJohn Levon struct statement *get_current_statement(void); 4471f5207b7SJohn Levon struct statement *get_prev_statement(void); 4481f5207b7SJohn Levon struct expression *get_last_expr_from_expression_stmt(struct expression *expr); 4491f5207b7SJohn Levon int get_param_num_from_sym(struct symbol *sym); 4501f5207b7SJohn Levon int get_param_num(struct expression *expr); 4515a0e240fSJohn Levon struct symbol *get_param_sym_from_num(int num); 4521f5207b7SJohn Levon int ms_since(struct timeval *start); 4531f5207b7SJohn Levon int parent_is_gone_var_sym(const char *name, struct symbol *sym); 4541f5207b7SJohn Levon int parent_is_gone(struct expression *expr); 4551f5207b7SJohn Levon int invert_op(int op); 456efe51d0cSJohn Levon int op_remove_assign(int op); 4571f5207b7SJohn Levon int expr_equiv(struct expression *one, struct expression *two); 4581f5207b7SJohn Levon void push_int(struct int_stack **stack, int num); 4591f5207b7SJohn Levon int pop_int(struct int_stack **stack); 4601f5207b7SJohn Levon 4611f5207b7SJohn Levon /* smatch_type.c */ 4621f5207b7SJohn Levon struct symbol *get_real_base_type(struct symbol *sym); 4631f5207b7SJohn Levon int type_bytes(struct symbol *type); 4641f5207b7SJohn Levon int array_bytes(struct symbol *type); 4651f5207b7SJohn Levon struct symbol *get_pointer_type(struct expression *expr); 4661f5207b7SJohn Levon struct symbol *get_type(struct expression *expr); 4671f5207b7SJohn Levon struct symbol *get_final_type(struct expression *expr); 4681f5207b7SJohn Levon struct symbol *get_promoted_type(struct symbol *left, struct symbol *right); 4691f5207b7SJohn Levon int type_signed(struct symbol *base_type); 4701f5207b7SJohn Levon int expr_unsigned(struct expression *expr); 4711f5207b7SJohn Levon int expr_signed(struct expression *expr); 4721f5207b7SJohn Levon int returns_unsigned(struct symbol *base_type); 4731f5207b7SJohn Levon int is_pointer(struct expression *expr); 4741f5207b7SJohn Levon int returns_pointer(struct symbol *base_type); 4751f5207b7SJohn Levon sval_t sval_type_max(struct symbol *base_type); 4761f5207b7SJohn Levon sval_t sval_type_min(struct symbol *base_type); 4771f5207b7SJohn Levon int nr_bits(struct expression *expr); 4781f5207b7SJohn Levon int is_void_pointer(struct expression *expr); 4791f5207b7SJohn Levon int is_char_pointer(struct expression *expr); 4801f5207b7SJohn Levon int is_string(struct expression *expr); 4811f5207b7SJohn Levon int is_static(struct expression *expr); 482c85f09ccSJohn Levon bool is_local_variable(struct expression *expr); 4831f5207b7SJohn Levon int types_equiv(struct symbol *one, struct symbol *two); 4841f5207b7SJohn Levon int fn_static(void); 4851f5207b7SJohn Levon const char *global_static(); 4861f5207b7SJohn Levon struct symbol *cur_func_return_type(void); 4871f5207b7SJohn Levon struct symbol *get_arg_type(struct expression *fn, int arg); 4881f5207b7SJohn Levon struct symbol *get_member_type_from_key(struct expression *expr, const char *key); 4891f5207b7SJohn Levon struct symbol *get_arg_type_from_key(struct expression *fn, int param, struct expression *arg, const char *key); 4901f5207b7SJohn Levon int is_struct(struct expression *expr); 4911f5207b7SJohn Levon char *type_to_str(struct symbol *type); 4921f5207b7SJohn Levon 4931f5207b7SJohn Levon /* smatch_ignore.c */ 4941f5207b7SJohn Levon void add_ignore(int owner, const char *name, struct symbol *sym); 4951f5207b7SJohn Levon int is_ignored(int owner, const char *name, struct symbol *sym); 4961f5207b7SJohn Levon void add_ignore_expr(int owner, struct expression *expr); 4971f5207b7SJohn Levon int is_ignored_expr(int owner, struct expression *expr); 4981f5207b7SJohn Levon 4991f5207b7SJohn Levon /* smatch_var_sym */ 5001f5207b7SJohn Levon struct var_sym *alloc_var_sym(const char *var, struct symbol *sym); 5011f5207b7SJohn Levon struct var_sym_list *expr_to_vsl(struct expression *expr); 5021f5207b7SJohn Levon void add_var_sym(struct var_sym_list **list, const char *var, struct symbol *sym); 5031f5207b7SJohn Levon void add_var_sym_expr(struct var_sym_list **list, struct expression *expr); 5041f5207b7SJohn Levon void del_var_sym(struct var_sym_list **list, const char *var, struct symbol *sym); 5051f5207b7SJohn Levon int in_var_sym_list(struct var_sym_list *list, const char *var, struct symbol *sym); 5061f5207b7SJohn Levon struct var_sym_list *clone_var_sym_list(struct var_sym_list *from_vsl); 5071f5207b7SJohn Levon void merge_var_sym_list(struct var_sym_list **dest, struct var_sym_list *src); 5081f5207b7SJohn Levon struct var_sym_list *combine_var_sym_lists(struct var_sym_list *one, struct var_sym_list *two); 5091f5207b7SJohn Levon int var_sym_lists_equiv(struct var_sym_list *one, struct var_sym_list *two); 5101f5207b7SJohn Levon void free_var_sym_list(struct var_sym_list **list); 5111f5207b7SJohn Levon void free_var_syms_and_list(struct var_sym_list **list); 5121f5207b7SJohn Levon 5131f5207b7SJohn Levon /* smatch_tracker */ 5141f5207b7SJohn Levon struct tracker *alloc_tracker(int owner, const char *name, struct symbol *sym); 5151f5207b7SJohn Levon void add_tracker(struct tracker_list **list, int owner, const char *name, 5161f5207b7SJohn Levon struct symbol *sym); 5171f5207b7SJohn Levon void add_tracker_expr(struct tracker_list **list, int owner, struct expression *expr); 5181f5207b7SJohn Levon void del_tracker(struct tracker_list **list, int owner, const char *name, 5191f5207b7SJohn Levon struct symbol *sym); 5201f5207b7SJohn Levon int in_tracker_list(struct tracker_list *list, int owner, const char *name, 5211f5207b7SJohn Levon struct symbol *sym); 5221f5207b7SJohn Levon void free_tracker_list(struct tracker_list **list); 5231f5207b7SJohn Levon void free_trackers_and_list(struct tracker_list **list); 5241f5207b7SJohn Levon 5251f5207b7SJohn Levon /* smatch_conditions */ 5261f5207b7SJohn Levon int in_condition(void); 5271f5207b7SJohn Levon 5281f5207b7SJohn Levon /* smatch_flow.c */ 5291f5207b7SJohn Levon 5301f5207b7SJohn Levon extern int __in_fake_assign; 5311f5207b7SJohn Levon extern int __in_fake_parameter_assign; 5321f5207b7SJohn Levon extern int __in_fake_struct_assign; 5331f5207b7SJohn Levon extern int in_fake_env; 534efe51d0cSJohn Levon void smatch (struct string_list *filelist); 5351f5207b7SJohn Levon int inside_loop(void); 5361f5207b7SJohn Levon int definitely_inside_loop(void); 5371f5207b7SJohn Levon struct expression *get_switch_expr(void); 5381f5207b7SJohn Levon int in_expression_statement(void); 5391f5207b7SJohn Levon void __process_post_op_stack(void); 5401f5207b7SJohn Levon void __split_expr(struct expression *expr); 5411f5207b7SJohn Levon void __split_label_stmt(struct statement *stmt); 5421f5207b7SJohn Levon void __split_stmt(struct statement *stmt); 5431f5207b7SJohn Levon extern int __in_function_def; 544c85f09ccSJohn Levon extern int __in_unmatched_hook; 5451f5207b7SJohn Levon extern int option_assume_loops; 5461f5207b7SJohn Levon extern int option_two_passes; 5471f5207b7SJohn Levon extern int option_no_db; 5481f5207b7SJohn Levon extern int option_file_output; 5491f5207b7SJohn Levon extern int option_time; 5501f5207b7SJohn Levon extern struct expression_list *big_expression_stack; 5511f5207b7SJohn Levon extern struct expression_list *big_condition_stack; 5521f5207b7SJohn Levon extern struct statement_list *big_statement_stack; 5531f5207b7SJohn Levon int is_assigned_call(struct expression *expr); 5541f5207b7SJohn Levon int inlinable(struct expression *expr); 5551f5207b7SJohn Levon extern int __inline_call; 5561f5207b7SJohn Levon extern struct expression *__inline_fn; 5571f5207b7SJohn Levon extern int __in_pre_condition; 5581f5207b7SJohn Levon extern int __bail_on_rest_of_function; 5591f5207b7SJohn Levon extern struct statement *__prev_stmt; 5601f5207b7SJohn Levon extern struct statement *__cur_stmt; 5611f5207b7SJohn Levon extern struct statement *__next_stmt; 5621f5207b7SJohn Levon void init_fake_env(void); 5631f5207b7SJohn Levon void end_fake_env(void); 5641f5207b7SJohn Levon int time_parsing_function(void); 565efe51d0cSJohn Levon bool taking_too_long(void); 5661f5207b7SJohn Levon 5671f5207b7SJohn Levon /* smatch_struct_assignment.c */ 5681f5207b7SJohn Levon struct expression *get_faked_expression(void); 5691f5207b7SJohn Levon void __fake_struct_member_assignments(struct expression *expr); 5701f5207b7SJohn Levon 5711f5207b7SJohn Levon /* smatch_project.c */ 5721f5207b7SJohn Levon int is_no_inline_function(const char *function); 5731f5207b7SJohn Levon 5741f5207b7SJohn Levon /* smatch_conditions */ 5751f5207b7SJohn Levon void __split_whole_condition(struct expression *expr); 5761f5207b7SJohn Levon void __handle_logic(struct expression *expr); 5771f5207b7SJohn Levon int is_condition(struct expression *expr); 5781f5207b7SJohn Levon int __handle_condition_assigns(struct expression *expr); 5791f5207b7SJohn Levon int __handle_select_assigns(struct expression *expr); 5801f5207b7SJohn Levon int __handle_expr_statement_assigns(struct expression *expr); 5811f5207b7SJohn Levon 5821f5207b7SJohn Levon /* smatch_implied.c */ 5831f5207b7SJohn Levon struct range_list_stack; 5841f5207b7SJohn Levon void param_limit_implications(struct expression *expr, int param, char *key, char *value); 5851f5207b7SJohn Levon struct stree *__implied_case_stree(struct expression *switch_expr, 5861f5207b7SJohn Levon struct range_list *case_rl, 5871f5207b7SJohn Levon struct range_list_stack **remaining_cases, 5881f5207b7SJohn Levon struct stree **raw_stree); 5891f5207b7SJohn Levon void overwrite_states_using_pool(struct sm_state *gate_sm, struct sm_state *pool_sm); 5901f5207b7SJohn Levon int assume(struct expression *expr); 5911f5207b7SJohn Levon void end_assume(void); 5921f5207b7SJohn Levon int impossible_assumption(struct expression *left, int op, sval_t sval); 5931f5207b7SJohn Levon 594efe51d0cSJohn Levon /* smatch_slist.h */ 595efe51d0cSJohn Levon bool has_dynamic_states(unsigned short owner); 596efe51d0cSJohn Levon void set_dynamic_states(unsigned short owner); 597efe51d0cSJohn Levon 5981f5207b7SJohn Levon /* smatch_extras.c */ 599efe51d0cSJohn Levon int in_warn_on_macro(void); 6001f5207b7SJohn Levon #define SMATCH_EXTRA 5 /* this is my_id from smatch extra set in smatch.c */ 6011f5207b7SJohn Levon extern int RETURN_ID; 6021f5207b7SJohn Levon 6031f5207b7SJohn Levon struct data_range { 6041f5207b7SJohn Levon sval_t min; 6051f5207b7SJohn Levon sval_t max; 6061f5207b7SJohn Levon }; 6071f5207b7SJohn Levon 6081f5207b7SJohn Levon #define MTAG_ALIAS_BIT (1ULL << 63) 6091f5207b7SJohn Levon #define MTAG_OFFSET_MASK 0xfffULL 610efe51d0cSJohn Levon #define MTAG_SEED 0xdead << 12 6111f5207b7SJohn Levon 612efe51d0cSJohn Levon const extern unsigned long valid_ptr_min; 613efe51d0cSJohn Levon extern unsigned long valid_ptr_max; 614efe51d0cSJohn Levon extern const sval_t valid_ptr_min_sval; 615efe51d0cSJohn Levon extern sval_t valid_ptr_max_sval; 6161f5207b7SJohn Levon extern struct range_list *valid_ptr_rl; 617efe51d0cSJohn Levon void alloc_valid_ptr_rl(void); 618efe51d0cSJohn Levon 6191f5207b7SJohn Levon static const sval_t array_min_sval = { 6201f5207b7SJohn Levon .type = &ptr_ctype, 6211f5207b7SJohn Levon {.value = 100000}, 6221f5207b7SJohn Levon }; 6231f5207b7SJohn Levon static const sval_t array_max_sval = { 6241f5207b7SJohn Levon .type = &ptr_ctype, 625efe51d0cSJohn Levon {.value = ULONG_MAX - 4095}, 6261f5207b7SJohn Levon }; 6271f5207b7SJohn Levon static const sval_t text_seg_min = { 6281f5207b7SJohn Levon .type = &ptr_ctype, 629efe51d0cSJohn Levon {.value = 4096}, 6301f5207b7SJohn Levon }; 6311f5207b7SJohn Levon static const sval_t text_seg_max = { 6321f5207b7SJohn Levon .type = &ptr_ctype, 633efe51d0cSJohn Levon {.value = ULONG_MAX - 4095}, 6341f5207b7SJohn Levon }; 6351f5207b7SJohn Levon static const sval_t data_seg_min = { 6361f5207b7SJohn Levon .type = &ptr_ctype, 637efe51d0cSJohn Levon {.value = 4096}, 6381f5207b7SJohn Levon }; 6391f5207b7SJohn Levon static const sval_t data_seg_max = { 6401f5207b7SJohn Levon .type = &ptr_ctype, 641efe51d0cSJohn Levon {.value = ULONG_MAX - 4095}, 6421f5207b7SJohn Levon }; 6431f5207b7SJohn Levon static const sval_t bss_seg_min = { 6441f5207b7SJohn Levon .type = &ptr_ctype, 645efe51d0cSJohn Levon {.value = 4096}, 6461f5207b7SJohn Levon }; 6471f5207b7SJohn Levon static const sval_t bss_seg_max = { 6481f5207b7SJohn Levon .type = &ptr_ctype, 649efe51d0cSJohn Levon {.value = ULONG_MAX - 4095}, 6501f5207b7SJohn Levon }; 6511f5207b7SJohn Levon static const sval_t stack_seg_min = { 6521f5207b7SJohn Levon .type = &ptr_ctype, 653efe51d0cSJohn Levon {.value = 4096}, 6541f5207b7SJohn Levon }; 6551f5207b7SJohn Levon static const sval_t stack_seg_max = { 6561f5207b7SJohn Levon .type = &ptr_ctype, 657efe51d0cSJohn Levon {.value = ULONG_MAX - 4095}, 6581f5207b7SJohn Levon }; 6591f5207b7SJohn Levon static const sval_t kmalloc_seg_min = { 6601f5207b7SJohn Levon .type = &ptr_ctype, 661efe51d0cSJohn Levon {.value = 4096}, 6621f5207b7SJohn Levon }; 6631f5207b7SJohn Levon static const sval_t kmalloc_seg_max = { 6641f5207b7SJohn Levon .type = &ptr_ctype, 665efe51d0cSJohn Levon {.value = ULONG_MAX - 4095}, 6661f5207b7SJohn Levon }; 6671f5207b7SJohn Levon static const sval_t vmalloc_seg_min = { 6681f5207b7SJohn Levon .type = &ptr_ctype, 669efe51d0cSJohn Levon {.value = 4096}, 6701f5207b7SJohn Levon }; 6711f5207b7SJohn Levon static const sval_t vmalloc_seg_max = { 6721f5207b7SJohn Levon .type = &ptr_ctype, 673efe51d0cSJohn Levon {.value = ULONG_MAX - 4095}, 6741f5207b7SJohn Levon }; 6751f5207b7SJohn Levon static const sval_t fn_ptr_min = { 6761f5207b7SJohn Levon .type = &ptr_ctype, 677efe51d0cSJohn Levon {.value = 4096}, 6781f5207b7SJohn Levon }; 6791f5207b7SJohn Levon static const sval_t fn_ptr_max = { 6801f5207b7SJohn Levon .type = &ptr_ctype, 681efe51d0cSJohn Levon {.value = ULONG_MAX - 4095}, 6821f5207b7SJohn Levon }; 6831f5207b7SJohn Levon 6841f5207b7SJohn Levon char *get_other_name_sym(const char *name, struct symbol *sym, struct symbol **new_sym); 6851f5207b7SJohn Levon char *map_call_to_other_name_sym(const char *name, struct symbol *sym, struct symbol **new_sym); 686efe51d0cSJohn Levon char *map_long_to_short_name_sym(const char *name, struct symbol *sym, struct symbol **new_sym, bool use_stack); 6871f5207b7SJohn Levon 6881f5207b7SJohn Levon #define STRLEN_MAX_RET 1010101 6891f5207b7SJohn Levon 6901f5207b7SJohn Levon /* smatch_absolute.c */ 6911f5207b7SJohn Levon int get_absolute_min_helper(struct expression *expr, sval_t *sval); 6921f5207b7SJohn Levon int get_absolute_max_helper(struct expression *expr, sval_t *sval); 6931f5207b7SJohn Levon 6941f5207b7SJohn Levon /* smatch_type_value.c */ 6951f5207b7SJohn Levon int get_db_type_rl(struct expression *expr, struct range_list **rl); 6961f5207b7SJohn Levon /* smatch_data_val.c */ 6971f5207b7SJohn Levon int get_mtag_rl(struct expression *expr, struct range_list **rl); 6981f5207b7SJohn Levon /* smatch_array_values.c */ 6991f5207b7SJohn Levon int get_array_rl(struct expression *expr, struct range_list **rl); 7001f5207b7SJohn Levon 7011f5207b7SJohn Levon /* smatch_states.c */ 702c85f09ccSJohn Levon struct stree *__swap_cur_stree(struct stree *stree); 7031f5207b7SJohn Levon void __push_fake_cur_stree(); 7041f5207b7SJohn Levon struct stree *__pop_fake_cur_stree(); 7051f5207b7SJohn Levon void __free_fake_cur_stree(); 7061f5207b7SJohn Levon void __set_fake_cur_stree_fast(struct stree *stree); 7071f5207b7SJohn Levon void __pop_fake_cur_stree_fast(void); 7081f5207b7SJohn Levon void __merge_stree_into_cur(struct stree *stree); 7091f5207b7SJohn Levon 7101f5207b7SJohn Levon int unreachable(void); 711c85f09ccSJohn Levon void __set_cur_stree_readonly(void); 712c85f09ccSJohn Levon void __set_cur_stree_writable(void); 7131f5207b7SJohn Levon void __set_sm(struct sm_state *sm); 7141f5207b7SJohn Levon void __set_sm_cur_stree(struct sm_state *sm); 7151f5207b7SJohn Levon void __set_sm_fake_stree(struct sm_state *sm); 7161f5207b7SJohn Levon void __set_true_false_sm(struct sm_state *true_state, 7171f5207b7SJohn Levon struct sm_state *false_state); 7181f5207b7SJohn Levon void nullify_path(void); 7191f5207b7SJohn Levon void __match_nullify_path_hook(const char *fn, struct expression *expr, 7201f5207b7SJohn Levon void *unused); 7211f5207b7SJohn Levon void __unnullify_path(void); 7221f5207b7SJohn Levon int __path_is_null(void); 7231f5207b7SJohn Levon void save_all_states(void); 7241f5207b7SJohn Levon void restore_all_states(void); 7251f5207b7SJohn Levon void free_goto_stack(void); 7261f5207b7SJohn Levon void clear_all_states(void); 7271f5207b7SJohn Levon 7281f5207b7SJohn Levon struct sm_state *get_sm_state(int owner, const char *name, 7291f5207b7SJohn Levon struct symbol *sym); 7301f5207b7SJohn Levon struct sm_state *get_sm_state_expr(int owner, struct expression *expr); 7311f5207b7SJohn Levon void __push_true_states(void); 7321f5207b7SJohn Levon void __use_false_states(void); 7331f5207b7SJohn Levon void __discard_false_states(void); 7341f5207b7SJohn Levon void __merge_false_states(void); 7351f5207b7SJohn Levon void __merge_true_states(void); 7361f5207b7SJohn Levon 7371f5207b7SJohn Levon void __negate_cond_stacks(void); 7381f5207b7SJohn Levon void __use_pre_cond_states(void); 7391f5207b7SJohn Levon void __use_cond_true_states(void); 7401f5207b7SJohn Levon void __use_cond_false_states(void); 7411f5207b7SJohn Levon void __push_cond_stacks(void); 7421f5207b7SJohn Levon void __fold_in_set_states(void); 7431f5207b7SJohn Levon void __free_set_states(void); 7441f5207b7SJohn Levon struct stree *__copy_cond_true_states(void); 7451f5207b7SJohn Levon struct stree *__copy_cond_false_states(void); 7461f5207b7SJohn Levon struct stree *__pop_cond_true_stack(void); 7471f5207b7SJohn Levon struct stree *__pop_cond_false_stack(void); 7481f5207b7SJohn Levon void __and_cond_states(void); 7491f5207b7SJohn Levon void __or_cond_states(void); 7501f5207b7SJohn Levon void __save_pre_cond_states(void); 7511f5207b7SJohn Levon void __discard_pre_cond_states(void); 7521f5207b7SJohn Levon struct stree *__get_true_states(void); 7531f5207b7SJohn Levon struct stree *__get_false_states(void); 7541f5207b7SJohn Levon void __use_cond_states(void); 7551f5207b7SJohn Levon extern struct state_list *__last_base_slist; 7561f5207b7SJohn Levon 7571f5207b7SJohn Levon void __push_continues(void); 7581f5207b7SJohn Levon void __discard_continues(void); 7591f5207b7SJohn Levon void __process_continues(void); 7601f5207b7SJohn Levon void __merge_continues(void); 7611f5207b7SJohn Levon 7621f5207b7SJohn Levon void __push_breaks(void); 7631f5207b7SJohn Levon void __process_breaks(void); 7641f5207b7SJohn Levon int __has_breaks(void); 7651f5207b7SJohn Levon void __merge_breaks(void); 7661f5207b7SJohn Levon void __use_breaks(void); 7671f5207b7SJohn Levon 7681f5207b7SJohn Levon void __save_switch_states(struct expression *switch_expr); 7691f5207b7SJohn Levon void __discard_switches(void); 7701f5207b7SJohn Levon int have_remaining_cases(void); 7711f5207b7SJohn Levon void __merge_switches(struct expression *switch_expr, struct range_list *case_rl); 7721f5207b7SJohn Levon void __push_default(void); 7731f5207b7SJohn Levon void __set_default(void); 7741f5207b7SJohn Levon int __pop_default(void); 7751f5207b7SJohn Levon 7761f5207b7SJohn Levon void __push_conditions(void); 7771f5207b7SJohn Levon void __discard_conditions(void); 7781f5207b7SJohn Levon 7791f5207b7SJohn Levon void __save_gotos(const char *name, struct symbol *sym); 7801f5207b7SJohn Levon void __merge_gotos(const char *name, struct symbol *sym); 7811f5207b7SJohn Levon 7821f5207b7SJohn Levon void __print_cur_stree(void); 7831f5207b7SJohn Levon 7841f5207b7SJohn Levon /* smatch_hooks.c */ 7851f5207b7SJohn Levon void __pass_to_client(void *data, enum hook_type type); 7861f5207b7SJohn Levon void __pass_case_to_client(struct expression *switch_expr, 7871f5207b7SJohn Levon struct range_list *rl); 7881f5207b7SJohn Levon int __has_merge_function(int client_id); 7891f5207b7SJohn Levon struct smatch_state *__client_merge_function(int owner, 7901f5207b7SJohn Levon struct smatch_state *s1, 7911f5207b7SJohn Levon struct smatch_state *s2); 7921f5207b7SJohn Levon struct smatch_state *__client_unmatched_state_function(struct sm_state *sm); 793c85f09ccSJohn Levon void call_pre_merge_hook(struct sm_state *cur, struct sm_state *other); 7941f5207b7SJohn Levon void __push_scope_hooks(void); 7951f5207b7SJohn Levon void __call_scope_hooks(void); 7961f5207b7SJohn Levon 7971f5207b7SJohn Levon /* smatch_function_hooks.c */ 7981f5207b7SJohn Levon void create_function_hook_hash(void); 7991f5207b7SJohn Levon void __match_initializer_call(struct symbol *sym); 8001f5207b7SJohn Levon 8011f5207b7SJohn Levon /* smatch_db.c */ 8021f5207b7SJohn Levon enum info_type { 8031f5207b7SJohn Levon INTERNAL = 0, 8041f5207b7SJohn Levon /* 8051f5207b7SJohn Levon * Changing these numbers is a pain. Don't do it. If you ever use a 8061f5207b7SJohn Levon * number it can't be re-used right away so there may be gaps. 8071f5207b7SJohn Levon * We select these in order by type so if the order matters, then give 8081f5207b7SJohn Levon * it a number below 100-999,9000-9999 ranges. */ 8091f5207b7SJohn Levon 8101f5207b7SJohn Levon PARAM_CLEARED = 101, 8111f5207b7SJohn Levon PARAM_LIMIT = 103, 8121f5207b7SJohn Levon PARAM_FILTER = 104, 8131f5207b7SJohn Levon 8141f5207b7SJohn Levon PARAM_VALUE = 1001, 8151f5207b7SJohn Levon BUF_SIZE = 1002, 8161f5207b7SJohn Levon CAPPED_DATA = 1004, 8171f5207b7SJohn Levon RETURN_VALUE = 1005, 8181f5207b7SJohn Levon DEREFERENCE = 1006, 8191f5207b7SJohn Levon RANGE_CAP = 1007, 8201f5207b7SJohn Levon ABSOLUTE_LIMITS = 1010, 8211f5207b7SJohn Levon PARAM_ADD = 1012, 8221f5207b7SJohn Levon PARAM_FREED = 1013, 8231f5207b7SJohn Levon DATA_SOURCE = 1014, 8241f5207b7SJohn Levon FUZZY_MAX = 1015, 825efe51d0cSJohn Levon HARD_MAX = 2015, 8261f5207b7SJohn Levon STR_LEN = 1016, 8271f5207b7SJohn Levon ARRAY_LEN = 1017, 8281f5207b7SJohn Levon CAPABLE = 1018, 8291f5207b7SJohn Levon NS_CAPABLE = 1019, 8301f5207b7SJohn Levon CONTAINER = 1020, 8311f5207b7SJohn Levon CASTED_CALL = 1021, 8321f5207b7SJohn Levon TYPE_LINK = 1022, 8331f5207b7SJohn Levon UNTRACKED_PARAM = 1023, 834efe51d0cSJohn Levon LOST_PARAM = 2023, 8351f5207b7SJohn Levon CULL_PATH = 1024, 8361f5207b7SJohn Levon PARAM_SET = 1025, 8371f5207b7SJohn Levon PARAM_USED = 1026, 8381f5207b7SJohn Levon BYTE_UNITS = 1027, 8391f5207b7SJohn Levon COMPARE_LIMIT = 1028, 8401f5207b7SJohn Levon PARAM_COMPARE = 1029, 8411f5207b7SJohn Levon CONSTRAINT = 1031, 8421f5207b7SJohn Levon PASSES_TYPE = 1032, 8431f5207b7SJohn Levon CONSTRAINT_REQUIRED = 1033, 844efe51d0cSJohn Levon BIT_INFO = 1034, 8451f5207b7SJohn Levon NOSPEC = 1035, 8461f5207b7SJohn Levon NOSPEC_WB = 1036, 8471f5207b7SJohn Levon STMT_CNT = 1037, 8481f5207b7SJohn Levon TERMINATED = 1038, 849*31ad075eSJohn Levon FRESH_ALLOC = 1044, 8501f5207b7SJohn Levon 8511f5207b7SJohn Levon /* put random temporary stuff in the 7000-7999 range for testing */ 852efe51d0cSJohn Levon USER_DATA = 8017, 853efe51d0cSJohn Levon USER_DATA_SET = 9017, 8541f5207b7SJohn Levon NO_OVERFLOW = 8018, 8551f5207b7SJohn Levon NO_OVERFLOW_SIMPLE = 8019, 8561f5207b7SJohn Levon LOCKED = 8020, 8571f5207b7SJohn Levon UNLOCKED = 8021, 8585a0e240fSJohn Levon HALF_LOCKED = 9022, 8595a0e240fSJohn Levon LOCK_RESTORED = 9023, 8605a0e240fSJohn Levon KNOWN_LOCKED = 9024, 8615a0e240fSJohn Levon KNOWN_UNLOCKED = 9025, 8621f5207b7SJohn Levon SET_FS = 8022, 8631f5207b7SJohn Levon ATOMIC_INC = 8023, 8641f5207b7SJohn Levon ATOMIC_DEC = 8024, 8651f5207b7SJohn Levon NO_SIDE_EFFECT = 8025, 8661f5207b7SJohn Levon FN_ARG_LINK = 8028, 8671f5207b7SJohn Levon DATA_VALUE = 8029, 8681f5207b7SJohn Levon ARRAYSIZE_ARG = 8033, 8691f5207b7SJohn Levon SIZEOF_ARG = 8034, 8701f5207b7SJohn Levon MEMORY_TAG = 8036, 8711f5207b7SJohn Levon MTAG_ASSIGN = 8035, 8721f5207b7SJohn Levon STRING_VALUE = 8041, 873efe51d0cSJohn Levon 874efe51d0cSJohn Levon BYTE_COUNT = 8050, 875efe51d0cSJohn Levon ELEM_COUNT = 8051, 876efe51d0cSJohn Levon ELEM_LAST = 8052, 877efe51d0cSJohn Levon USED_LAST = 8053, 878efe51d0cSJohn Levon USED_COUNT = 8054, 8791f5207b7SJohn Levon }; 8801f5207b7SJohn Levon 8811f5207b7SJohn Levon extern struct sqlite3 *smatch_db; 8821f5207b7SJohn Levon extern struct sqlite3 *mem_db; 8831f5207b7SJohn Levon extern struct sqlite3 *cache_db; 8841f5207b7SJohn Levon 8851f5207b7SJohn Levon void db_ignore_states(int id); 8861f5207b7SJohn Levon void select_caller_info_hook(void (*callback)(const char *name, struct symbol *sym, char *key, char *value), int type); 8871f5207b7SJohn Levon void add_member_info_callback(int owner, void (*callback)(struct expression *call, int param, char *printed_name, struct sm_state *sm)); 8881f5207b7SJohn Levon void add_split_return_callback(void (*fn)(int return_id, char *return_ranges, struct expression *returned_expr)); 8891f5207b7SJohn Levon 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)); 8901f5207b7SJohn Levon void select_call_implies_hook(int type, void (*callback)(struct expression *call, struct expression *arg, char *key, char *value)); 8911f5207b7SJohn Levon void select_return_implies_hook(int type, void (*callback)(struct expression *call, struct expression *arg, char *key, char *value)); 8921f5207b7SJohn Levon struct range_list *db_return_vals(struct expression *expr); 8931f5207b7SJohn Levon struct range_list *db_return_vals_from_str(const char *fn_name); 894c85f09ccSJohn Levon struct range_list *db_return_vals_no_args(struct expression *expr); 8951f5207b7SJohn Levon char *return_state_to_var_sym(struct expression *expr, int param, const char *key, struct symbol **sym); 8961f5207b7SJohn Levon char *get_chunk_from_key(struct expression *arg, char *key, struct symbol **sym, struct var_sym_list **vsl); 8971f5207b7SJohn Levon char *get_variable_from_key(struct expression *arg, const char *key, struct symbol **sym); 8981f5207b7SJohn Levon const char *state_name_to_param_name(const char *state_name, const char *param_name); 8991f5207b7SJohn Levon const char *get_param_name_var_sym(const char *name, struct symbol *sym); 9001f5207b7SJohn Levon const char *get_param_name(struct sm_state *sm); 9011f5207b7SJohn Levon const char *get_mtag_name_var_sym(const char *state_name, struct symbol *sym); 9021f5207b7SJohn Levon const char *get_mtag_name_expr(struct expression *expr); 9031f5207b7SJohn Levon char *get_data_info_name(struct expression *expr); 9045a0e240fSJohn Levon char *sm_to_arg_name(struct expression *expr, struct sm_state *sm); 905efe51d0cSJohn Levon int is_recursive_member(const char *param_name); 9061f5207b7SJohn Levon 9071f5207b7SJohn Levon char *escape_newlines(const char *str); 9081f5207b7SJohn Levon void sql_exec(struct sqlite3 *db, int (*callback)(void*, int, char**, char**), void *data, const char *sql); 9091f5207b7SJohn Levon 9101f5207b7SJohn Levon #define sql_helper(db, call_back, data, sql...) \ 9111f5207b7SJohn Levon do { \ 9121f5207b7SJohn Levon char sql_txt[1024]; \ 9131f5207b7SJohn Levon \ 9141f5207b7SJohn Levon sqlite3_snprintf(sizeof(sql_txt), sql_txt, sql); \ 9155a0e240fSJohn Levon db_debug("debug: %s\n", sql_txt); \ 9161f5207b7SJohn Levon sql_exec(db, call_back, data, sql_txt); \ 9171f5207b7SJohn Levon } while (0) 9181f5207b7SJohn Levon 9191f5207b7SJohn Levon 9201f5207b7SJohn Levon #define run_sql(call_back, data, sql...) \ 9211f5207b7SJohn Levon do { \ 9221f5207b7SJohn Levon if (option_no_db) \ 9231f5207b7SJohn Levon break; \ 9241f5207b7SJohn Levon sql_helper(smatch_db, call_back, data, sql); \ 9251f5207b7SJohn Levon } while (0) 9261f5207b7SJohn Levon 9271f5207b7SJohn Levon #define mem_sql(call_back, data, sql...) \ 9281f5207b7SJohn Levon sql_helper(mem_db, call_back, data, sql) 9291f5207b7SJohn Levon 9301f5207b7SJohn Levon #define cache_sql(call_back, data, sql...) \ 9311f5207b7SJohn Levon sql_helper(cache_db, call_back, data, sql) 9321f5207b7SJohn Levon 9331f5207b7SJohn Levon #define sql_insert_helper(table, db, ignore, late, values...) \ 9341f5207b7SJohn Levon do { \ 9351f5207b7SJohn Levon struct sqlite3 *_db = db; \ 9361f5207b7SJohn Levon \ 9371f5207b7SJohn Levon if (__inline_fn && !_db) \ 9381f5207b7SJohn Levon _db = mem_db; \ 9391f5207b7SJohn Levon if (_db) { \ 9401f5207b7SJohn Levon char buf[1024]; \ 9411f5207b7SJohn Levon char *err, *p = buf; \ 9421f5207b7SJohn Levon int rc; \ 9431f5207b7SJohn Levon \ 9441f5207b7SJohn Levon p += snprintf(p, buf + sizeof(buf) - p, \ 9451f5207b7SJohn Levon "insert %sinto %s values (", \ 9461f5207b7SJohn Levon ignore ? "or ignore " : "", #table); \ 9471f5207b7SJohn Levon p += snprintf(p, buf + sizeof(buf) - p, values); \ 9481f5207b7SJohn Levon p += snprintf(p, buf + sizeof(buf) - p, ");"); \ 9495a0e240fSJohn Levon db_debug("mem-db: %s\n", buf); \ 9501f5207b7SJohn Levon rc = sqlite3_exec(_db, buf, NULL, NULL, &err); \ 9511f5207b7SJohn Levon if (rc != SQLITE_OK) { \ 9521f5207b7SJohn Levon sm_ierror("SQL error #2: %s", err); \ 9531f5207b7SJohn Levon sm_ierror("SQL: '%s'", buf); \ 9541f5207b7SJohn Levon parse_error = 1; \ 9551f5207b7SJohn Levon } \ 9561f5207b7SJohn Levon break; \ 9571f5207b7SJohn Levon } \ 9581f5207b7SJohn Levon if (option_info) { \ 9591f5207b7SJohn Levon FILE *tmp_fd = sm_outfd; \ 9601f5207b7SJohn Levon sm_outfd = sql_outfd; \ 9611f5207b7SJohn Levon sm_prefix(); \ 9621f5207b7SJohn Levon sm_printf("SQL%s: insert %sinto " #table " values(", \ 9631f5207b7SJohn Levon late ? "_late" : "", ignore ? "or ignore " : ""); \ 9641f5207b7SJohn Levon sm_printf(values); \ 9651f5207b7SJohn Levon sm_printf(");\n"); \ 9661f5207b7SJohn Levon sm_outfd = tmp_fd; \ 9671f5207b7SJohn Levon } \ 9681f5207b7SJohn Levon } while (0) 9691f5207b7SJohn Levon 9701f5207b7SJohn Levon #define sql_insert(table, values...) sql_insert_helper(table, 0, 0, 0, values); 9711f5207b7SJohn Levon #define sql_insert_or_ignore(table, values...) sql_insert_helper(table, 0, 1, 0, values); 9721f5207b7SJohn Levon #define sql_insert_late(table, values...) sql_insert_helper(table, 0, 0, 1, values); 9731f5207b7SJohn Levon #define sql_insert_cache(table, values...) sql_insert_helper(table, cache_db, 1, 0, values); 9741f5207b7SJohn Levon 9751f5207b7SJohn Levon char *get_static_filter(struct symbol *sym); 9761f5207b7SJohn Levon 9771f5207b7SJohn Levon void sql_insert_return_states(int return_id, const char *return_ranges, 9781f5207b7SJohn Levon int type, int param, const char *key, const char *value); 9791f5207b7SJohn Levon void sql_insert_caller_info(struct expression *call, int type, int param, 9801f5207b7SJohn Levon const char *key, const char *value); 9811f5207b7SJohn Levon void sql_insert_function_ptr(const char *fn, const char *struct_name); 9821f5207b7SJohn Levon void sql_insert_return_values(const char *return_values); 9831f5207b7SJohn Levon void sql_insert_return_implies(int type, int param, const char *key, const char *value); 9841f5207b7SJohn Levon void sql_insert_function_type_size(const char *member, const char *ranges); 9851f5207b7SJohn Levon void sql_insert_function_type_info(int type, const char *struct_type, const char *member, const char *value); 9861f5207b7SJohn Levon void sql_insert_type_info(int type, const char *member, const char *value); 9871f5207b7SJohn Levon void sql_insert_local_values(const char *name, const char *value); 9881f5207b7SJohn Levon void sql_insert_function_type_value(const char *type, const char *value); 9891f5207b7SJohn Levon void sql_insert_function_type(int param, const char *value); 9901f5207b7SJohn Levon void sql_insert_parameter_name(int param, const char *value); 9911f5207b7SJohn Levon void sql_insert_data_info(struct expression *data, int type, const char *value); 9921f5207b7SJohn Levon void sql_insert_data_info_var_sym(const char *var, struct symbol *sym, int type, const char *value); 9931f5207b7SJohn Levon void sql_save_constraint(const char *con); 9941f5207b7SJohn Levon void sql_save_constraint_required(const char *data, int op, const char *limit); 9951f5207b7SJohn Levon void sql_copy_constraint_required(const char *new_limit, const char *old_limit); 9961f5207b7SJohn Levon void sql_insert_fn_ptr_data_link(const char *ptr, const char *data); 9971f5207b7SJohn Levon void sql_insert_fn_data_link(struct expression *fn, int type, int param, const char *key, const char *value); 9981f5207b7SJohn Levon void sql_insert_mtag_about(mtag_t tag, const char *left_name, const char *right_name); 9991f5207b7SJohn Levon void sql_insert_mtag_map(mtag_t tag, int offset, mtag_t container); 10001f5207b7SJohn Levon void sql_insert_mtag_alias(mtag_t orig, mtag_t alias); 10011f5207b7SJohn Levon int mtag_map_select_container(mtag_t tag, int offset, mtag_t *container); 10021f5207b7SJohn Levon int mtag_map_select_tag(mtag_t container, int offset, mtag_t *tag); 1003efe51d0cSJohn Levon struct smatch_state *swap_mtag_return(struct expression *expr, struct smatch_state *state); 1004efe51d0cSJohn Levon struct range_list *swap_mtag_seed(struct expression *expr, struct range_list *rl); 10051f5207b7SJohn Levon 10061f5207b7SJohn Levon void sql_select_return_states(const char *cols, struct expression *call, 10071f5207b7SJohn Levon int (*callback)(void*, int, char**, char**), void *info); 10081f5207b7SJohn Levon void sql_select_call_implies(const char *cols, struct expression *call, 10091f5207b7SJohn Levon int (*callback)(void*, int, char**, char**)); 10101f5207b7SJohn Levon 10111f5207b7SJohn Levon void open_smatch_db(char *db_file); 10121f5207b7SJohn Levon 10131f5207b7SJohn Levon /* smatch_files.c */ 10141f5207b7SJohn Levon int open_data_file(const char *filename); 10151f5207b7SJohn Levon int open_schema_file(const char *schema); 10161f5207b7SJohn Levon struct token *get_tokens_file(const char *filename); 10171f5207b7SJohn Levon 10181f5207b7SJohn Levon /* smatch.c */ 10191f5207b7SJohn Levon extern char *option_debug_check; 10201f5207b7SJohn Levon extern char *option_project_str; 10211f5207b7SJohn Levon extern char *bin_dir; 10221f5207b7SJohn Levon extern char *data_dir; 10231f5207b7SJohn Levon extern int option_no_data; 10241f5207b7SJohn Levon extern int option_full_path; 10251f5207b7SJohn Levon extern int option_call_tree; 10261f5207b7SJohn Levon extern int num_checks; 10271f5207b7SJohn Levon 10281f5207b7SJohn Levon enum project_type { 10291f5207b7SJohn Levon PROJ_NONE, 10301f5207b7SJohn Levon PROJ_KERNEL, 10311f5207b7SJohn Levon PROJ_WINE, 10321f5207b7SJohn Levon PROJ_ILLUMOS_KERNEL, 10331f5207b7SJohn Levon PROJ_ILLUMOS_USER, 10341f5207b7SJohn Levon PROJ_UNKNOWN, 10351f5207b7SJohn Levon }; 10361f5207b7SJohn Levon extern enum project_type option_project; 10371f5207b7SJohn Levon const char *check_name(unsigned short id); 10381f5207b7SJohn Levon int id_from_name(const char *name); 10391f5207b7SJohn Levon 10401f5207b7SJohn Levon 10411f5207b7SJohn Levon /* smatch_buf_size.c */ 10421f5207b7SJohn Levon int get_array_size(struct expression *expr); 10431f5207b7SJohn Levon int get_array_size_bytes(struct expression *expr); 10441f5207b7SJohn Levon int get_array_size_bytes_min(struct expression *expr); 10451f5207b7SJohn Levon int get_array_size_bytes_max(struct expression *expr); 10461f5207b7SJohn Levon struct range_list *get_array_size_bytes_rl(struct expression *expr); 10471f5207b7SJohn Levon int get_real_array_size(struct expression *expr); 10481f5207b7SJohn Levon int last_member_is_resizable(struct symbol *type); 10491f5207b7SJohn Levon /* smatch_strlen.c */ 10501f5207b7SJohn Levon int get_implied_strlen(struct expression *expr, struct range_list **rl); 10511f5207b7SJohn Levon int get_size_from_strlen(struct expression *expr); 10521f5207b7SJohn Levon 10531f5207b7SJohn Levon /* smatch_capped.c */ 10541f5207b7SJohn Levon int is_capped(struct expression *expr); 10551f5207b7SJohn Levon int is_capped_var_sym(const char *name, struct symbol *sym); 10561f5207b7SJohn Levon 10571f5207b7SJohn Levon /* check_user_data.c */ 10581f5207b7SJohn Levon int is_user_macro(struct expression *expr); 10591f5207b7SJohn Levon int is_capped_user_data(struct expression *expr); 10601f5207b7SJohn Levon int implied_user_data(struct expression *expr, struct range_list **rl); 10611f5207b7SJohn Levon struct stree *get_user_stree(void); 10621f5207b7SJohn Levon int get_user_rl(struct expression *expr, struct range_list **rl); 10631f5207b7SJohn Levon int is_user_rl(struct expression *expr); 10641f5207b7SJohn Levon int get_user_rl_var_sym(const char *name, struct symbol *sym, struct range_list **rl); 1065efe51d0cSJohn Levon bool user_rl_capped(struct expression *expr); 1066efe51d0cSJohn Levon struct range_list *var_user_rl(struct expression *expr); 10671f5207b7SJohn Levon 10681f5207b7SJohn Levon /* check_locking.c */ 10691f5207b7SJohn Levon void print_held_locks(); 10701f5207b7SJohn Levon 10711f5207b7SJohn Levon /* check_assigned_expr.c */ 10721f5207b7SJohn Levon struct expression *get_assigned_expr(struct expression *expr); 10731f5207b7SJohn Levon struct expression *get_assigned_expr_name_sym(const char *name, struct symbol *sym); 10741f5207b7SJohn Levon /* smatch_return_to_param.c */ 10751f5207b7SJohn Levon void __add_return_to_param_mapping(struct expression *assign, const char *return_string); 10761f5207b7SJohn Levon char *map_call_to_param_name_sym(struct expression *expr, struct symbol **sym); 10771f5207b7SJohn Levon 10781f5207b7SJohn Levon /* smatch_comparison.c */ 10795a0e240fSJohn Levon extern int comparison_id; 1080c85f09ccSJohn Levon #define UNKNOWN_COMPARISON 0 1081c85f09ccSJohn Levon #define IMPOSSIBLE_COMPARISON -1 10821f5207b7SJohn Levon struct compare_data { 10831f5207b7SJohn Levon /* The ->left and ->right expression pointers might be NULL (I'm lazy) */ 10841f5207b7SJohn Levon struct expression *left; 10851f5207b7SJohn Levon const char *left_var; 10861f5207b7SJohn Levon struct var_sym_list *left_vsl; 10871f5207b7SJohn Levon int comparison; 10881f5207b7SJohn Levon struct expression *right; 10891f5207b7SJohn Levon const char *right_var; 10901f5207b7SJohn Levon struct var_sym_list *right_vsl; 10911f5207b7SJohn Levon }; 10921f5207b7SJohn Levon DECLARE_ALLOCATOR(compare_data); 10931f5207b7SJohn Levon struct smatch_state *alloc_compare_state( 10941f5207b7SJohn Levon struct expression *left, 10951f5207b7SJohn Levon const char *left_var, struct var_sym_list *left_vsl, 10961f5207b7SJohn Levon int comparison, 10971f5207b7SJohn Levon struct expression *right, 10981f5207b7SJohn Levon const char *right_var, struct var_sym_list *right_vsl); 1099c85f09ccSJohn Levon int comparison_intersection(int orig, int op); 11001f5207b7SJohn Levon int merge_comparisons(int one, int two); 11011f5207b7SJohn Levon int combine_comparisons(int left_compare, int right_compare); 11021f5207b7SJohn Levon int state_to_comparison(struct smatch_state *state); 11031f5207b7SJohn Levon struct smatch_state *merge_compare_states(struct smatch_state *s1, struct smatch_state *s2); 11041f5207b7SJohn Levon int get_comparison(struct expression *left, struct expression *right); 1105efe51d0cSJohn Levon int get_comparison_no_extra(struct expression *a, struct expression *b); 11061f5207b7SJohn Levon int get_comparison_strings(const char *one, const char *two); 11071f5207b7SJohn Levon int possible_comparison(struct expression *a, int comparison, struct expression *b); 11081f5207b7SJohn Levon struct state_list *get_all_comparisons(struct expression *expr); 11091f5207b7SJohn Levon struct state_list *get_all_possible_equal_comparisons(struct expression *expr); 11101f5207b7SJohn Levon void __add_return_comparison(struct expression *call, const char *range); 11111f5207b7SJohn Levon void __add_comparison_info(struct expression *expr, struct expression *call, const char *range); 11121f5207b7SJohn Levon char *get_printed_param_name(struct expression *call, const char *param_name, struct symbol *param_sym); 11131f5207b7SJohn Levon char *name_sym_to_param_comparison(const char *name, struct symbol *sym); 11141f5207b7SJohn Levon char *expr_equal_to_param(struct expression *expr, int ignore); 11151f5207b7SJohn Levon char *expr_lte_to_param(struct expression *expr, int ignore); 11161f5207b7SJohn Levon char *expr_param_comparison(struct expression *expr, int ignore); 11171f5207b7SJohn Levon int flip_comparison(int op); 11181f5207b7SJohn Levon int negate_comparison(int op); 11191f5207b7SJohn Levon int remove_unsigned_from_comparison(int op); 11201f5207b7SJohn Levon int param_compare_limit_is_impossible(struct expression *expr, int left_param, char *left_key, char *value); 11211f5207b7SJohn Levon void filter_by_comparison(struct range_list **rl, int comparison, struct range_list *right); 11221f5207b7SJohn Levon struct sm_state *comparison_implication_hook(struct expression *expr, 11231f5207b7SJohn Levon struct state_list **true_stack, 11241f5207b7SJohn Levon struct state_list **false_stack); 11251f5207b7SJohn Levon void __compare_param_limit_hook(struct expression *left_expr, struct expression *right_expr, 11261f5207b7SJohn Levon const char *state_name, 11271f5207b7SJohn Levon struct smatch_state *true_state, struct smatch_state *false_state); 11281f5207b7SJohn Levon int impossibly_high_comparison(struct expression *expr); 11291f5207b7SJohn Levon 11301f5207b7SJohn Levon /* smatch_sval.c */ 11311f5207b7SJohn Levon sval_t *sval_alloc(sval_t sval); 11321f5207b7SJohn Levon sval_t *sval_alloc_permanent(sval_t sval); 11331f5207b7SJohn Levon sval_t sval_blank(struct expression *expr); 11341f5207b7SJohn Levon sval_t sval_type_val(struct symbol *type, long long val); 11355a0e240fSJohn Levon sval_t sval_type_fval(struct symbol *type, long double fval); 11361f5207b7SJohn Levon sval_t sval_from_val(struct expression *expr, long long val); 11375a0e240fSJohn Levon sval_t sval_from_fval(struct expression *expr, long double fval); 11381f5207b7SJohn Levon int sval_is_ptr(sval_t sval); 11395a0e240fSJohn Levon bool sval_is_fp(sval_t sval); 11401f5207b7SJohn Levon int sval_unsigned(sval_t sval); 11411f5207b7SJohn Levon int sval_signed(sval_t sval); 11421f5207b7SJohn Levon int sval_bits(sval_t sval); 11431f5207b7SJohn Levon int sval_bits_used(sval_t sval); 11441f5207b7SJohn Levon int sval_is_negative(sval_t sval); 11451f5207b7SJohn Levon int sval_is_positive(sval_t sval); 11461f5207b7SJohn Levon int sval_is_min(sval_t sval); 11471f5207b7SJohn Levon int sval_is_max(sval_t sval); 11481f5207b7SJohn Levon int sval_is_a_min(sval_t sval); 11491f5207b7SJohn Levon int sval_is_a_max(sval_t sval); 11501f5207b7SJohn Levon int sval_is_negative_min(sval_t sval); 11511f5207b7SJohn Levon int sval_cmp_t(struct symbol *type, sval_t one, sval_t two); 11521f5207b7SJohn Levon int sval_cmp_val(sval_t one, long long val); 11531f5207b7SJohn Levon sval_t sval_min(sval_t one, sval_t two); 11541f5207b7SJohn Levon sval_t sval_max(sval_t one, sval_t two); 11551f5207b7SJohn Levon int sval_too_low(struct symbol *type, sval_t sval); 11561f5207b7SJohn Levon int sval_too_high(struct symbol *type, sval_t sval); 11571f5207b7SJohn Levon int sval_fits(struct symbol *type, sval_t sval); 11581f5207b7SJohn Levon sval_t sval_cast(struct symbol *type, sval_t sval); 11591f5207b7SJohn Levon sval_t sval_preop(sval_t sval, int op); 11601f5207b7SJohn Levon sval_t sval_binop(sval_t left, int op, sval_t right); 11611f5207b7SJohn Levon int sval_binop_overflows(sval_t left, int op, sval_t right); 11621f5207b7SJohn Levon int sval_binop_overflows_no_sign(sval_t left, int op, sval_t right); 1163efe51d0cSJohn Levon int find_first_zero_bit(unsigned long long uvalue); 1164efe51d0cSJohn Levon int sm_fls64(unsigned long long uvalue); 11651f5207b7SJohn Levon unsigned long long fls_mask(unsigned long long uvalue); 11661f5207b7SJohn Levon unsigned long long sval_fls_mask(sval_t sval); 11671f5207b7SJohn Levon const char *sval_to_str(sval_t sval); 1168efe51d0cSJohn Levon const char *sval_to_str_or_err_ptr(sval_t sval); 11691f5207b7SJohn Levon const char *sval_to_numstr(sval_t sval); 11701f5207b7SJohn Levon sval_t ll_to_sval(long long val); 11711f5207b7SJohn Levon 11721f5207b7SJohn Levon /* smatch_string_list.c */ 11731f5207b7SJohn Levon int list_has_string(struct string_list *str_list, const char *str); 1174efe51d0cSJohn Levon int insert_string(struct string_list **str_list, const char *str); 11751f5207b7SJohn Levon struct string_list *clone_str_list(struct string_list *orig); 11761f5207b7SJohn Levon struct string_list *combine_string_lists(struct string_list *one, struct string_list *two); 11771f5207b7SJohn Levon 11781f5207b7SJohn Levon /* smatch_start_states.c */ 11791f5207b7SJohn Levon struct stree *get_start_states(void); 11801f5207b7SJohn Levon 11811f5207b7SJohn Levon /* smatch_recurse.c */ 11821f5207b7SJohn Levon int has_symbol(struct expression *expr, struct symbol *sym); 11831f5207b7SJohn Levon int has_variable(struct expression *expr, struct expression *var); 11841f5207b7SJohn Levon int has_inc_dec(struct expression *expr); 11851f5207b7SJohn Levon 11861f5207b7SJohn Levon /* smatch_stored_conditions.c */ 11871f5207b7SJohn Levon struct smatch_state *get_stored_condition(struct expression *expr); 11881f5207b7SJohn Levon struct expression_list *get_conditions(struct expression *expr); 11891f5207b7SJohn Levon struct sm_state *stored_condition_implication_hook(struct expression *expr, 11901f5207b7SJohn Levon struct state_list **true_stack, 11911f5207b7SJohn Levon struct state_list **false_stack); 11925a0e240fSJohn Levon /* smatch_parsed_conditions.c */ 11935a0e240fSJohn Levon struct sm_state *parsed_condition_implication_hook(struct expression *expr, 11945a0e240fSJohn Levon struct state_list **true_stack, 11955a0e240fSJohn Levon struct state_list **false_stack); 11961f5207b7SJohn Levon 11971f5207b7SJohn Levon /* check_string_len.c */ 11981f5207b7SJohn Levon int get_formatted_string_size(struct expression *call, int arg); 1199efe51d0cSJohn Levon int get_formatted_string_min_size(struct expression *call, int arg); 12001f5207b7SJohn Levon 12011f5207b7SJohn Levon /* smatch_param_set.c */ 12021f5207b7SJohn Levon int param_was_set(struct expression *expr); 12031f5207b7SJohn Levon int param_was_set_var_sym(const char *name, struct symbol *sym); 1204c85f09ccSJohn Levon void print_limited_param_set(int return_id, char *return_ranges, struct expression *expr); 12051f5207b7SJohn Levon /* smatch_param_filter.c */ 12061f5207b7SJohn Levon int param_has_filter_data(struct sm_state *sm); 12071f5207b7SJohn Levon 12081f5207b7SJohn Levon /* smatch_links.c */ 12091f5207b7SJohn Levon void set_up_link_functions(int id, int linkid); 12101f5207b7SJohn Levon struct smatch_state *merge_link_states(struct smatch_state *s1, struct smatch_state *s2); 12111f5207b7SJohn Levon void store_link(int link_id, const char *name, struct symbol *sym, const char *link_name, struct symbol *link_sym); 12121f5207b7SJohn Levon 12131f5207b7SJohn Levon /* check_buf_comparison */ 1214efe51d0cSJohn Levon const char *limit_type_str(unsigned int limit_type); 1215efe51d0cSJohn Levon struct expression *get_size_variable(struct expression *buf, int *limit_type); 12161f5207b7SJohn Levon struct expression *get_array_variable(struct expression *size); 1217efe51d0cSJohn Levon int buf_comparison_index_ok(struct expression *expr); 12181f5207b7SJohn Levon 12191f5207b7SJohn Levon /* smatch_untracked_param.c */ 12201f5207b7SJohn Levon void mark_untracked(struct expression *expr, int param, const char *key, const char *value); 12211f5207b7SJohn Levon void add_untracked_param_hook(void (func)(struct expression *call, int param)); 1222efe51d0cSJohn Levon void add_lost_param_hook(void (func)(struct expression *call, int param)); 12231f5207b7SJohn Levon void mark_all_params_untracked(int return_id, char *return_ranges, struct expression *expr); 12241f5207b7SJohn Levon 12251f5207b7SJohn Levon /* smatch_strings.c */ 12261f5207b7SJohn Levon struct state_list *get_strings(struct expression *expr); 12271f5207b7SJohn Levon struct expression *fake_string_from_mtag(mtag_t tag); 12281f5207b7SJohn Levon 12291f5207b7SJohn Levon /* smatch_estate.c */ 12301f5207b7SJohn Levon int estate_get_single_value(struct smatch_state *state, sval_t *sval); 12311f5207b7SJohn Levon 12321f5207b7SJohn Levon /* smatch_address.c */ 12331f5207b7SJohn Levon int get_address_rl(struct expression *expr, struct range_list **rl); 12341f5207b7SJohn Levon int get_member_offset(struct symbol *type, const char *member_name); 12351f5207b7SJohn Levon int get_member_offset_from_deref(struct expression *expr); 12361f5207b7SJohn Levon 12371f5207b7SJohn Levon /* for now this is in smatch_used_parameter.c */ 12381f5207b7SJohn Levon void __get_state_hook(int owner, const char *name, struct symbol *sym); 12391f5207b7SJohn Levon 12401f5207b7SJohn Levon /* smatch_buf_comparison.c */ 12411f5207b7SJohn Levon int db_var_is_array_limit(struct expression *array, const char *name, struct var_sym_list *vsl); 12421f5207b7SJohn Levon 12431f5207b7SJohn Levon struct stree *get_all_return_states(void); 12441f5207b7SJohn Levon struct stree_stack *get_all_return_strees(void); 12451f5207b7SJohn Levon int on_atomic_dec_path(void); 12461f5207b7SJohn Levon int was_inced(const char *name, struct symbol *sym); 12471f5207b7SJohn Levon 12481f5207b7SJohn Levon /* smatch_constraints.c */ 12491f5207b7SJohn Levon char *get_constraint_str(struct expression *expr); 12501f5207b7SJohn Levon struct constraint_list *get_constraints(struct expression *expr); 12511f5207b7SJohn Levon char *unmet_constraint(struct expression *data, struct expression *offset); 12521f5207b7SJohn Levon char *get_required_constraint(const char *data_str); 12531f5207b7SJohn Levon 12541f5207b7SJohn Levon /* smatch_container_of.c */ 12551f5207b7SJohn Levon int get_param_from_container_of(struct expression *expr); 12561f5207b7SJohn Levon int get_offset_from_container_of(struct expression *expr); 1257efe51d0cSJohn Levon char *get_container_name(struct expression *container, struct expression *expr); 12581f5207b7SJohn Levon 12591f5207b7SJohn Levon /* smatch_mtag.c */ 1260*31ad075eSJohn Levon mtag_t str_to_mtag(const char *str); 12611f5207b7SJohn Levon int get_string_mtag(struct expression *expr, mtag_t *tag); 12621f5207b7SJohn Levon int get_toplevel_mtag(struct symbol *sym, mtag_t *tag); 12631f5207b7SJohn Levon int create_mtag_alias(mtag_t tag, struct expression *expr, mtag_t *new); 12641f5207b7SJohn Levon int expr_to_mtag_offset(struct expression *expr, mtag_t *tag, int *offset); 1265c85f09ccSJohn Levon void update_mtag_data(struct expression *expr, struct smatch_state *state); 12661f5207b7SJohn Levon int get_mtag_sval(struct expression *expr, sval_t *sval); 12671f5207b7SJohn Levon 12681f5207b7SJohn Levon /* Trinity fuzzer stuff */ 12691f5207b7SJohn Levon const char *get_syscall_arg_type(struct symbol *sym); 12701f5207b7SJohn Levon 1271efe51d0cSJohn Levon /* smatch_bit_info.c */ 1272c85f09ccSJohn Levon struct bit_info *rl_to_binfo(struct range_list *rl); 1273efe51d0cSJohn Levon struct bit_info *get_bit_info(struct expression *expr); 1274efe51d0cSJohn Levon struct bit_info *get_bit_info_var_sym(const char *name, struct symbol *sym); 12751f5207b7SJohn Levon /* smatch_mem_tracker.c */ 12761f5207b7SJohn Levon extern int option_mem; 1277efe51d0cSJohn Levon unsigned long get_mem_kb(void); 12781f5207b7SJohn Levon unsigned long get_max_memory(void); 12791f5207b7SJohn Levon 12801f5207b7SJohn Levon /* check_is_nospec.c */ 12811f5207b7SJohn Levon bool is_nospec(struct expression *expr); 1282efe51d0cSJohn Levon long get_stmt_cnt(void); 12831f5207b7SJohn Levon 12841f5207b7SJohn Levon /* smatch_nul_terminator.c */ 1285c85f09ccSJohn Levon bool is_nul_terminated_var_sym(const char *name, struct symbol *sym); 12861f5207b7SJohn Levon bool is_nul_terminated(struct expression *expr); 1287efe51d0cSJohn Levon /* check_kernel.c */ 1288efe51d0cSJohn Levon bool is_ignored_kernel_data(const char *name); 1289efe51d0cSJohn Levon 1290*31ad075eSJohn Levon bool is_fresh_alloc_var_sym(const char *var, struct symbol *sym); 1291*31ad075eSJohn Levon bool is_fresh_alloc(struct expression *expr); 1292efe51d0cSJohn Levon static inline bool type_is_ptr(struct symbol *type) 1293efe51d0cSJohn Levon { 1294efe51d0cSJohn Levon return type && 1295efe51d0cSJohn Levon (type->type == SYM_PTR || 1296efe51d0cSJohn Levon type->type == SYM_ARRAY || 1297efe51d0cSJohn Levon type->type == SYM_FN); 1298efe51d0cSJohn Levon } 12991f5207b7SJohn Levon 13005a0e240fSJohn Levon static inline bool type_is_fp(struct symbol *type) 13015a0e240fSJohn Levon { 13025a0e240fSJohn Levon return type && 13035a0e240fSJohn Levon (type == &float_ctype || 13045a0e240fSJohn Levon type == &double_ctype || 13055a0e240fSJohn Levon type == &ldouble_ctype); 13065a0e240fSJohn Levon } 13075a0e240fSJohn Levon 13081f5207b7SJohn Levon static inline int type_bits(struct symbol *type) 13091f5207b7SJohn Levon { 13101f5207b7SJohn Levon if (!type) 13111f5207b7SJohn Levon return 0; 1312efe51d0cSJohn Levon if (type_is_ptr(type)) 13131f5207b7SJohn Levon return bits_in_pointer; 13141f5207b7SJohn Levon if (!type->examined) 13151f5207b7SJohn Levon examine_symbol_type(type); 13161f5207b7SJohn Levon return type->bit_size; 13171f5207b7SJohn Levon } 13181f5207b7SJohn Levon 13191f5207b7SJohn Levon static inline int type_unsigned(struct symbol *base_type) 13201f5207b7SJohn Levon { 13211f5207b7SJohn Levon if (!base_type) 13221f5207b7SJohn Levon return 0; 1323efe51d0cSJohn Levon if (is_ptr_type(base_type)) 1324efe51d0cSJohn Levon return 1; 13251f5207b7SJohn Levon if (base_type->ctype.modifiers & MOD_UNSIGNED) 13261f5207b7SJohn Levon return 1; 13271f5207b7SJohn Levon return 0; 13281f5207b7SJohn Levon } 13291f5207b7SJohn Levon 13301f5207b7SJohn Levon static inline int type_positive_bits(struct symbol *type) 13311f5207b7SJohn Levon { 13321f5207b7SJohn Levon if (!type) 13331f5207b7SJohn Levon return 0; 1334efe51d0cSJohn Levon if (is_ptr_type(type)) 1335efe51d0cSJohn Levon return bits_in_pointer; 13361f5207b7SJohn Levon if (type_unsigned(type)) 13371f5207b7SJohn Levon return type_bits(type); 13381f5207b7SJohn Levon return type_bits(type) - 1; 13391f5207b7SJohn Levon } 13401f5207b7SJohn Levon 13411f5207b7SJohn Levon static inline int sval_positive_bits(sval_t sval) 13421f5207b7SJohn Levon { 13431f5207b7SJohn Levon return type_positive_bits(sval.type); 13441f5207b7SJohn Levon } 13451f5207b7SJohn Levon 13461f5207b7SJohn Levon /* 13471f5207b7SJohn Levon * Returns -1 if one is smaller, 0 if they are the same and 1 if two is larger. 13481f5207b7SJohn Levon */ 13495a0e240fSJohn Levon 13505a0e240fSJohn Levon static inline int fp_cmp(sval_t one, sval_t two) 13515a0e240fSJohn Levon { 13525a0e240fSJohn Levon struct symbol *type; 13535a0e240fSJohn Levon 13545a0e240fSJohn Levon if (sval_is_fp(one) && sval_is_fp(two)) 13555a0e240fSJohn Levon type = type_bits(one.type) > type_bits(two.type) ? one.type : two.type; 13565a0e240fSJohn Levon else if (sval_is_fp(one)) 13575a0e240fSJohn Levon type = one.type; 13585a0e240fSJohn Levon else 13595a0e240fSJohn Levon type = two.type; 13605a0e240fSJohn Levon 13615a0e240fSJohn Levon one = sval_cast(type, one); 13625a0e240fSJohn Levon two = sval_cast(type, two); 13635a0e240fSJohn Levon 13645a0e240fSJohn Levon if (one.type == &float_ctype) { 13655a0e240fSJohn Levon if (one.fvalue < two.fvalue) 13665a0e240fSJohn Levon return -1; 13675a0e240fSJohn Levon if (one.fvalue == two.fvalue) 13685a0e240fSJohn Levon return 0; 13695a0e240fSJohn Levon return 1; 13705a0e240fSJohn Levon } 13715a0e240fSJohn Levon if (one.type == &double_ctype) { 13725a0e240fSJohn Levon if (one.dvalue < two.dvalue) 13735a0e240fSJohn Levon return -1; 13745a0e240fSJohn Levon if (one.dvalue == two.dvalue) 13755a0e240fSJohn Levon return 0; 13765a0e240fSJohn Levon return 1; 13775a0e240fSJohn Levon } 13785a0e240fSJohn Levon if (one.type == &ldouble_ctype) { 13795a0e240fSJohn Levon if (one.ldvalue < two.ldvalue) 13805a0e240fSJohn Levon return -1; 13815a0e240fSJohn Levon if (one.ldvalue == two.ldvalue) 13825a0e240fSJohn Levon return 0; 13835a0e240fSJohn Levon return 1; 13845a0e240fSJohn Levon } 13855a0e240fSJohn Levon sm_perror("bad type in fp_cmp(): %s", type_to_str(type)); 13865a0e240fSJohn Levon return 1; 13875a0e240fSJohn Levon } 13885a0e240fSJohn Levon 13891f5207b7SJohn Levon static inline int sval_cmp(sval_t one, sval_t two) 13901f5207b7SJohn Levon { 13911f5207b7SJohn Levon struct symbol *type; 13921f5207b7SJohn Levon 13935a0e240fSJohn Levon if (sval_is_fp(one) || sval_is_fp(two)) 13945a0e240fSJohn Levon return fp_cmp(one, two); 13955a0e240fSJohn Levon 13961f5207b7SJohn Levon type = one.type; 13971f5207b7SJohn Levon if (sval_positive_bits(two) > sval_positive_bits(one)) 13981f5207b7SJohn Levon type = two.type; 13991f5207b7SJohn Levon if (type_bits(type) < 31) 14001f5207b7SJohn Levon type = &int_ctype; 14011f5207b7SJohn Levon 14021f5207b7SJohn Levon one = sval_cast(type, one); 14031f5207b7SJohn Levon two = sval_cast(type, two); 14041f5207b7SJohn Levon 14051f5207b7SJohn Levon if (type_unsigned(type)) { 14061f5207b7SJohn Levon if (one.uvalue < two.uvalue) 14071f5207b7SJohn Levon return -1; 14081f5207b7SJohn Levon if (one.uvalue == two.uvalue) 14091f5207b7SJohn Levon return 0; 14101f5207b7SJohn Levon return 1; 14111f5207b7SJohn Levon } 14121f5207b7SJohn Levon /* fix me handle type promotion and unsigned values */ 14131f5207b7SJohn Levon if (one.value < two.value) 14141f5207b7SJohn Levon return -1; 14151f5207b7SJohn Levon if (one.value == two.value) 14161f5207b7SJohn Levon return 0; 14171f5207b7SJohn Levon return 1; 14181f5207b7SJohn Levon } 14191f5207b7SJohn Levon 14201f5207b7SJohn Levon #endif /* !SMATCH_H_ */ 1421