Print this page
new smatch

Split Close
Expand all
Collapse all
          --- old/usr/src/tools/smatch/src/symbol.h
          +++ new/usr/src/tools/smatch/src/symbol.h
↓ open down ↓ 93 lines elided ↑ open up ↑
  94   94  };
  95   95  
  96   96  extern struct context *alloc_context(void);
  97   97  
  98   98  DECLARE_PTR_LIST(context_list, struct context);
  99   99  
 100  100  struct ctype {
 101  101          unsigned long modifiers;
 102  102          unsigned long alignment;
 103  103          struct context_list *contexts;
 104      -        unsigned int as;
      104 +        struct ident *as;
 105  105          struct symbol *base_type;
 106  106  };
 107  107  
 108  108  struct decl_state {
 109  109          struct ctype ctype;
 110  110          struct ident **ident;
 111  111          struct symbol_op *mode;
 112  112          unsigned char prefer_abstract, is_inline, storage_class, is_tls;
      113 +        unsigned char is_ext_visible;
 113  114  };
 114  115  
 115  116  struct symbol_op {
 116  117          enum keyword type;
 117  118          int (*evaluate)(struct expression *);
 118  119          int (*expand)(struct expression *, int);
 119  120          int (*args)(struct expression *);
 120  121  
 121  122          /* keywords */
 122  123          struct token *(*declarator)(struct token *token, struct decl_state *ctx);
 123  124          struct token *(*statement)(struct token *token, struct statement *stmt);
 124  125          struct token *(*toplevel)(struct token *token, struct symbol_list **list);
 125  126          struct token *(*attribute)(struct token *token, struct symbol *attr, struct decl_state *ctx);
 126  127          struct symbol *(*to_mode)(struct symbol *);
      128 +        void          (*asm_modifier)(struct token *token, unsigned long *mods);
 127  129  
 128  130          int test, set, class;
 129  131  };
 130  132  
 131  133  
 132  134  #define SYM_ATTR_WEAK           0
 133  135  #define SYM_ATTR_NORMAL         1
 134  136  #define SYM_ATTR_STRONG         2
 135  137  
 136  138  struct symbol {
↓ open down ↓ 11 lines elided ↑ open up ↑
 148  150                  struct symbol   *next_subobject;
 149  151          };
 150  152  
 151  153          struct symbol_op *op;
 152  154  
 153  155          union {
 154  156                  struct /* NS_MACRO */ {
 155  157                          struct token *expansion;
 156  158                          struct token *arglist;
 157  159                          struct scope *used_in;
      160 +                        void (*expander)(struct token *);
 158  161                  };
 159  162                  struct /* NS_PREPROCESSOR */ {
 160  163                          int (*handler)(struct stream *, struct token **, struct token *);
 161  164                          int normal;
 162  165                  };
 163  166                  struct /* NS_SYMBOL */ {
 164  167                          unsigned long   offset;
 165  168                          int             bit_size;
 166  169                          unsigned int    bit_offset:8,
 167      -                                        arg_count:10,
 168  170                                          variadic:1,
 169  171                                          initialized:1,
 170  172                                          examined:1,
 171  173                                          expanding:1,
 172  174                                          evaluated:1,
 173  175                                          string:1,
 174  176                                          designated_init:1,
 175  177                                          forced_arg:1,
      178 +                                        accessed:1,
      179 +                                        builtin:1,
      180 +                                        torename:1,
 176  181                                          transparent_union:1;
 177  182                          struct expression *array_size;
 178  183                          struct ctype ctype;
 179  184                          struct symbol_list *arguments;
 180  185                          struct statement *stmt;
 181  186                          struct symbol_list *symbol_list;
 182  187                          struct statement *inline_stmt;
 183  188                          struct symbol_list *inline_symbol_list;
 184  189                          struct expression *initializer;
 185  190                          struct entrypoint *ep;
 186      -                        long long value;                /* Initial value */
 187  191                          struct symbol *definition;
 188  192                  };
 189  193          };
 190  194          union /* backend */ {
 191  195                  struct basic_block *bb_target;  /* label */
 192  196                  void *aux;                      /* Auxiliary info, e.g. backend information */
 193  197                  struct {                        /* sparse ctags */
 194  198                          char kind;
 195  199                          unsigned char visited:1;
 196  200                  };
 197  201          };
 198  202          pseudo_t pseudo;
 199  203  };
 200  204  
 201  205  /* Modifiers */
 202      -#define MOD_AUTO        0x0001
 203      -#define MOD_REGISTER    0x0002
 204      -#define MOD_STATIC      0x0004
 205      -#define MOD_EXTERN      0x0008
      206 +#define MOD_AUTO                0x00000001
      207 +#define MOD_REGISTER            0x00000002
      208 +#define MOD_STATIC              0x00000004
      209 +#define MOD_EXTERN              0x00000008
      210 +#define MOD_TOPLEVEL            0x00000010      // scoping..
      211 +#define MOD_TLS                 0x00000020
      212 +#define MOD_ASM_GOTO            MOD_TLS         // never used together
      213 +#define MOD_INLINE              0x00000040
 206  214  
 207      -#define MOD_CONST       0x0010
 208      -#define MOD_VOLATILE    0x0020
 209      -#define MOD_SIGNED      0x0040
 210      -#define MOD_UNSIGNED    0x0080
      215 +#define MOD_ASSIGNED            0x00000080
      216 +#define MOD_ADDRESSABLE         0x00000100
 211  217  
 212      -#define MOD_CHAR        0x0100
 213      -#define MOD_SHORT       0x0200
 214      -#define MOD_LONG        0x0400
 215      -#define MOD_LONGLONG    0x0800
 216      -#define MOD_LONGLONGLONG        0x1000
 217      -#define MOD_PURE        0x2000
      218 +#define MOD_CONST               0x00000200
      219 +#define MOD_VOLATILE            0x00000400
      220 +#define MOD_RESTRICT            0x00000800
      221 +#define MOD_ATOMIC              0x00001000
 218  222  
 219      -#define MOD_TYPEDEF     0x10000
      223 +#define MOD_SIGNED              0x00002000
      224 +#define MOD_UNSIGNED            0x00004000
      225 +#define MOD_EXPLICITLY_SIGNED   0x00008000
 220  226  
 221      -#define MOD_TLS         0x20000
 222      -#define MOD_INLINE      0x40000
 223      -#define MOD_ADDRESSABLE 0x80000
      227 +#define MOD_TYPE                0x00010000
      228 +#define MOD_USERTYPE            0x00020000
      229 +#define MOD_CHAR                0x00040000
      230 +#define MOD_SHORT               0x00080000
      231 +#define MOD_LONG                0x00100000
      232 +#define MOD_LONGLONG            0x00200000
      233 +#define MOD_LONGLONGLONG        0x00400000
 224  234  
 225      -#define MOD_NOCAST      0x100000
 226      -#define MOD_NODEREF     0x200000
 227      -#define MOD_ACCESSED    0x400000
 228      -#define MOD_TOPLEVEL    0x800000        // scoping..
      235 +#define MOD_SAFE                0x00800000      // non-null/non-trapping pointer
      236 +#define MOD_PURE                0x01000000
      237 +#define MOD_BITWISE             0x02000000
      238 +#define MOD_NOCAST              0x04000000
      239 +#define MOD_NODEREF             0x08000000
      240 +#define MOD_NORETURN            0x10000000
      241 +#define MOD_EXT_VISIBLE         0x20000000
 229  242  
 230      -#define MOD_ASSIGNED    0x2000000
 231      -#define MOD_TYPE        0x4000000
 232      -#define MOD_SAFE        0x8000000       // non-null/non-trapping pointer
 233  243  
 234      -#define MOD_USERTYPE    0x10000000
 235      -#define MOD_NORETURN    0x20000000
 236      -#define MOD_EXPLICITLY_SIGNED   0x40000000
 237      -#define MOD_BITWISE     0x80000000
 238      -
 239      -
      244 +#define MOD_ACCESS      (MOD_ASSIGNED | MOD_ADDRESSABLE)
 240  245  #define MOD_NONLOCAL    (MOD_EXTERN | MOD_TOPLEVEL)
 241  246  #define MOD_STORAGE     (MOD_AUTO | MOD_REGISTER | MOD_STATIC | MOD_EXTERN | MOD_INLINE | MOD_TOPLEVEL)
 242  247  #define MOD_SIGNEDNESS  (MOD_SIGNED | MOD_UNSIGNED | MOD_EXPLICITLY_SIGNED)
 243  248  #define MOD_LONG_ALL    (MOD_LONG | MOD_LONGLONG | MOD_LONGLONGLONG)
 244  249  #define MOD_SPECIFIER   (MOD_CHAR | MOD_SHORT | MOD_LONG_ALL | MOD_SIGNEDNESS)
 245  250  #define MOD_SIZE        (MOD_CHAR | MOD_SHORT | MOD_LONG_ALL)
 246      -#define MOD_IGNORE (MOD_TOPLEVEL | MOD_STORAGE | MOD_ADDRESSABLE |      \
 247      -        MOD_ASSIGNED | MOD_USERTYPE | MOD_ACCESSED | MOD_EXPLICITLY_SIGNED)
 248      -#define MOD_PTRINHERIT (MOD_VOLATILE | MOD_CONST | MOD_NODEREF | MOD_NORETURN | MOD_NOCAST)
      251 +#define MOD_IGNORE      (MOD_STORAGE | MOD_ACCESS | MOD_USERTYPE | MOD_EXPLICITLY_SIGNED | MOD_EXT_VISIBLE)
      252 +#define MOD_QUALIFIER   (MOD_CONST | MOD_VOLATILE | MOD_RESTRICT | MOD_ATOMIC)
      253 +#define MOD_PTRINHERIT  (MOD_QUALIFIER | MOD_NODEREF | MOD_NORETURN | MOD_NOCAST)
 249  254  /* modifiers preserved by typeof() operator */
 250      -#define MOD_TYPEOF      (MOD_VOLATILE | MOD_CONST | MOD_NOCAST | MOD_SPECIFIER)
      255 +#define MOD_TYPEOF      (MOD_QUALIFIER | MOD_NOCAST | MOD_SPECIFIER)
 251  256  
 252  257  
 253  258  /* Current parsing/evaluation function */
 254  259  extern struct symbol *current_fn;
 255  260  
 256  261  /* Abstract types */
 257  262  extern struct symbol    int_type,
 258  263                          fp_type;
 259  264  
 260  265  /* C types */
