Print this page
new smatch
   1 #ifndef LIB_H
   2 #define LIB_H
   3 

   4 #include <stdlib.h>
   5 #include <stddef.h>
   6 
   7 /*
   8  * Basic helper routine descriptions for 'sparse'.
   9  *
  10  * Copyright (C) 2003 Transmeta Corp.
  11  *               2003 Linus Torvalds
  12  *               2004 Christopher Li
  13  *
  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:
  20  *
  21  * The above copyright notice and this permission notice shall be included in
  22  * all copies or substantial portions of the Software.
  23  *
  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.
  31  */
  32 
  33 #include "compat.h"
  34 #include "ptrlist.h"


  35 
  36 #define DO_STRINGIFY(x) #x
  37 #define STRINGIFY(x) DO_STRINGIFY(x)
  38 
  39 #ifndef ARRAY_SIZE
  40 #define ARRAY_SIZE(x) (sizeof(x)/sizeof((x)[0]))
  41 #endif
  42 
  43 extern int verbose, optimize, optimize_size, preprocessing;
  44 extern int die_if_error;
  45 extern int parse_error;
  46 extern int repeat_phase, merge_phi_sources;

  47 extern int gcc_major, gcc_minor, gcc_patchlevel;
  48 


  49 extern unsigned int hexval(unsigned int c);
  50 
  51 struct position {
  52         unsigned int type:6,
  53                      stream:14,
  54                      newline:1,
  55                      whitespace:1,
  56                      pos:10;
  57         unsigned int line:31,
  58                      noexpand:1;
  59 };
  60 
  61 struct ident;
  62 struct token;
  63 struct symbol;
  64 struct statement;
  65 struct expression;
  66 struct basic_block;
  67 struct entrypoint;
  68 struct instruction;
  69 struct multijmp;
  70 struct pseudo;
  71 
  72 DECLARE_PTR_LIST(symbol_list, struct symbol);
  73 DECLARE_PTR_LIST(statement_list, struct statement);
  74 DECLARE_PTR_LIST(expression_list, struct expression);
  75 DECLARE_PTR_LIST(basic_block_list, struct basic_block);
  76 DECLARE_PTR_LIST(instruction_list, struct instruction);
  77 DECLARE_PTR_LIST(multijmp_list, struct multijmp);
  78 DECLARE_PTR_LIST(pseudo_list, struct pseudo);
  79 DECLARE_PTR_LIST(ident_list, struct ident);
  80 DECLARE_PTR_LIST(string_list, char);
  81 
  82 typedef struct pseudo *pseudo_t;
  83 
  84 struct token *skip_to(struct token *, int);
  85 struct token *expect(struct token *, int, const char *);


  86 #ifdef __GNUC__
  87 #define FORMAT_ATTR(pos) __attribute__ ((__format__ (__printf__, pos, pos+1)))
  88 #define NORETURN_ATTR __attribute__ ((__noreturn__))
  89 #define SENTINEL_ATTR __attribute__ ((__sentinel__))
  90 #else
  91 #define FORMAT_ATTR(pos)
  92 #define NORETURN_ATTR
  93 #define SENTINEL_ATTR
  94 #endif
  95 
  96 FORMAT_ATTR(1) NORETURN_ATTR
  97 extern void die(const char *, ...);
  98 
  99 FORMAT_ATTR(2) NORETURN_ATTR
 100 extern void error_die(struct position, const char *, ...);
 101 
 102 extern void info(struct position, const char *, ...) FORMAT_ATTR(2);
 103 extern void warning(struct position, const char *, ...) FORMAT_ATTR(2);
 104 extern void sparse_error(struct position, const char *, ...) FORMAT_ATTR(2);
 105 extern void expression_error(struct expression *, const char *, ...) FORMAT_ATTR(2);
 106 
 107 #define ERROR_CURR_PHASE        (1 << 0)
 108 #define ERROR_PREV_PHASE        (1 << 1)
 109 extern int has_error;
 110 
















 111 extern void add_pre_buffer(const char *fmt, ...) FORMAT_ATTR(1);

 112 
 113 extern int preprocess_only;
 114 
 115 extern int Waddress;
 116 extern int Waddress_space;
 117 extern int Wbitwise;


 118 extern int Wcast_to_as;
 119 extern int Wcast_truncate;
 120 extern int Wconstant_suffix;
 121 extern int Wconstexpr_not_const;
 122 extern int Wcontext;
 123 extern int Wdecl;
 124 extern int Wdeclarationafterstatement;
 125 extern int Wdefault_bitfield_sign;
 126 extern int Wdesignated_init;
 127 extern int Wdo_while;
 128 extern int Wenum_mismatch;
 129 extern int Wexternal_function_has_definition;
 130 extern int Wsparse_error;
 131 extern int Wimplicit_int;
 132 extern int Winit_cstring;

 133 extern int Wmemcpy_max_count;
 134 extern int Wnon_pointer_null;
 135 extern int Wold_initializer;
 136 extern int Wold_style_definition;
 137 extern int Wone_bit_signed_bitfield;
 138 extern int Woverride_init;
 139 extern int Woverride_init_all;
 140 extern int Woverride_init_whole_range;
 141 extern int Wparen_string;
 142 extern int Wpointer_arith;

 143 extern int Wptr_subtraction_blows;
 144 extern int Wreturn_void;
 145 extern int Wshadow;


 146 extern int Wsizeof_bool;
 147 extern int Wstrict_prototypes;
 148 extern int Wtautological_compare;
 149 extern int Wtransparent_union;
 150 extern int Wtypesign;
 151 extern int Wundef;
 152 extern int Wuninitialized;
 153 extern int Wunknown_attribute;
 154 extern int Wvla;
 155 
 156 extern int dump_macro_defs;

 157 
 158 extern int dbg_entry;
 159 extern int dbg_dead;




 160 

 161 extern int fmem_report;
 162 extern int fdump_linearize;
 163 extern unsigned long long fmemcpy_max_count;


 164 
 165 extern int arch_m64;
 166 extern int arch_msize_long;
 167 extern int arch_big_endian;

 168 
 169 extern void declare_builtin_functions(void);
 170 extern void create_builtin_stream(void);
 171 extern void dump_macro_definitions(void);
 172 extern struct symbol_list *sparse_initialize(int argc, char **argv, struct string_list **files);
 173 extern struct symbol_list *__sparse(char *filename);
 174 extern struct symbol_list *sparse_keep_tokens(char *filename);
 175 extern struct symbol_list *sparse(char *filename);
 176 extern void report_stats(void);
 177 
 178 static inline int symbol_list_size(struct symbol_list *list)
 179 {
 180         return ptr_list_size((struct ptr_list *)(list));
 181 }
 182 
 183 static inline int statement_list_size(struct statement_list *list)
 184 {
 185         return ptr_list_size((struct ptr_list *)(list));
 186 }
 187 
 188 static inline int expression_list_size(struct expression_list *list)
 189 {
 190         return ptr_list_size((struct ptr_list *)(list));
 191 }
 192 
 193 static inline int instruction_list_size(struct instruction_list *list)
 194 {
 195         return ptr_list_size((struct ptr_list *)(list));
 196 }
 197 
 198 static inline int pseudo_list_size(struct pseudo_list *list)
 199 {
 200         return ptr_list_size((struct ptr_list *)(list));
 201 }
 202 
 203 static inline int bb_list_size(struct basic_block_list *list)
 204 {
 205         return ptr_list_size((struct ptr_list *)(list));
 206 }
 207 
 208 static inline void free_instruction_list(struct instruction_list **head)
 209 {
 210         free_ptr_list((struct ptr_list **)head);
 211 }
 212 
 213 static inline struct instruction * delete_last_instruction(struct instruction_list **head)
 214 {
 215         return undo_ptr_list_last((struct ptr_list **)head);
 216 }
 217 
 218 static inline struct basic_block * delete_last_basic_block(struct basic_block_list **head)
 219 {
 220         return delete_ptr_list_last((struct ptr_list **)head);
 221 }
 222 
 223 static inline struct basic_block *first_basic_block(struct basic_block_list *head)
 224 {
 225         return first_ptr_list((struct ptr_list *)head);
 226 }
 227 static inline struct instruction *last_instruction(struct instruction_list *head)
 228 {
 229         return last_ptr_list((struct ptr_list *)head);
 230 }
 231 
 232 static inline struct instruction *first_instruction(struct instruction_list *head)
 233 {
 234         return first_ptr_list((struct ptr_list *)head);
 235 }
 236 
 237 static inline struct expression *first_expression(struct expression_list *head)
 238 {
 239         return first_ptr_list((struct ptr_list *)head);
 240 }
 241 
 242 static inline pseudo_t first_pseudo(struct pseudo_list *head)


   1 #ifndef LIB_H
   2 #define LIB_H
   3 
   4 #include <stdbool.h>
   5 #include <stdlib.h>
   6 #include <stddef.h>
   7 
   8 /*
   9  * Basic helper routine descriptions for 'sparse'.
  10  *
  11  * Copyright (C) 2003 Transmeta Corp.
  12  *               2003 Linus Torvalds
  13  *               2004 Christopher Li
  14  *
  15  * Permission is hereby granted, free of charge, to any person obtaining a copy
  16  * of this software and associated documentation files (the "Software"), to deal
  17  * in the Software without restriction, including without limitation the rights
  18  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  19  * copies of the Software, and to permit persons to whom the Software is
  20  * furnished to do so, subject to the following conditions:
  21  *
  22  * The above copyright notice and this permission notice shall be included in
  23  * all copies or substantial portions of the Software.
  24  *
  25  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  26  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  27  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  28  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  29  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  30  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  31  * THE SOFTWARE.
  32  */
  33 
  34 #include "compat.h"
  35 #include "ptrlist.h"
  36 #include "utils.h"
  37 #include "bits.h"
  38 
  39 #define DO_STRINGIFY(x) #x
  40 #define STRINGIFY(x) DO_STRINGIFY(x)
  41 
  42 #ifndef ARRAY_SIZE
  43 #define ARRAY_SIZE(x) (sizeof(x)/sizeof((x)[0]))
  44 #endif
  45 
  46 extern int verbose, optimize_level, optimize_size, preprocessing;
  47 extern int die_if_error;
  48 extern int parse_error;
  49 extern int repeat_phase;
  50 extern int do_output;
  51 extern int gcc_major, gcc_minor, gcc_patchlevel;
  52 
  53 extern const char *base_filename;
  54 
  55 extern unsigned int hexval(unsigned int c);
  56 
  57 struct position {
  58         unsigned int type:6,
  59                      stream:14,
  60                      newline:1,
  61                      whitespace:1,
  62                      pos:10;
  63         unsigned int line:31,
  64                      noexpand:1;
  65 };
  66 
  67 struct ident;
  68 struct token;
  69 struct symbol;
  70 struct statement;
  71 struct expression;
  72 struct basic_block;
  73 struct entrypoint;
  74 struct instruction;
  75 struct multijmp;
  76 struct pseudo;
  77 
  78 DECLARE_PTR_LIST(symbol_list, struct symbol);
  79 DECLARE_PTR_LIST(statement_list, struct statement);
  80 DECLARE_PTR_LIST(expression_list, struct expression);
  81 DECLARE_PTR_LIST(basic_block_list, struct basic_block);
  82 DECLARE_PTR_LIST(instruction_list, struct instruction);
  83 DECLARE_PTR_LIST(multijmp_list, struct multijmp);
  84 DECLARE_PTR_LIST(pseudo_list, struct pseudo);
  85 DECLARE_PTR_LIST(ident_list, struct ident);
  86 DECLARE_PTR_LIST(string_list, char);
  87 
  88 typedef struct pseudo *pseudo_t;
  89 
  90 struct token *skip_to(struct token *, int);
  91 struct token *expect(struct token *, int, const char *);
  92 void unexpected(struct token *, const char *errmsg);
  93 
  94 #ifdef __GNUC__
  95 #define FORMAT_ATTR(pos) __attribute__ ((__format__ (__printf__, pos, pos+1)))
  96 #define NORETURN_ATTR __attribute__ ((__noreturn__))
  97 #define SENTINEL_ATTR __attribute__ ((__sentinel__))
  98 #else
  99 #define FORMAT_ATTR(pos)
 100 #define NORETURN_ATTR
 101 #define SENTINEL_ATTR
 102 #endif
 103 
 104 FORMAT_ATTR(1) NORETURN_ATTR
 105 extern void die(const char *, ...);
 106 
 107 FORMAT_ATTR(2) NORETURN_ATTR
 108 extern void error_die(struct position, const char *, ...);
 109 
 110 extern void info(struct position, const char *, ...) FORMAT_ATTR(2);
 111 extern void warning(struct position, const char *, ...) FORMAT_ATTR(2);
 112 extern void sparse_error(struct position, const char *, ...) FORMAT_ATTR(2);
 113 extern void expression_error(struct expression *, const char *, ...) FORMAT_ATTR(2);
 114 
 115 #define ERROR_CURR_PHASE        (1 << 0)
 116 #define ERROR_PREV_PHASE        (1 << 1)
 117 extern int has_error;
 118 
 119 
 120 enum phase {
 121         PASS__PARSE,
 122         PASS__LINEARIZE,
 123         PASS__MEM2REG,
 124         PASS__OPTIM,
 125         PASS__FINAL,
 126 };
 127 
 128 #define PASS_PARSE              (1UL << PASS__PARSE)
 129 #define PASS_LINEARIZE          (1UL << PASS__LINEARIZE)
 130 #define PASS_MEM2REG            (1UL << PASS__MEM2REG)
 131 #define PASS_OPTIM              (1UL << PASS__OPTIM)
 132 #define PASS_FINAL              (1UL << PASS__FINAL)
 133 
 134 
 135 extern void add_pre_buffer(const char *fmt, ...) FORMAT_ATTR(1);
 136 extern void predefine(const char *name, int weak, const char *fmt, ...) FORMAT_ATTR(3);
 137 
 138 extern int preprocess_only;
 139 
 140 extern int Waddress;
 141 extern int Waddress_space;
 142 extern int Wbitwise;
 143 extern int Wbitwise_pointer;
 144 extern int Wcast_from_as;
 145 extern int Wcast_to_as;
 146 extern int Wcast_truncate;
 147 extern int Wconstant_suffix;
 148 extern int Wconstexpr_not_const;
 149 extern int Wcontext;
 150 extern int Wdecl;
 151 extern int Wdeclarationafterstatement;
 152 extern int Wdefault_bitfield_sign;
 153 extern int Wdesignated_init;
 154 extern int Wdo_while;
 155 extern int Wenum_mismatch;
 156 extern int Wexternal_function_has_definition;
 157 extern int Wsparse_error;
 158 extern int Wimplicit_int;
 159 extern int Winit_cstring;
 160 extern int Wint_to_pointer_cast;
 161 extern int Wmemcpy_max_count;
 162 extern int Wnon_pointer_null;
 163 extern int Wold_initializer;
 164 extern int Wold_style_definition;
 165 extern int Wone_bit_signed_bitfield;
 166 extern int Woverride_init;
 167 extern int Woverride_init_all;
 168 extern int Woverride_init_whole_range;
 169 extern int Wparen_string;
 170 extern int Wpointer_arith;
 171 extern int Wpointer_to_int_cast;
 172 extern int Wptr_subtraction_blows;
 173 extern int Wreturn_void;
 174 extern int Wshadow;
 175 extern int Wshift_count_negative;
 176 extern int Wshift_count_overflow;
 177 extern int Wsizeof_bool;
 178 extern int Wstrict_prototypes;
 179 extern int Wtautological_compare;
 180 extern int Wtransparent_union;
 181 extern int Wtypesign;
 182 extern int Wundef;
 183 extern int Wuninitialized;
 184 extern int Wunknown_attribute;
 185 extern int Wvla;
 186 
 187 extern int dump_macro_defs;
 188 extern int dump_macros_only;
 189 
 190 extern int dbg_compound;
 191 extern int dbg_dead;
 192 extern int dbg_domtree;
 193 extern int dbg_entry;
 194 extern int dbg_ir;
 195 extern int dbg_postorder;
 196 
 197 extern unsigned int fmax_warnings;
 198 extern int fmem_report;
 199 extern unsigned long fdump_ir;
 200 extern unsigned long long fmemcpy_max_count;
 201 extern unsigned long fpasses;
 202 extern int funsigned_char;
 203 
 204 extern int arch_m64;
 205 extern int arch_msize_long;
 206 extern int arch_big_endian;
 207 extern int arch_mach;
 208 


 209 extern void dump_macro_definitions(void);
 210 extern struct symbol_list *sparse_initialize(int argc, char **argv, struct string_list **files);
 211 extern struct symbol_list *__sparse(char *filename);
 212 extern struct symbol_list *sparse_keep_tokens(char *filename);
 213 extern struct symbol_list *sparse(char *filename);
 214 extern void report_stats(void);
 215 
 216 static inline int symbol_list_size(struct symbol_list *list)
 217 {
 218         return ptr_list_size((struct ptr_list *)(list));
 219 }
 220 
 221 static inline int statement_list_size(struct statement_list *list)
 222 {
 223         return ptr_list_size((struct ptr_list *)(list));
 224 }
 225 
 226 static inline int expression_list_size(struct expression_list *list)
 227 {
 228         return ptr_list_size((struct ptr_list *)(list));
 229 }
 230 
 231 static inline int instruction_list_size(struct instruction_list *list)
 232 {
 233         return ptr_list_size((struct ptr_list *)(list));
 234 }
 235 
 236 static inline int pseudo_list_size(struct pseudo_list *list)
 237 {
 238         return ptr_list_size((struct ptr_list *)(list));
 239 }
 240 
 241 static inline int bb_list_size(struct basic_block_list *list)
 242 {
 243         return ptr_list_size((struct ptr_list *)(list));
 244 }
 245 
 246 static inline void free_instruction_list(struct instruction_list **head)
 247 {
 248         free_ptr_list(head);
 249 }
 250 
 251 static inline struct instruction * delete_last_instruction(struct instruction_list **head)
 252 {
 253         return undo_ptr_list_last((struct ptr_list **)head);
 254 }
 255 





 256 static inline struct basic_block *first_basic_block(struct basic_block_list *head)
 257 {
 258         return first_ptr_list((struct ptr_list *)head);
 259 }
 260 static inline struct instruction *last_instruction(struct instruction_list *head)
 261 {
 262         return last_ptr_list((struct ptr_list *)head);
 263 }
 264 
 265 static inline struct instruction *first_instruction(struct instruction_list *head)
 266 {
 267         return first_ptr_list((struct ptr_list *)head);
 268 }
 269 
 270 static inline struct expression *first_expression(struct expression_list *head)
 271 {
 272         return first_ptr_list((struct ptr_list *)head);
 273 }
 274 
 275 static inline pseudo_t first_pseudo(struct pseudo_list *head)