xref: /illumos-gate/usr/src/tools/smatch/src/smatch.h (revision 6523a3aa)
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 
INT_PTR(int i)611f5207b7SJohn Levon static inline void *INT_PTR(int i)
621f5207b7SJohn Levon {
631f5207b7SJohn Levon 	return (void *)(long)i;
641f5207b7SJohn Levon }
651f5207b7SJohn Levon 
PTR_INT(void * p)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 
10731ad075eSJohn Levon struct alloc_info {
10831ad075eSJohn Levon 	const char *fn;
10931ad075eSJohn Levon 	int size_param, nr;
11031ad075eSJohn Levon };
11131ad075eSJohn Levon extern struct alloc_info *alloc_funcs;
11231ad075eSJohn 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);
199*6523a3aaSJohn Levon void allocate_tracker_array(int num_checks);
2001f5207b7SJohn Levon 
2011f5207b7SJohn Levon struct modification_data {
2021f5207b7SJohn Levon 	struct smatch_state *prev;
2031f5207b7SJohn Levon 	struct expression *cur;
2041f5207b7SJohn Levon };
2051f5207b7SJohn Levon 
2061f5207b7SJohn Levon typedef void (modification_hook)(struct sm_state *sm, struct expression *mod_expr);
2071f5207b7SJohn Levon void add_modification_hook(int owner, modification_hook *call_back);
2081f5207b7SJohn Levon void add_modification_hook_late(int owner, modification_hook *call_back);
2091f5207b7SJohn Levon struct smatch_state *get_modification_state(struct expression *expr);
2101f5207b7SJohn Levon 
2111f5207b7SJohn Levon int outside_of_function(void);
2121f5207b7SJohn Levon const char *get_filename(void);
2131f5207b7SJohn Levon const char *get_base_file(void);
2141f5207b7SJohn Levon char *get_function(void);
2151f5207b7SJohn Levon int get_lineno(void);
2161f5207b7SJohn Levon extern int final_pass;
2171f5207b7SJohn Levon extern struct symbol *cur_func_sym;
2181f5207b7SJohn Levon extern int option_debug;
2191f5207b7SJohn Levon extern int local_debug;
2205a0e240fSJohn Levon extern int debug_db;
221c85f09ccSJohn Levon bool debug_implied(void);
2221f5207b7SJohn Levon extern int option_info;
2231f5207b7SJohn Levon extern int option_spammy;
2247ae7577cSJohn Levon extern int option_timeout;
2251f5207b7SJohn Levon extern char *trace_variable;
2261f5207b7SJohn Levon extern struct stree *global_states;
2271f5207b7SJohn Levon int is_skipped_function(void);
2281f5207b7SJohn Levon int is_silenced_function(void);
229efe51d0cSJohn Levon extern bool implications_off;
2301f5207b7SJohn Levon 
2311f5207b7SJohn Levon /* smatch_impossible.c */
2321f5207b7SJohn Levon int is_impossible_path(void);
2331f5207b7SJohn Levon void set_path_impossible(void);
2341f5207b7SJohn Levon 
2351f5207b7SJohn Levon extern FILE *sm_outfd;
2361f5207b7SJohn Levon extern FILE *sql_outfd;
2371f5207b7SJohn Levon extern FILE *caller_info_fd;
2381f5207b7SJohn Levon extern int sm_nr_checks;
2391f5207b7SJohn Levon extern int sm_nr_errors;
2401f5207b7SJohn Levon extern const char *progname;
2411f5207b7SJohn Levon 
2421f5207b7SJohn Levon /*
2431f5207b7SJohn Levon  * How to use these routines:
2441f5207b7SJohn Levon  *
2451f5207b7SJohn Levon  * sm_fatal(): an internal error of some kind that should immediately exit
2461f5207b7SJohn Levon  * sm_ierror(): an internal error
2471f5207b7SJohn Levon  * sm_perror(): an internal error from parsing input source
2481f5207b7SJohn Levon  * sm_error(): an error from input source
2491f5207b7SJohn Levon  * sm_warning(): a warning from input source
2501f5207b7SJohn Levon  * sm_info(): info message (from option_info)
2511f5207b7SJohn Levon  * sm_debug(): debug message
2521f5207b7SJohn Levon  * sm_msg(): other message (please avoid using this)
2531f5207b7SJohn Levon  */
2541f5207b7SJohn Levon 
2555a0e240fSJohn Levon #define sm_printf(msg...) do {						\
2565a0e240fSJohn Levon 	if (final_pass || option_debug || local_debug || debug_db)	\
2575a0e240fSJohn Levon 		fprintf(sm_outfd, msg);					\
2585a0e240fSJohn Levon } while (0)
2591f5207b7SJohn Levon 
sm_prefix(void)2601f5207b7SJohn Levon static inline void sm_prefix(void)
2611f5207b7SJohn Levon {
2621f5207b7SJohn Levon 	sm_printf("%s: %s:%d %s() ", progname, get_filename(), get_lineno(), get_function());
2631f5207b7SJohn Levon }
2641f5207b7SJohn Levon 
2651f5207b7SJohn Levon static inline void print_implied_debug_msg();
2661f5207b7SJohn Levon 
2671f5207b7SJohn Levon extern bool __silence_warnings_for_stmt;
2681f5207b7SJohn Levon 
2691f5207b7SJohn Levon #define sm_print_msg(type, msg...) \
2701f5207b7SJohn Levon do {                                                           \
2711f5207b7SJohn Levon 	print_implied_debug_msg();                             \
2725a0e240fSJohn Levon 	if (!final_pass && !option_debug && !local_debug && !debug_db)	  \
2731f5207b7SJohn Levon 		break;                                         \
2741f5207b7SJohn Levon 	if (__silence_warnings_for_stmt && !option_debug && !local_debug) \
2751f5207b7SJohn Levon 		break;					       \
2761f5207b7SJohn Levon 	if (!option_info && is_silenced_function())	       \
2771f5207b7SJohn Levon 		break;					       \
2781f5207b7SJohn Levon 	sm_prefix();					       \
2791f5207b7SJohn Levon 	if (type == 1) {				       \
2801f5207b7SJohn Levon 		sm_printf("warn: ");			       \
2811f5207b7SJohn Levon 		sm_nr_checks++;			    	       \
2821f5207b7SJohn Levon 	} else if (type == 2) {				       \
2831f5207b7SJohn Levon 		sm_printf("error: ");			       \
2841f5207b7SJohn Levon 		sm_nr_checks++;				       \
2851f5207b7SJohn Levon 	} else if (type == 3) {				       \
2861f5207b7SJohn Levon 		sm_printf("parse error: ");		       \
2871f5207b7SJohn Levon 		sm_nr_errors++;				       \
2881f5207b7SJohn Levon 	}						       \
2891f5207b7SJohn Levon         sm_printf(msg);                                        \
2901f5207b7SJohn Levon         sm_printf("\n");                                       \
2911f5207b7SJohn Levon } while (0)
2921f5207b7SJohn Levon 
2931f5207b7SJohn Levon #define sm_msg(msg...) do { sm_print_msg(0, msg); } while (0)
2941f5207b7SJohn Levon 
2951f5207b7SJohn Levon extern char *implied_debug_msg;
print_implied_debug_msg(void)2961f5207b7SJohn Levon static inline void print_implied_debug_msg(void)
2971f5207b7SJohn Levon {
2981f5207b7SJohn Levon 	static struct symbol *last_printed = NULL;
2991f5207b7SJohn Levon 
3001f5207b7SJohn Levon 	if (!implied_debug_msg)
3011f5207b7SJohn Levon 		return;
3021f5207b7SJohn Levon 	if (last_printed == cur_func_sym)
3031f5207b7SJohn Levon 		return;
3041f5207b7SJohn Levon 	last_printed = cur_func_sym;
3051f5207b7SJohn Levon 	sm_msg("%s", implied_debug_msg);
3061f5207b7SJohn Levon }
3071f5207b7SJohn Levon 
3081f5207b7SJohn Levon #define sm_debug(msg...) do { if (option_debug) sm_printf(msg); } while (0)
3095a0e240fSJohn Levon #define db_debug(msg...) do { if (option_debug || debug_db) sm_printf(msg); } while (0)
3101f5207b7SJohn Levon 
3111f5207b7SJohn Levon #define sm_info(msg...) do {					\
3121f5207b7SJohn Levon 	if (option_debug || (option_info && final_pass)) {	\
3131f5207b7SJohn Levon 		sm_prefix();					\
3141f5207b7SJohn Levon 		sm_printf("info: ");				\
3151f5207b7SJohn Levon 		sm_printf(msg);					\
3161f5207b7SJohn Levon 		sm_printf("\n");				\
3171f5207b7SJohn Levon 	}							\
3181f5207b7SJohn Levon } while(0)
3191f5207b7SJohn Levon 
3201f5207b7SJohn Levon #define sm_warning(msg...) do { sm_print_msg(1, msg); } while (0)
3211f5207b7SJohn Levon #define sm_error(msg...) do { sm_print_msg(2, msg); } while (0)
3221f5207b7SJohn Levon #define sm_perror(msg...) do { sm_print_msg(3, msg); } while (0)
3231f5207b7SJohn Levon 
sm_fatal(const char * fmt,...)3241f5207b7SJohn Levon static inline void sm_fatal(const char *fmt, ...)
3251f5207b7SJohn Levon {
3261f5207b7SJohn Levon 	va_list args;
3271f5207b7SJohn Levon 
3281f5207b7SJohn Levon 	va_start(args, fmt);
3291f5207b7SJohn Levon 	vfprintf(sm_outfd, fmt, args);
3301f5207b7SJohn Levon 	va_end(args);
3311f5207b7SJohn Levon 
3321f5207b7SJohn Levon 	fprintf(sm_outfd, "\n");
3331f5207b7SJohn Levon 
3341f5207b7SJohn Levon 	exit(1);
3351f5207b7SJohn Levon }
3361f5207b7SJohn Levon 
sm_ierror(const char * fmt,...)3371f5207b7SJohn Levon static inline void sm_ierror(const char *fmt, ...)
3381f5207b7SJohn Levon {
3391f5207b7SJohn Levon 	va_list args;
3401f5207b7SJohn Levon 
3411f5207b7SJohn Levon 	sm_nr_errors++;
3421f5207b7SJohn Levon 
3431f5207b7SJohn Levon 	fprintf(sm_outfd, "internal error: ");
3441f5207b7SJohn Levon 
3451f5207b7SJohn Levon 	va_start(args, fmt);
3461f5207b7SJohn Levon 	vfprintf(sm_outfd, fmt, args);
3471f5207b7SJohn Levon 	va_end(args);
3481f5207b7SJohn Levon 
3491f5207b7SJohn Levon 	fprintf(sm_outfd, "\n");
3501f5207b7SJohn Levon }
3511f5207b7SJohn Levon #define ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1))
3521f5207b7SJohn Levon 
3531f5207b7SJohn Levon struct smatch_state *__get_state(int owner, const char *name, struct symbol *sym);
3541f5207b7SJohn Levon struct smatch_state *get_state(int owner, const char *name, struct symbol *sym);
3551f5207b7SJohn Levon struct smatch_state *get_state_expr(int owner, struct expression *expr);
3561f5207b7SJohn Levon struct state_list *get_possible_states(int owner, const char *name,
3571f5207b7SJohn Levon 				       struct symbol *sym);
3581f5207b7SJohn Levon struct state_list *get_possible_states_expr(int owner, struct expression *expr);
3591f5207b7SJohn Levon struct sm_state *set_state(int owner, const char *name, struct symbol *sym,
3601f5207b7SJohn Levon 	       struct smatch_state *state);
3611f5207b7SJohn Levon struct sm_state *set_state_expr(int owner, struct expression *expr,
3621f5207b7SJohn Levon 		struct smatch_state *state);
3631f5207b7SJohn Levon void delete_state(int owner, const char *name, struct symbol *sym);
3641f5207b7SJohn Levon void delete_state_expr(int owner, struct expression *expr);
3651f5207b7SJohn Levon void __delete_all_states_sym(struct symbol *sym);
3661f5207b7SJohn Levon void set_true_false_states(int owner, const char *name, struct symbol *sym,
3671f5207b7SJohn Levon 			   struct smatch_state *true_state,
3681f5207b7SJohn Levon 			   struct smatch_state *false_state);
3691f5207b7SJohn Levon void set_true_false_states_expr(int owner, struct expression *expr,
3701f5207b7SJohn Levon 			   struct smatch_state *true_state,
3711f5207b7SJohn Levon 			   struct smatch_state *false_state);
3721f5207b7SJohn Levon 
3731f5207b7SJohn Levon struct stree *get_all_states_from_stree(int owner, struct stree *source);
3741f5207b7SJohn Levon struct stree *get_all_states_stree(int id);
3751f5207b7SJohn Levon struct stree *__get_cur_stree(void);
3761f5207b7SJohn Levon int is_reachable(void);
3771f5207b7SJohn Levon void add_get_state_hook(void (*fn)(int owner, const char *name, struct symbol *sym));
3781f5207b7SJohn Levon 
3791f5207b7SJohn Levon /* smatch_helper.c */
3801f5207b7SJohn Levon DECLARE_PTR_LIST(int_stack, int);
3811f5207b7SJohn Levon char *alloc_string(const char *str);
382c85f09ccSJohn Levon char *alloc_string_newline(const char *str);
3831f5207b7SJohn Levon void free_string(char *str);
3841f5207b7SJohn Levon void append(char *dest, const char *data, int buff_len);
3851f5207b7SJohn Levon void remove_parens(char *str);
3861f5207b7SJohn Levon struct smatch_state *alloc_state_num(int num);
3871f5207b7SJohn Levon struct smatch_state *alloc_state_str(const char *name);
388efe51d0cSJohn Levon struct smatch_state *merge_str_state(struct smatch_state *s1, struct smatch_state *s2);
3891f5207b7SJohn Levon struct smatch_state *alloc_state_expr(struct expression *expr);
3901f5207b7SJohn Levon struct expression *get_argument_from_call_expr(struct expression_list *args,
3911f5207b7SJohn Levon 					       int num);
392*6523a3aaSJohn Levon struct expression *get_array_expr(struct expression *expr);
3931f5207b7SJohn Levon 
3941f5207b7SJohn Levon char *expr_to_var(struct expression *expr);
3951f5207b7SJohn Levon struct symbol *expr_to_sym(struct expression *expr);
3961f5207b7SJohn Levon char *expr_to_str(struct expression *expr);
3971f5207b7SJohn Levon char *expr_to_str_sym(struct expression *expr,
3981f5207b7SJohn Levon 				     struct symbol **sym_ptr);
3991f5207b7SJohn Levon char *expr_to_var_sym(struct expression *expr,
4001f5207b7SJohn Levon 			     struct symbol **sym_ptr);
4011f5207b7SJohn Levon char *expr_to_known_chunk_sym(struct expression *expr, struct symbol **sym);
4021f5207b7SJohn Levon char *expr_to_chunk_sym_vsl(struct expression *expr, struct symbol **sym, struct var_sym_list **vsl);
4031f5207b7SJohn Levon int get_complication_score(struct expression *expr);
4041f5207b7SJohn Levon 
4051f5207b7SJohn Levon int sym_name_is(const char *name, struct expression *expr);
4061f5207b7SJohn Levon int get_const_value(struct expression *expr, sval_t *sval);
4071f5207b7SJohn Levon int get_value(struct expression *expr, sval_t *val);
4081f5207b7SJohn Levon int get_implied_value(struct expression *expr, sval_t *val);
40931ad075eSJohn Levon int get_implied_value_fast(struct expression *expr, sval_t *sval);
4101f5207b7SJohn Levon int get_implied_min(struct expression *expr, sval_t *sval);
4111f5207b7SJohn Levon int get_implied_max(struct expression *expr, sval_t *val);
4121f5207b7SJohn Levon int get_hard_max(struct expression *expr, sval_t *sval);
4131f5207b7SJohn Levon int get_fuzzy_min(struct expression *expr, sval_t *min);
4141f5207b7SJohn Levon int get_fuzzy_max(struct expression *expr, sval_t *max);
4151f5207b7SJohn Levon int get_absolute_min(struct expression *expr, sval_t *sval);
4161f5207b7SJohn Levon int get_absolute_max(struct expression *expr, sval_t *sval);
4171f5207b7SJohn Levon int parse_call_math(struct expression *expr, char *math, sval_t *val);
418efe51d0cSJohn Levon int parse_call_math_rl(struct expression *call, const char *math, struct range_list **rl);
419c85f09ccSJohn Levon const char *get_allocation_math(struct expression *expr);
4201f5207b7SJohn Levon char *get_value_in_terms_of_parameter_math(struct expression *expr);
4211f5207b7SJohn Levon char *get_value_in_terms_of_parameter_math_var_sym(const char *var, struct symbol *sym);
422c85f09ccSJohn Levon int expr_is_zero(struct expression *expr);
4231f5207b7SJohn Levon int known_condition_true(struct expression *expr);
4241f5207b7SJohn Levon int known_condition_false(struct expression *expr);
4251f5207b7SJohn Levon int implied_condition_true(struct expression *expr);
4261f5207b7SJohn Levon int implied_condition_false(struct expression *expr);
4271f5207b7SJohn Levon int can_integer_overflow(struct symbol *type, struct expression *expr);
4281f5207b7SJohn Levon void clear_math_cache(void);
429c85f09ccSJohn Levon void set_fast_math_only(void);
430c85f09ccSJohn Levon void clear_fast_math_only(void);
4311f5207b7SJohn Levon 
4321f5207b7SJohn Levon int is_array(struct expression *expr);
4331f5207b7SJohn Levon struct expression *get_array_base(struct expression *expr);
4341f5207b7SJohn Levon struct expression *get_array_offset(struct expression *expr);
4351f5207b7SJohn Levon const char *show_state(struct smatch_state *state);
4361f5207b7SJohn Levon struct statement *get_expression_statement(struct expression *expr);
4371f5207b7SJohn Levon struct expression *strip_parens(struct expression *expr);
4381f5207b7SJohn Levon struct expression *strip_expr(struct expression *expr);
4391f5207b7SJohn Levon struct expression *strip_expr_set_parent(struct expression *expr);
4401f5207b7SJohn Levon void scoped_state(int my_id, const char *name, struct symbol *sym);
4411f5207b7SJohn Levon int is_error_return(struct expression *expr);
442c85f09ccSJohn Levon int getting_address(struct expression *expr);
4431f5207b7SJohn Levon int get_struct_and_member(struct expression *expr, const char **type, const char **member);
4441f5207b7SJohn Levon char *get_member_name(struct expression *expr);
4451f5207b7SJohn Levon char *get_fnptr_name(struct expression *expr);
4461f5207b7SJohn Levon int cmp_pos(struct position pos1, struct position pos2);
4471f5207b7SJohn Levon int positions_eq(struct position pos1, struct position pos2);
4481f5207b7SJohn Levon struct statement *get_current_statement(void);
4491f5207b7SJohn Levon struct statement *get_prev_statement(void);
4501f5207b7SJohn Levon struct expression *get_last_expr_from_expression_stmt(struct expression *expr);
451*6523a3aaSJohn Levon 
452*6523a3aaSJohn Levon #define RETURN_VAR    -1
453*6523a3aaSJohn Levon #define LOCAL_SCOPE   -2
454*6523a3aaSJohn Levon #define FILE_SCOPE    -3
455*6523a3aaSJohn Levon #define GLOBAL_SCOPE  -4
456*6523a3aaSJohn Levon #define UNKNOWN_SCOPE -5
4571f5207b7SJohn Levon int get_param_num_from_sym(struct symbol *sym);
4581f5207b7SJohn Levon int get_param_num(struct expression *expr);
4595a0e240fSJohn Levon struct symbol *get_param_sym_from_num(int num);
460*6523a3aaSJohn Levon 
4611f5207b7SJohn Levon int ms_since(struct timeval *start);
4621f5207b7SJohn Levon int parent_is_gone_var_sym(const char *name, struct symbol *sym);
4631f5207b7SJohn Levon int parent_is_gone(struct expression *expr);
4641f5207b7SJohn Levon int invert_op(int op);
465efe51d0cSJohn Levon int op_remove_assign(int op);
4661f5207b7SJohn Levon int expr_equiv(struct expression *one, struct expression *two);
4671f5207b7SJohn Levon void push_int(struct int_stack **stack, int num);
4681f5207b7SJohn Levon int pop_int(struct int_stack **stack);
4691f5207b7SJohn Levon 
4701f5207b7SJohn Levon /* smatch_type.c */
4711f5207b7SJohn Levon struct symbol *get_real_base_type(struct symbol *sym);
4721f5207b7SJohn Levon int type_bytes(struct symbol *type);
4731f5207b7SJohn Levon int array_bytes(struct symbol *type);
4741f5207b7SJohn Levon struct symbol *get_pointer_type(struct expression *expr);
4751f5207b7SJohn Levon struct symbol *get_type(struct expression *expr);
4761f5207b7SJohn Levon struct symbol *get_final_type(struct expression *expr);
4771f5207b7SJohn Levon struct symbol *get_promoted_type(struct symbol *left, struct symbol *right);
4781f5207b7SJohn Levon int type_signed(struct symbol *base_type);
4791f5207b7SJohn Levon int expr_unsigned(struct expression *expr);
4801f5207b7SJohn Levon int expr_signed(struct expression *expr);
4811f5207b7SJohn Levon int returns_unsigned(struct symbol *base_type);
4821f5207b7SJohn Levon int is_pointer(struct expression *expr);
4831f5207b7SJohn Levon int returns_pointer(struct symbol *base_type);
4841f5207b7SJohn Levon sval_t sval_type_max(struct symbol *base_type);
4851f5207b7SJohn Levon sval_t sval_type_min(struct symbol *base_type);
4861f5207b7SJohn Levon int nr_bits(struct expression *expr);
4871f5207b7SJohn Levon int is_void_pointer(struct expression *expr);
4881f5207b7SJohn Levon int is_char_pointer(struct expression *expr);
4891f5207b7SJohn Levon int is_string(struct expression *expr);
490*6523a3aaSJohn Levon bool is_struct_ptr(struct symbol *type);
4911f5207b7SJohn Levon int is_static(struct expression *expr);
492c85f09ccSJohn Levon bool is_local_variable(struct expression *expr);
4931f5207b7SJohn Levon int types_equiv(struct symbol *one, struct symbol *two);
494*6523a3aaSJohn Levon bool type_fits(struct symbol *type, struct symbol *test);
4951f5207b7SJohn Levon int fn_static(void);
4961f5207b7SJohn Levon const char *global_static();
4971f5207b7SJohn Levon struct symbol *cur_func_return_type(void);
4981f5207b7SJohn Levon struct symbol *get_arg_type(struct expression *fn, int arg);
4991f5207b7SJohn Levon struct symbol *get_member_type_from_key(struct expression *expr, const char *key);
5001f5207b7SJohn Levon struct symbol *get_arg_type_from_key(struct expression *fn, int param, struct expression *arg, const char *key);
5011f5207b7SJohn Levon int is_struct(struct expression *expr);
5021f5207b7SJohn Levon char *type_to_str(struct symbol *type);
5031f5207b7SJohn Levon 
5041f5207b7SJohn Levon /* smatch_ignore.c */
5051f5207b7SJohn Levon void add_ignore(int owner, const char *name, struct symbol *sym);
5061f5207b7SJohn Levon int is_ignored(int owner, const char *name, struct symbol *sym);
5071f5207b7SJohn Levon void add_ignore_expr(int owner, struct expression *expr);
5081f5207b7SJohn Levon int is_ignored_expr(int owner, struct expression *expr);
5091f5207b7SJohn Levon 
5101f5207b7SJohn Levon /* smatch_var_sym */
5111f5207b7SJohn Levon struct var_sym *alloc_var_sym(const char *var, struct symbol *sym);
5121f5207b7SJohn Levon struct var_sym_list *expr_to_vsl(struct expression *expr);
5131f5207b7SJohn Levon void add_var_sym(struct var_sym_list **list, const char *var, struct symbol *sym);
5141f5207b7SJohn Levon void add_var_sym_expr(struct var_sym_list **list, struct expression *expr);
5151f5207b7SJohn Levon void del_var_sym(struct var_sym_list **list, const char *var, struct symbol *sym);
5161f5207b7SJohn Levon int in_var_sym_list(struct var_sym_list *list, const char *var, struct symbol *sym);
5171f5207b7SJohn Levon struct var_sym_list *clone_var_sym_list(struct var_sym_list *from_vsl);
5181f5207b7SJohn Levon void merge_var_sym_list(struct var_sym_list **dest, struct var_sym_list *src);
5191f5207b7SJohn Levon struct var_sym_list *combine_var_sym_lists(struct var_sym_list *one, struct var_sym_list *two);
5201f5207b7SJohn Levon int var_sym_lists_equiv(struct var_sym_list *one, struct var_sym_list *two);
5211f5207b7SJohn Levon void free_var_sym_list(struct var_sym_list **list);
5221f5207b7SJohn Levon void free_var_syms_and_list(struct var_sym_list **list);
5231f5207b7SJohn Levon 
5241f5207b7SJohn Levon /* smatch_tracker */
5251f5207b7SJohn Levon struct tracker *alloc_tracker(int owner, const char *name, struct symbol *sym);
5261f5207b7SJohn Levon void add_tracker(struct tracker_list **list, int owner, const char *name,
5271f5207b7SJohn Levon 		struct symbol *sym);
5281f5207b7SJohn Levon void add_tracker_expr(struct tracker_list **list, int owner, struct expression *expr);
5291f5207b7SJohn Levon void del_tracker(struct tracker_list **list, int owner, const char *name,
5301f5207b7SJohn Levon 		struct symbol *sym);
5311f5207b7SJohn Levon int in_tracker_list(struct tracker_list *list, int owner, const char *name,
5321f5207b7SJohn Levon 		struct symbol *sym);
5331f5207b7SJohn Levon void free_tracker_list(struct tracker_list **list);
5341f5207b7SJohn Levon void free_trackers_and_list(struct tracker_list **list);
5351f5207b7SJohn Levon 
5361f5207b7SJohn Levon /* smatch_conditions */
5371f5207b7SJohn Levon int in_condition(void);
5381f5207b7SJohn Levon 
5391f5207b7SJohn Levon /* smatch_flow.c */
5401f5207b7SJohn Levon 
5411f5207b7SJohn Levon extern int __in_fake_assign;
5421f5207b7SJohn Levon extern int __in_fake_parameter_assign;
5431f5207b7SJohn Levon extern int __in_fake_struct_assign;
5441f5207b7SJohn Levon extern int in_fake_env;
545efe51d0cSJohn Levon void smatch (struct string_list *filelist);
5461f5207b7SJohn Levon int inside_loop(void);
5471f5207b7SJohn Levon int definitely_inside_loop(void);
5481f5207b7SJohn Levon struct expression *get_switch_expr(void);
5491f5207b7SJohn Levon int in_expression_statement(void);
5501f5207b7SJohn Levon void __process_post_op_stack(void);
5511f5207b7SJohn Levon void __split_expr(struct expression *expr);
5521f5207b7SJohn Levon void __split_label_stmt(struct statement *stmt);
5531f5207b7SJohn Levon void __split_stmt(struct statement *stmt);
5541f5207b7SJohn Levon extern int __in_function_def;
555c85f09ccSJohn Levon extern int __in_unmatched_hook;
5561f5207b7SJohn Levon extern int option_assume_loops;
5571f5207b7SJohn Levon extern int option_two_passes;
5581f5207b7SJohn Levon extern int option_no_db;
5591f5207b7SJohn Levon extern int option_file_output;
5601f5207b7SJohn Levon extern int option_time;
5611f5207b7SJohn Levon extern struct expression_list *big_expression_stack;
5621f5207b7SJohn Levon extern struct expression_list *big_condition_stack;
5631f5207b7SJohn Levon extern struct statement_list *big_statement_stack;
5641f5207b7SJohn Levon int is_assigned_call(struct expression *expr);
5651f5207b7SJohn Levon int inlinable(struct expression *expr);
5661f5207b7SJohn Levon extern int __inline_call;
5671f5207b7SJohn Levon extern struct expression *__inline_fn;
5681f5207b7SJohn Levon extern int __in_pre_condition;
5691f5207b7SJohn Levon extern int __bail_on_rest_of_function;
5701f5207b7SJohn Levon extern struct statement *__prev_stmt;
5711f5207b7SJohn Levon extern struct statement *__cur_stmt;
5721f5207b7SJohn Levon extern struct statement *__next_stmt;
5731f5207b7SJohn Levon void init_fake_env(void);
5741f5207b7SJohn Levon void end_fake_env(void);
5751f5207b7SJohn Levon int time_parsing_function(void);
576efe51d0cSJohn Levon bool taking_too_long(void);
5771f5207b7SJohn Levon 
5781f5207b7SJohn Levon /* smatch_struct_assignment.c */
5791f5207b7SJohn Levon struct expression *get_faked_expression(void);
5801f5207b7SJohn Levon void __fake_struct_member_assignments(struct expression *expr);
5811f5207b7SJohn Levon 
5821f5207b7SJohn Levon /* smatch_project.c */
5831f5207b7SJohn Levon int is_no_inline_function(const char *function);
5841f5207b7SJohn Levon 
5851f5207b7SJohn Levon /* smatch_conditions */
5861f5207b7SJohn Levon void __split_whole_condition(struct expression *expr);
5871f5207b7SJohn Levon void __handle_logic(struct expression *expr);
5881f5207b7SJohn Levon int is_condition(struct expression *expr);
5891f5207b7SJohn Levon int __handle_condition_assigns(struct expression *expr);
5901f5207b7SJohn Levon int __handle_select_assigns(struct expression *expr);
5911f5207b7SJohn Levon int __handle_expr_statement_assigns(struct expression *expr);
5921f5207b7SJohn Levon 
5931f5207b7SJohn Levon /* smatch_implied.c */
5941f5207b7SJohn Levon struct range_list_stack;
595*6523a3aaSJohn Levon void param_limit_implications(struct expression *expr, int param, char *key, char *value, struct stree **implied);
5961f5207b7SJohn Levon struct stree *__implied_case_stree(struct expression *switch_expr,
5971f5207b7SJohn Levon 				   struct range_list *case_rl,
5981f5207b7SJohn Levon 				   struct range_list_stack **remaining_cases,
5991f5207b7SJohn Levon 				   struct stree **raw_stree);
6001f5207b7SJohn Levon void overwrite_states_using_pool(struct sm_state *gate_sm, struct sm_state *pool_sm);
6011f5207b7SJohn Levon int assume(struct expression *expr);
6021f5207b7SJohn Levon void end_assume(void);
6031f5207b7SJohn Levon int impossible_assumption(struct expression *left, int op, sval_t sval);
6041f5207b7SJohn Levon 
605efe51d0cSJohn Levon /* smatch_slist.h */
606efe51d0cSJohn Levon bool has_dynamic_states(unsigned short owner);
607efe51d0cSJohn Levon void set_dynamic_states(unsigned short owner);
608efe51d0cSJohn Levon 
6091f5207b7SJohn Levon /* smatch_extras.c */
610efe51d0cSJohn Levon int in_warn_on_macro(void);
6111f5207b7SJohn Levon #define SMATCH_EXTRA 5 /* this is my_id from smatch extra set in smatch.c */
6121f5207b7SJohn Levon extern int RETURN_ID;
6131f5207b7SJohn Levon 
6141f5207b7SJohn Levon struct data_range {
6151f5207b7SJohn Levon 	sval_t min;
6161f5207b7SJohn Levon 	sval_t max;
6171f5207b7SJohn Levon };
6181f5207b7SJohn Levon 
6191f5207b7SJohn Levon #define MTAG_ALIAS_BIT (1ULL << 63)
6201f5207b7SJohn Levon #define MTAG_OFFSET_MASK 0xfffULL
621efe51d0cSJohn Levon #define MTAG_SEED 0xdead << 12
6221f5207b7SJohn Levon 
623efe51d0cSJohn Levon const extern unsigned long valid_ptr_min;
624efe51d0cSJohn Levon extern unsigned long valid_ptr_max;
625efe51d0cSJohn Levon extern const sval_t valid_ptr_min_sval;
626efe51d0cSJohn Levon extern sval_t valid_ptr_max_sval;
6271f5207b7SJohn Levon extern struct range_list *valid_ptr_rl;
628efe51d0cSJohn Levon void alloc_valid_ptr_rl(void);
629efe51d0cSJohn Levon 
6301f5207b7SJohn Levon static const sval_t array_min_sval = {
6311f5207b7SJohn Levon 	.type = &ptr_ctype,
6321f5207b7SJohn Levon 	{.value = 100000},
6331f5207b7SJohn Levon };
6341f5207b7SJohn Levon static const sval_t array_max_sval = {
6351f5207b7SJohn Levon 	.type = &ptr_ctype,
636efe51d0cSJohn Levon 	{.value = ULONG_MAX - 4095},
6371f5207b7SJohn Levon };
6381f5207b7SJohn Levon static const sval_t text_seg_min = {
6391f5207b7SJohn Levon 	.type = &ptr_ctype,
640efe51d0cSJohn Levon 	{.value = 4096},
6411f5207b7SJohn Levon };
6421f5207b7SJohn Levon static const sval_t text_seg_max = {
6431f5207b7SJohn Levon 	.type = &ptr_ctype,
644efe51d0cSJohn Levon 	{.value = ULONG_MAX - 4095},
6451f5207b7SJohn Levon };
6461f5207b7SJohn Levon static const sval_t data_seg_min = {
6471f5207b7SJohn Levon 	.type = &ptr_ctype,
648efe51d0cSJohn Levon 	{.value = 4096},
6491f5207b7SJohn Levon };
6501f5207b7SJohn Levon static const sval_t data_seg_max = {
6511f5207b7SJohn Levon 	.type = &ptr_ctype,
652efe51d0cSJohn Levon 	{.value = ULONG_MAX - 4095},
6531f5207b7SJohn Levon };
6541f5207b7SJohn Levon static const sval_t bss_seg_min = {
6551f5207b7SJohn Levon 	.type = &ptr_ctype,
656efe51d0cSJohn Levon 	{.value = 4096},
6571f5207b7SJohn Levon };
6581f5207b7SJohn Levon static const sval_t bss_seg_max = {
6591f5207b7SJohn Levon 	.type = &ptr_ctype,
660efe51d0cSJohn Levon 	{.value = ULONG_MAX - 4095},
6611f5207b7SJohn Levon };
6621f5207b7SJohn Levon static const sval_t stack_seg_min = {
6631f5207b7SJohn Levon 	.type = &ptr_ctype,
664efe51d0cSJohn Levon 	{.value = 4096},
6651f5207b7SJohn Levon };
6661f5207b7SJohn Levon static const sval_t stack_seg_max = {
6671f5207b7SJohn Levon 	.type = &ptr_ctype,
668efe51d0cSJohn Levon 	{.value = ULONG_MAX - 4095},
6691f5207b7SJohn Levon };
6701f5207b7SJohn Levon static const sval_t kmalloc_seg_min = {
6711f5207b7SJohn Levon 	.type = &ptr_ctype,
672efe51d0cSJohn Levon 	{.value = 4096},
6731f5207b7SJohn Levon };
6741f5207b7SJohn Levon static const sval_t kmalloc_seg_max = {
6751f5207b7SJohn Levon 	.type = &ptr_ctype,
676efe51d0cSJohn Levon 	{.value = ULONG_MAX - 4095},
6771f5207b7SJohn Levon };
6781f5207b7SJohn Levon static const sval_t vmalloc_seg_min = {
6791f5207b7SJohn Levon 	.type = &ptr_ctype,
680efe51d0cSJohn Levon 	{.value = 4096},
6811f5207b7SJohn Levon };
6821f5207b7SJohn Levon static const sval_t vmalloc_seg_max = {
6831f5207b7SJohn Levon 	.type = &ptr_ctype,
684efe51d0cSJohn Levon 	{.value = ULONG_MAX - 4095},
6851f5207b7SJohn Levon };
6861f5207b7SJohn Levon static const sval_t fn_ptr_min = {
6871f5207b7SJohn Levon 	.type = &ptr_ctype,
688efe51d0cSJohn Levon 	{.value = 4096},
6891f5207b7SJohn Levon };
6901f5207b7SJohn Levon static const sval_t fn_ptr_max = {
6911f5207b7SJohn Levon 	.type = &ptr_ctype,
692efe51d0cSJohn Levon 	{.value = ULONG_MAX - 4095},
6931f5207b7SJohn Levon };
6941f5207b7SJohn Levon 
6951f5207b7SJohn Levon char *get_other_name_sym(const char *name, struct symbol *sym, struct symbol **new_sym);
6961f5207b7SJohn Levon char *map_call_to_other_name_sym(const char *name, struct symbol *sym, struct symbol **new_sym);
697efe51d0cSJohn Levon char *map_long_to_short_name_sym(const char *name, struct symbol *sym, struct symbol **new_sym, bool use_stack);
6981f5207b7SJohn Levon 
6991f5207b7SJohn Levon #define STRLEN_MAX_RET 1010101
7001f5207b7SJohn Levon 
7011f5207b7SJohn Levon /* smatch_absolute.c */
7021f5207b7SJohn Levon int get_absolute_min_helper(struct expression *expr, sval_t *sval);
7031f5207b7SJohn Levon int get_absolute_max_helper(struct expression *expr, sval_t *sval);
7041f5207b7SJohn Levon 
7051f5207b7SJohn Levon /* smatch_type_value.c */
7061f5207b7SJohn Levon int get_db_type_rl(struct expression *expr, struct range_list **rl);
7071f5207b7SJohn Levon /* smatch_data_val.c */
7081f5207b7SJohn Levon int get_mtag_rl(struct expression *expr, struct range_list **rl);
7091f5207b7SJohn Levon /* smatch_array_values.c */
7101f5207b7SJohn Levon int get_array_rl(struct expression *expr, struct range_list **rl);
7111f5207b7SJohn Levon 
7121f5207b7SJohn Levon /* smatch_states.c */
713c85f09ccSJohn Levon struct stree *__swap_cur_stree(struct stree *stree);
7141f5207b7SJohn Levon void __push_fake_cur_stree();
7151f5207b7SJohn Levon struct stree *__pop_fake_cur_stree();
7161f5207b7SJohn Levon void __free_fake_cur_stree();
7171f5207b7SJohn Levon void __set_fake_cur_stree_fast(struct stree *stree);
7181f5207b7SJohn Levon void __pop_fake_cur_stree_fast(void);
7191f5207b7SJohn Levon void __merge_stree_into_cur(struct stree *stree);
7201f5207b7SJohn Levon 
7211f5207b7SJohn Levon int unreachable(void);
722c85f09ccSJohn Levon void __set_cur_stree_readonly(void);
723c85f09ccSJohn Levon void __set_cur_stree_writable(void);
7241f5207b7SJohn Levon void __set_sm(struct sm_state *sm);
7251f5207b7SJohn Levon void __set_sm_cur_stree(struct sm_state *sm);
7261f5207b7SJohn Levon void __set_sm_fake_stree(struct sm_state *sm);
7271f5207b7SJohn Levon void __set_true_false_sm(struct sm_state *true_state,
7281f5207b7SJohn Levon 			struct sm_state *false_state);
7291f5207b7SJohn Levon void nullify_path(void);
7301f5207b7SJohn Levon void __match_nullify_path_hook(const char *fn, struct expression *expr,
7311f5207b7SJohn Levon 			       void *unused);
7321f5207b7SJohn Levon void __unnullify_path(void);
7331f5207b7SJohn Levon int __path_is_null(void);
7341f5207b7SJohn Levon void save_all_states(void);
7351f5207b7SJohn Levon void restore_all_states(void);
7361f5207b7SJohn Levon void free_goto_stack(void);
7371f5207b7SJohn Levon void clear_all_states(void);
7381f5207b7SJohn Levon 
7391f5207b7SJohn Levon struct sm_state *get_sm_state(int owner, const char *name,
7401f5207b7SJohn Levon 				struct symbol *sym);
7411f5207b7SJohn Levon struct sm_state *get_sm_state_expr(int owner, struct expression *expr);
7421f5207b7SJohn Levon void __push_true_states(void);
7431f5207b7SJohn Levon void __use_false_states(void);
7441f5207b7SJohn Levon void __discard_false_states(void);
7451f5207b7SJohn Levon void __merge_false_states(void);
7461f5207b7SJohn Levon void __merge_true_states(void);
7471f5207b7SJohn Levon 
7481f5207b7SJohn Levon void __negate_cond_stacks(void);
7491f5207b7SJohn Levon void __use_pre_cond_states(void);
7501f5207b7SJohn Levon void __use_cond_true_states(void);
7511f5207b7SJohn Levon void __use_cond_false_states(void);
7521f5207b7SJohn Levon void __push_cond_stacks(void);
7531f5207b7SJohn Levon void __fold_in_set_states(void);
7541f5207b7SJohn Levon void __free_set_states(void);
7551f5207b7SJohn Levon struct stree *__copy_cond_true_states(void);
7561f5207b7SJohn Levon struct stree *__copy_cond_false_states(void);
7571f5207b7SJohn Levon struct stree *__pop_cond_true_stack(void);
7581f5207b7SJohn Levon struct stree *__pop_cond_false_stack(void);
7591f5207b7SJohn Levon void __and_cond_states(void);
7601f5207b7SJohn Levon void __or_cond_states(void);
7611f5207b7SJohn Levon void __save_pre_cond_states(void);
7621f5207b7SJohn Levon void __discard_pre_cond_states(void);
7631f5207b7SJohn Levon struct stree *__get_true_states(void);
7641f5207b7SJohn Levon struct stree *__get_false_states(void);
7651f5207b7SJohn Levon void __use_cond_states(void);
7661f5207b7SJohn Levon extern struct state_list *__last_base_slist;
7671f5207b7SJohn Levon 
7681f5207b7SJohn Levon void __push_continues(void);
7691f5207b7SJohn Levon void __discard_continues(void);
7701f5207b7SJohn Levon void __process_continues(void);
7711f5207b7SJohn Levon void __merge_continues(void);
7721f5207b7SJohn Levon 
7731f5207b7SJohn Levon void __push_breaks(void);
7741f5207b7SJohn Levon void __process_breaks(void);
7751f5207b7SJohn Levon int __has_breaks(void);
7761f5207b7SJohn Levon void __merge_breaks(void);
7771f5207b7SJohn Levon void __use_breaks(void);
7781f5207b7SJohn Levon 
7791f5207b7SJohn Levon void __save_switch_states(struct expression *switch_expr);
7801f5207b7SJohn Levon void __discard_switches(void);
7811f5207b7SJohn Levon int have_remaining_cases(void);
7821f5207b7SJohn Levon void __merge_switches(struct expression *switch_expr, struct range_list *case_rl);
7831f5207b7SJohn Levon void __push_default(void);
7841f5207b7SJohn Levon void __set_default(void);
7851f5207b7SJohn Levon int __pop_default(void);
7861f5207b7SJohn Levon 
7871f5207b7SJohn Levon void __push_conditions(void);
7881f5207b7SJohn Levon void __discard_conditions