locking: ignore unreachable unlocks
[smatch.git] / lib.h
blob2cea2520eaff1b98e0d7c2408ce2f4d9fa88f2b5
1 #ifndef LIB_H
2 #define LIB_H
4 #include <stdlib.h>
5 #include <stddef.h>
7 /*
8 * Basic helper routine descriptions for 'sparse'.
10 * Copyright (C) 2003 Transmeta Corp.
11 * 2003 Linus Torvalds
12 * 2004 Christopher Li
14 * Licensed under the Open Software License version 1.1
17 #include "compat.h"
18 #include "ptrlist.h"
20 #define DO_STRINGIFY(x) #x
21 #define STRINGIFY(x) DO_STRINGIFY(x)
23 #ifndef ARRAY_SIZE
24 #define ARRAY_SIZE(x) (sizeof(x)/sizeof((x)[0]))
25 #endif
27 extern int verbose, optimize, optimize_size, preprocessing;
28 extern int die_if_error;
29 extern int repeat_phase, merge_phi_sources;
30 extern int gcc_major, gcc_minor, gcc_patchlevel;
32 extern unsigned int hexval(unsigned int c);
34 struct position {
35 unsigned int type:6,
36 stream:14,
37 newline:1,
38 whitespace:1,
39 pos:10;
40 unsigned int line:31,
41 noexpand:1;
44 struct cmdline_include {
45 char *filename;
46 int fd;
49 extern struct cmdline_include cmdline_include[];
50 extern int cmdline_include_nr;
53 struct ident;
54 struct token;
55 struct symbol;
56 struct statement;
57 struct expression;
58 struct basic_block;
59 struct entrypoint;
60 struct instruction;
61 struct multijmp;
62 struct pseudo;
64 DECLARE_PTR_LIST(symbol_list, struct symbol);
65 DECLARE_PTR_LIST(statement_list, struct statement);
66 DECLARE_PTR_LIST(expression_list, struct expression);
67 DECLARE_PTR_LIST(basic_block_list, struct basic_block);
68 DECLARE_PTR_LIST(instruction_list, struct instruction);
69 DECLARE_PTR_LIST(multijmp_list, struct multijmp);
70 DECLARE_PTR_LIST(pseudo_list, struct pseudo);
71 DECLARE_PTR_LIST(string_list, char);
73 typedef struct pseudo *pseudo_t;
75 struct token *skip_to(struct token *, int);
76 struct token *expect(struct token *, int, const char *);
77 #ifdef __GNUC__
78 #define FORMAT_ATTR(pos) __attribute__ ((__format__ (__printf__, pos, pos+1)))
79 #define NORETURN_ATTR __attribute__ ((__noreturn__))
80 #define SENTINEL_ATTR __attribute__ ((__sentinel__))
81 #else
82 #define FORMAT_ATTR(pos)
83 #define NORETURN_ATTR
84 #define SENTINEL_ATTR
85 #endif
86 extern void die(const char *, ...) FORMAT_ATTR(1) NORETURN_ATTR;
87 extern void info(struct position, const char *, ...) FORMAT_ATTR(2);
88 extern void warning(struct position, const char *, ...) FORMAT_ATTR(2);
89 extern void sparse_error(struct position, const char *, ...) FORMAT_ATTR(2);
90 extern void error_die(struct position, const char *, ...) FORMAT_ATTR(2) NORETURN_ATTR;
91 extern void expression_error(struct expression *, const char *, ...) FORMAT_ATTR(2);
93 extern void add_pre_buffer(const char *fmt, ...) FORMAT_ATTR(1);
95 extern int preprocess_only;
97 extern int Waddress_space;
98 extern int Wbitwise;
99 extern int Wcast_to_as;
100 extern int Wcast_truncate;
101 extern int Wcontext;
102 extern int Wdecl;
103 extern int Wdefault_bitfield_sign;
104 extern int Wdesignated_init;
105 extern int Wdo_while;
106 extern int Wenum_mismatch;
107 extern int Wnon_pointer_null;
108 extern int Wold_initializer;
109 extern int Wone_bit_signed_bitfield;
110 extern int Wparen_string;
111 extern int Wptr_subtraction_blows;
112 extern int Wreturn_void;
113 extern int Wshadow;
114 extern int Wtransparent_union;
115 extern int Wtypesign;
116 extern int Wundef;
117 extern int Wuninitialized;
118 extern int Wdeclarationafterstatement;
120 extern int dbg_entry;
121 extern int dbg_dead;
123 extern void declare_builtin_functions(void);
124 extern void create_builtin_stream(void);
125 extern struct symbol_list *sparse_initialize(int argc, char **argv, struct string_list **files);
126 extern struct symbol_list *__sparse(char *filename);
127 extern struct symbol_list *sparse_keep_tokens(char *filename);
128 extern struct symbol_list *sparse(char *filename);
130 static inline int symbol_list_size(struct symbol_list *list)
132 return ptr_list_size((struct ptr_list *)(list));
135 static inline int statement_list_size(struct statement_list *list)
137 return ptr_list_size((struct ptr_list *)(list));
140 static inline int expression_list_size(struct expression_list *list)
142 return ptr_list_size((struct ptr_list *)(list));
145 static inline int instruction_list_size(struct instruction_list *list)
147 return ptr_list_size((struct ptr_list *)(list));
150 static inline int pseudo_list_size(struct pseudo_list *list)
152 return ptr_list_size((struct ptr_list *)(list));
155 static inline int bb_list_size(struct basic_block_list *list)
157 return ptr_list_size((struct ptr_list *)(list));
160 static inline void free_instruction_list(struct instruction_list **head)
162 free_ptr_list((struct ptr_list **)head);
165 static inline struct instruction * delete_last_instruction(struct instruction_list **head)
167 return undo_ptr_list_last((struct ptr_list **)head);
170 static inline struct basic_block * delete_last_basic_block(struct basic_block_list **head)
172 return delete_ptr_list_last((struct ptr_list **)head);
175 static inline struct basic_block *first_basic_block(struct basic_block_list *head)
177 return first_ptr_list((struct ptr_list *)head);
179 static inline struct instruction *last_instruction(struct instruction_list *head)
181 return last_ptr_list((struct ptr_list *)head);
184 static inline struct instruction *first_instruction(struct instruction_list *head)
186 return first_ptr_list((struct ptr_list *)head);
189 static inline pseudo_t first_pseudo(struct pseudo_list *head)
191 return first_ptr_list((struct ptr_list *)head);
194 static inline void concat_symbol_list(struct symbol_list *from, struct symbol_list **to)
196 concat_ptr_list((struct ptr_list *)from, (struct ptr_list **)to);
199 static inline void concat_basic_block_list(struct basic_block_list *from, struct basic_block_list **to)
201 concat_ptr_list((struct ptr_list *)from, (struct ptr_list **)to);
204 static inline void concat_instruction_list(struct instruction_list *from, struct instruction_list **to)
206 concat_ptr_list((struct ptr_list *)from, (struct ptr_list **)to);
209 static inline void add_symbol(struct symbol_list **list, struct symbol *sym)
211 add_ptr_list(list, sym);
214 static inline void add_statement(struct statement_list **list, struct statement *stmt)
216 add_ptr_list(list, stmt);
219 static inline void add_expression(struct expression_list **list, struct expression *expr)
221 add_ptr_list(list, expr);
224 #define hashval(x) ((unsigned long)(x))
226 #endif