↓ open down ↓ 1 lines elided ↑ open up ↑
 262  267                          char_ctype, schar_ctype, uchar_ctype,
 263  268                          short_ctype, sshort_ctype, ushort_ctype,
 264  269                          int_ctype, sint_ctype, uint_ctype,
 265  270                          long_ctype, slong_ctype, ulong_ctype,
 266  271                          llong_ctype, sllong_ctype, ullong_ctype,
 267  272                          lllong_ctype, slllong_ctype, ulllong_ctype,
 268  273                          float_ctype, double_ctype, ldouble_ctype,
 269  274                          string_ctype, ptr_ctype, lazy_ptr_ctype,
 270  275                          incomplete_ctype, label_ctype, bad_ctype,
 271  276                          null_ctype;
      277 +extern struct symbol    int_ptr_ctype, uint_ptr_ctype;
      278 +extern struct symbol    long_ptr_ctype, ulong_ptr_ctype;
      279 +extern struct symbol    llong_ptr_ctype, ullong_ptr_ctype;
      280 +extern struct symbol    float32_ctype, float32x_ctype;
      281 +extern struct symbol    float64_ctype, float64x_ctype;
      282 +extern struct symbol    float128_ctype;
      283 +extern struct symbol    const_void_ctype, const_char_ctype;
      284 +extern struct symbol    const_ptr_ctype, const_string_ctype;
 272  285  
      286 +#define uintptr_ctype    size_t_ctype
      287 +#define  intptr_ctype   ssize_t_ctype
      288 +
 273  289  /* Special internal symbols */
 274  290  extern struct symbol    zero_int;
 275  291  
 276  292  #define __IDENT(n,str,res) \
 277  293          extern struct ident n
 278  294  #include "ident-list.h"
 279  295  
 280      -#define symbol_is_typename(sym) ((sym)->type == SYM_TYPE)
 281  296  
 282  297  extern struct symbol_list *translation_unit_used_list;
 283  298  
 284  299  extern void access_symbol(struct symbol *);
 285  300  
 286  301  extern const char * type_difference(struct ctype *c1, struct ctype *c2,
 287  302          unsigned long mod1, unsigned long mod2);
 288  303  
 289  304  extern struct symbol *lookup_symbol(struct ident *, enum namespace);
 290  305  extern struct symbol *create_symbol(int stream, const char *name, int type, int namespace);
 291  306  extern void init_symbols(void);
 292  307  extern void init_builtins(int stream);
      308 +extern void declare_builtins(void);
 293  309  extern void init_ctype(void);
      310 +extern void init_target(void);
 294  311  extern struct symbol *alloc_symbol(struct position, int type);
 295  312  extern void show_type(struct symbol *);
 296  313  extern const char *modifier_string(unsigned long mod);
 297  314  extern void show_symbol(struct symbol *);
 298  315  extern int show_symbol_expr_init(struct symbol *sym);
 299  316  extern void show_type_list(struct symbol *);
 300  317  extern void show_symbol_list(struct symbol_list *, const char *);
 301  318  extern void add_symbol(struct symbol_list **, struct symbol *);
 302  319  extern void bind_symbol(struct symbol *, struct ident *, enum namespace);
 303  320  
 304  321  extern struct symbol *examine_symbol_type(struct symbol *);
 305  322  extern struct symbol *examine_pointer_target(struct symbol *);
 306      -extern void examine_simple_symbol_type(struct symbol *);
      323 +extern const char *show_as(struct ident *as);
 307  324  extern const char *show_typename(struct symbol *sym);
 308  325  extern const char *builtin_typename(struct symbol *sym);
      326 +extern const char *builtin_type_suffix(struct symbol *sym);
 309  327  extern const char *builtin_ctypename(struct ctype *ctype);
 310  328  extern const char* get_type_name(enum type type);
 311  329  
 312  330  extern void debug_symbol(struct symbol *);
 313  331  extern void merge_type(struct symbol *sym, struct symbol *base_type);
 314  332  extern void check_declaration(struct symbol *sym);
      333 +extern void check_duplicates(struct symbol *sym);
 315  334  
      335 +static inline int valid_type(const struct symbol *ctype)
      336 +{
      337 +        return ctype && ctype != &bad_ctype;
      338 +}
      339 +
 316  340  static inline struct symbol *get_base_type(const struct symbol *sym)
 317  341  {
 318  342          return examine_symbol_type(sym->ctype.base_type);
 319  343  }
 320  344  
      345 +///
      346 +// test if type is an integer type
      347 +//
      348 +// @return: ``1`` for plain integer type, enums & bitfields
      349 +//      but ``0`` for bitwise types!
 321  350  static inline int is_int_type(const struct symbol *type)
 322  351  {
 323  352          if (type->type == SYM_NODE)
 324  353                  type = type->ctype.base_type;
 325  354          if (type->type == SYM_ENUM)
 326  355                  type = type->ctype.base_type;
 327  356          return type->type == SYM_BITFIELD ||
 328  357                 type->ctype.base_type == &int_type;
 329  358  }
 330  359  
 331  360  static inline int is_enum_type(const struct symbol *type)
 332  361  {
 333  362          if (type->type == SYM_NODE)
 334  363                  type = type->ctype.base_type;
 335  364          return (type->type == SYM_ENUM);
 336  365  }
 337  366  
      367 +static inline int is_signed_type(struct symbol *sym)
      368 +{
      369 +        if (sym->type == SYM_NODE)
      370 +                sym = sym->ctype.base_type;
      371 +        if (sym->type == SYM_PTR)
      372 +                return 0;
      373 +        return !(sym->ctype.modifiers & MOD_UNSIGNED);
      374 +}
      375 +
 338  376  static inline int is_type_type(struct symbol *type)
 339  377  {
 340  378          return (type->ctype.modifiers & MOD_TYPE) != 0;
 341  379  }
 342  380  
 343  381  static inline int is_ptr_type(struct symbol *type)
 344  382  {
 345  383          if (!type)
 346  384                  return 0;
 347  385          if (type->type == SYM_NODE)
↓ open down ↓ 54 lines elided ↑ open up ↑
 402  440          default:
 403  441                  break;
 404  442          }
 405  443          if (type->ctype.base_type == &int_type)
 406  444                  return 1;
 407  445          if (type->ctype.base_type == &fp_type)
 408  446                  return 1;
 409  447          return 0;
 410  448  }
 411  449  
      450 +/// return true for integer & pointer types
      451 +static inline bool is_integral_type(struct symbol *type)
      452 +{
      453 +        if (type->type == SYM_NODE)
      454 +                type = type->ctype.base_type;
      455 +        switch (type->type) {
      456 +        case SYM_ENUM:
      457 +        case SYM_PTR:
      458 +        case SYM_RESTRICT:      // OK, always integer types
      459 +                return 1;
      460 +        default:
      461 +                break;
      462 +        }
      463 +        if (type->ctype.base_type == &int_type)
      464 +                return 1;
      465 +        return 0;
      466 +}
      467 +
 412  468  static inline int is_function(struct symbol *type)
 413  469  {
 414  470          return type && type->type == SYM_FN;
 415  471  }
 416  472  
 417  473  static inline int is_extern_inline(struct symbol *sym)
 418  474  {
 419  475          return (sym->ctype.modifiers & MOD_EXTERN) &&
 420  476                  (sym->ctype.modifiers & MOD_INLINE) &&
 421  477                  is_function(sym->ctype.base_type);
↓ open down ↓ 1 lines elided ↑ open up ↑
 423  479  
 424  480  static inline int get_sym_type(struct symbol *type)
 425  481  {
 426  482          if (type->type == SYM_NODE)
 427  483                  type = type->ctype.base_type;
 428  484          if (type->type == SYM_ENUM)
 429  485                  type = type->ctype.base_type;
 430  486          return type->type;
 431  487  }
 432  488  
      489 +static inline long long extend_value(long long val, struct symbol *ctype)
      490 +{
      491 +        int is_signed = !(ctype->ctype.modifiers & MOD_UNSIGNED);
      492 +        unsigned size = ctype->bit_size;
      493 +
      494 +        return bits_extend(val, size, is_signed);
      495 +}
      496 +
 433  497  static inline struct symbol *lookup_keyword(struct ident *ident, enum namespace ns)
 434  498  {
 435  499          if (!ident->keyword)
 436  500                  return NULL;
 437  501          return lookup_symbol(ident, ns);
 438  502  }
 439  503  
 440  504  #define is_restricted_type(type) (get_sym_type(type) == SYM_RESTRICT)
 441  505  #define is_fouled_type(type) (get_sym_type(type) == SYM_FOULED)
 442  506  #define is_bitfield_type(type)   (get_sym_type(type) == SYM_BITFIELD)
 443      -extern int is_ptr_type(struct symbol *);
 444  507  
 445  508  void create_fouled(struct symbol *type);
 446  509  struct symbol *befoul(struct symbol *type);
 447  510  
      511 +
      512 +extern struct ident bad_address_space;
      513 +
      514 +static inline bool valid_as(struct ident *as)
      515 +{
      516 +        return as && as != &bad_address_space;
      517 +}
      518 +
      519 +static inline void combine_address_space(struct position pos,
      520 +        struct ident **tas, struct ident *sas)
      521 +{
      522 +        struct ident *as;
      523 +        if (!sas)
      524 +                return;
      525 +        as = *tas;
      526 +        if (!as)
      527 +                *tas = sas;
      528 +        else if (as != sas) {
      529 +                *tas = &bad_address_space;
      530 +                sparse_error(pos, "multiple address spaces given");
      531 +        }
      532 +}
      533 +
 448  534  #endif /* SYMBOL_H */
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX