warn if testing the address of an array
[smatch.git] / lib.h
blob0bf8c97e43779bb054d4320a93635d440a65c2ae
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 * Permission is hereby granted, free of charge, to any person obtaining a copy
15 * of this software and associated documentation files (the "Software"), to deal
16 * in the Software without restriction, including without limitation the rights
17 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
18 * copies of the Software, and to permit persons to whom the Software is
19 * furnished to do so, subject to the following conditions:
21 * The above copyright notice and this permission notice shall be included in
22 * all copies or substantial portions of the Software.
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
29 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
30 * THE SOFTWARE.
33 #include "compat.h"
34 #include "ptrlist.h"
36 #define DO_STRINGIFY(x) #x
37 #define STRINGIFY(x) DO_STRINGIFY(x)
39 #ifndef ARRAY_SIZE
40 #define ARRAY_SIZE(x) (sizeof(x)/sizeof((x)[0]))
41 #endif
43 extern int verbose, optimize, optimize_size, preprocessing;
44 extern int die_if_error;
45 extern int repeat_phase, merge_phi_sources;
46 extern int gcc_major, gcc_minor, gcc_patchlevel;
48 extern unsigned int hexval(unsigned int c);
50 struct position {
51 unsigned int type:6,
52 stream:14,
53 newline:1,
54 whitespace:1,
55 pos:10;
56 unsigned int line:31,
57 noexpand:1;
60 struct ident;
61 struct token;
62 struct symbol;
63 struct statement;
64 struct expression;
65 struct basic_block;
66 struct entrypoint;
67 struct instruction;
68 struct multijmp;
69 struct pseudo;
71 DECLARE_PTR_LIST(symbol_list, struct symbol);
72 DECLARE_PTR_LIST(statement_list, struct statement);
73 DECLARE_PTR_LIST(expression_list, struct expression);
74 DECLARE_PTR_LIST(basic_block_list, struct basic_block);
75 DECLARE_PTR_LIST(instruction_list, struct instruction);
76 DECLARE_PTR_LIST(multijmp_list, struct multijmp);
77 DECLARE_PTR_LIST(pseudo_list, struct pseudo);
78 DECLARE_PTR_LIST(string_list, char);
80 typedef struct pseudo *pseudo_t;
82 struct token *skip_to(struct token *, int);
83 struct token *expect(struct token *, int, const char *);
84 #ifdef __GNUC__
85 #define FORMAT_ATTR(pos) __attribute__ ((__format__ (__printf__, pos, pos+1)))
86 #define NORETURN_ATTR __attribute__ ((__noreturn__))
87 #define SENTINEL_ATTR __attribute__ ((__sentinel__))
88 #else
89 #define FORMAT_ATTR(pos)
90 #define NORETURN_ATTR
91 #define SENTINEL_ATTR
92 #endif
93 extern void die(const char *, ...) FORMAT_ATTR(1) NORETURN_ATTR;
94 extern void info(struct position, const char *, ...) FORMAT_ATTR(2);
95 extern void warning(struct position, const char *, ...) FORMAT_ATTR(2);
96 extern void sparse_error(struct position, const char *, ...) FORMAT_ATTR(2);
97 extern void error_die(struct position, const char *, ...) FORMAT_ATTR(2) NORETURN_ATTR;
98 extern void expression_error(struct expression *, const char *, ...) FORMAT_ATTR(2);
100 extern void add_pre_buffer(const char *fmt, ...) FORMAT_ATTR(1);
102 extern int preprocess_only;
104 extern int Waddress;
105 extern int Waddress_space;
106 extern int Wbitwise;
107 extern int Wcast_to_as;
108 extern int Wcast_truncate;
109 extern int Wcontext;
110 extern int Wdecl;
111 extern int Wdeclarationafterstatement;
112 extern int Wdefault_bitfield_sign;
113 extern int Wdesignated_init;
114 extern int Wdo_while;
115 extern int Wenum_mismatch;
116 extern int Wsparse_error;
117 extern int Winit_cstring;
118 extern int Wnon_pointer_null;
119 extern int Wold_initializer;
120 extern int Wone_bit_signed_bitfield;
121 extern int Woverride_init;
122 extern int Woverride_init_all;
123 extern int Woverride_init_whole_range;
124 extern int Wparen_string;
125 extern int Wptr_subtraction_blows;
126 extern int Wreturn_void;
127 extern int Wshadow;
128 extern int Wsizeof_bool;
129 extern int Wtautological_compare;
130 extern int Wtransparent_union;
131 extern int Wtypesign;
132 extern int Wundef;
133 extern int Wuninitialized;
134 extern int Wunknown_attribute;
135 extern int Wvla;
137 extern int dbg_entry;
138 extern int dbg_dead;
140 extern int arch_m64;
142 extern void declare_builtin_functions(void);
143 extern void create_builtin_stream(void);
144 extern struct symbol_list *sparse_initialize(int argc, char **argv, struct string_list **files);
145 extern struct symbol_list *__sparse(char *filename);
146 extern struct symbol_list *sparse_keep_tokens(char *filename);
147 extern struct symbol_list *sparse(char *filename);
149 static inline int symbol_list_size(struct symbol_list *list)
151 return ptr_list_size((struct ptr_list *)(list));
154 static inline int statement_list_size(struct statement_list *list)
156 return ptr_list_size((struct ptr_list *)(list));
159 static inline int expression_list_size(struct expression_list *list)
161 return ptr_list_size((struct ptr_list *)(list));
164 static inline int instruction_list_size(struct instruction_list *list)
166 return ptr_list_size((struct ptr_list *)(list));
169 static inline int pseudo_list_size(struct pseudo_list *list)
171 return ptr_list_size((struct ptr_list *)(list));
174 static inline int bb_list_size(struct basic_block_list *list)
176 return ptr_list_size((struct ptr_list *)(list));
179 static inline void free_instruction_list(struct instruction_list **head)
181 free_ptr_list((struct ptr_list **)head);
184 static inline struct instruction * delete_last_instruction(struct instruction_list **head)
186 return undo_ptr_list_last((struct ptr_list **)head);
189 static inline struct basic_block * delete_last_basic_block(struct basic_block_list **head)
191 return delete_ptr_list_last((struct ptr_list **)head);
194 static inline struct basic_block *first_basic_block(struct basic_block_list *head)
196 return first_ptr_list((struct ptr_list *)head);
198 static inline struct instruction *last_instruction(struct instruction_list *head)
200 return last_ptr_list((struct ptr_list *)head);
203 static inline struct instruction *first_instruction(struct instruction_list *head)
205 return first_ptr_list((struct ptr_list *)head);
208 static inline struct expression *first_expression(struct expression_list *head)
210 return first_ptr_list((struct ptr_list *)head);
213 static inline pseudo_t first_pseudo(struct pseudo_list *head)
215 return first_ptr_list((struct ptr_list *)head);
218 static inline void concat_symbol_list(struct symbol_list *from, struct symbol_list **to)
220 concat_ptr_list((struct ptr_list *)from, (struct ptr_list **)to);
223 static inline void concat_basic_block_list(struct basic_block_list *from, struct basic_block_list **to)
225 concat_ptr_list((struct ptr_list *)from, (struct ptr_list **)to);
228 static inline void concat_instruction_list(struct instruction_list *from, struct instruction_list **to)
230 concat_ptr_list((struct ptr_list *)from, (struct ptr_list **)to);
233 static inline void add_symbol(struct symbol_list **list, struct symbol *sym)
235 add_ptr_list(list, sym);
238 static inline void add_statement(struct statement_list **list, struct statement *stmt)
240 add_ptr_list(list, stmt);
243 static inline void add_expression(struct expression_list **list, struct expression *expr)
245 add_ptr_list(list, expr);
248 #define hashval(x) ((unsigned long)(x))
250 #endif