Annotation of src/usr.bin/xlint/lint1/lint1.h, Revision 1.112
1.112 ! rillig 1: /* $NetBSD: lint1.h,v 1.111 2021/07/05 19:48:32 rillig Exp $ */
1.2 cgd 2:
1.1 cgd 3: /*
1.7 cgd 4: * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
1.1 cgd 5: * Copyright (c) 1994, 1995 Jochen Pohl
6: * All Rights Reserved.
7: *
8: * Redistribution and use in source and binary forms, with or without
9: * modification, are permitted provided that the following conditions
10: * are met:
11: * 1. Redistributions of source code must retain the above copyright
12: * notice, this list of conditions and the following disclaimer.
13: * 2. Redistributions in binary form must reproduce the above copyright
14: * notice, this list of conditions and the following disclaimer in the
15: * documentation and/or other materials provided with the distribution.
16: * 3. All advertising materials mentioning features or use of this software
17: * must display the following acknowledgement:
18: * This product includes software developed by Jochen Pohl for
19: * The NetBSD Project.
20: * 4. The name of the author may not be used to endorse or promote products
21: * derived from this software without specific prior written permission.
22: *
23: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
27: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33: */
34:
35: #include "lint.h"
1.49 rillig 36: #include "err-msgs.h"
1.1 cgd 37: #include "op.h"
1.12 tv 38:
1.25 christos 39: /*
40: * XXX - Super conservative so that works for most systems, but we should
41: * not depend on the host settings but the target settings in determining
42: * the alignment. The only valid use for this is in mem1.c; uses in decl.c
43: * are bogus.
44: */
45: #ifndef WORST_ALIGN
46: #ifdef _LP64
47: # define AVAL 15
48: #else
49: # define AVAL 7
50: #endif
51: #define WORST_ALIGN(x) (((x) + AVAL) & ~AVAL)
1.12 tv 52: #endif
1.1 cgd 53:
1.53 rillig 54: #define LWARN_BAD (-3)
55: #define LWARN_ALL (-2)
56: #define LWARN_NONE (-1)
1.27 christos 57:
1.1 cgd 58: /*
59: * Describes the position of a declaration or anything else.
1.96 rillig 60: *
61: * FIXME: Just a single file:lineno pair is not enough to accurately describe
62: * the position of a symbol. The whole inclusion path at that point must be
63: * stored as well. This makes a difference for symbols from included
64: * headers, see print_stack_trace.
1.1 cgd 65: */
66: typedef struct {
1.92 rillig 67: const char *p_file;
1.1 cgd 68: int p_line;
1.7 cgd 69: int p_uniq; /* uniquifier */
1.1 cgd 70: } pos_t;
1.7 cgd 71:
72: /* Copies curr_pos, keeping things unique. */
1.34 rillig 73: #define UNIQUE_CURR_POS(pos) \
74: do { \
1.45 rillig 75: (pos) = curr_pos; \
1.34 rillig 76: curr_pos.p_uniq++; \
77: if (curr_pos.p_file == csrc_pos.p_file) \
78: csrc_pos.p_uniq++; \
1.100 rillig 79: } while (false)
1.1 cgd 80:
81: /*
82: * Strings cannot be referenced to simply by a pointer to its first
83: * char. This is because strings can contain NUL characters other than the
84: * trailing NUL.
85: *
86: * Strings are stored with a trailing NUL.
87: */
88: typedef struct strg {
89: tspec_t st_tspec; /* CHAR or WCHAR */
90: size_t st_len; /* length without trailing NUL */
91: union {
92: u_char *_st_cp;
93: wchar_t *_st_wcp;
94: } st_u;
95: } strg_t;
96:
97: #define st_cp st_u._st_cp
98: #define st_wcp st_u._st_wcp
99:
100: /*
101: * qualifiers (only for lex/yacc interface)
102: */
103: typedef enum {
1.31 christos 104: CONST, VOLATILE, RESTRICT, THREAD
1.1 cgd 105: } tqual_t;
106:
1.104 rillig 107: /* An integer or floating-point value. */
1.1 cgd 108: typedef struct {
109: tspec_t v_tspec;
1.105 rillig 110: /*
111: * Set if an integer constant is unsigned only in C90 and later, but
112: * not in traditional C.
113: *
114: * See the operators table in ops.def, columns "l r".
115: */
116: bool v_unsigned_since_c90;
1.1 cgd 117: union {
1.13 thorpej 118: int64_t _v_quad; /* integers */
1.1 cgd 119: ldbl_t _v_ldbl; /* floats */
120: } v_u;
121: } val_t;
122:
123: #define v_quad v_u._v_quad
124: #define v_ldbl v_u._v_ldbl
125:
126: /*
1.62 rillig 127: * Structures of type struct_or_union uniquely identify structures. This can't
1.1 cgd 128: * be done in structures of type type_t, because these are copied
129: * if they must be modified. So it would not be possible to check
1.29 dholland 130: * if two structures are identical by comparing the pointers to
1.1 cgd 131: * the type structures.
132: *
133: * The typename is used if the structure is unnamed to identify
134: * the structure type in pass 2.
135: */
136: typedef struct {
1.75 rillig 137: u_int sou_size_in_bits;
138: u_int sou_align_in_bits : 15;
1.62 rillig 139: bool sou_incomplete : 1;
140: struct sym *sou_first_member;
141: struct sym *sou_tag;
142: struct sym *sou_first_typedef;
143: } struct_or_union;
1.1 cgd 144:
145: /*
146: * same as above for enums
147: */
148: typedef struct {
1.63 rillig 149: bool en_incomplete : 1;
150: struct sym *en_first_enumerator;
151: struct sym *en_tag;
152: struct sym *en_first_typedef;
153: } enumeration;
1.1 cgd 154:
155: /*
1.93 rillig 156: * The type of an expression or object. Complex types are formed via t_subt
157: * (for arrays, pointers and functions), as well as t_str.
1.1 cgd 158: */
1.94 rillig 159: struct lint1_type {
1.1 cgd 160: tspec_t t_tspec; /* type specifier */
1.64 rillig 161: bool t_incomplete_array : 1;
1.47 rillig 162: bool t_const : 1; /* const modifier */
163: bool t_volatile : 1; /* volatile modifier */
164: bool t_proto : 1; /* function prototype (t_args valid) */
1.58 rillig 165: bool t_vararg : 1; /* prototype with '...' */
1.47 rillig 166: bool t_typedef : 1; /* type defined with typedef */
1.50 rillig 167: bool t_bitfield : 1;
1.109 rillig 168: /*
169: * Either the type is currently an enum (having t_tspec ENUM), or
170: * it is an integer type (typically INT) that has been implicitly
171: * converted from an enum type. In both cases, t_enum is valid.
172: *
173: * The information about a former enum type is retained to allow
174: * type checks in expressions such as ((var1 & 0x0001) == var2), to
175: * detect when var1 and var2 are from incompatible enum types.
176: */
177: bool t_is_enum : 1;
1.51 rillig 178: bool t_packed : 1;
1.1 cgd 179: union {
1.74 rillig 180: int _t_dim; /* dimension (if ARRAY) */
1.63 rillig 181: struct_or_union *_t_str;
182: enumeration *_t_enum;
1.1 cgd 183: struct sym *_t_args; /* arguments (if t_proto) */
184: } t_u;
1.8 pk 185: struct {
186: u_int _t_flen : 8; /* length of bit-field */
187: u_int _t_foffs : 24; /* offset of bit-field */
188: } t_b;
1.94 rillig 189: struct lint1_type *t_subt; /* element type (if ARRAY),
190: * return value (if FUNC),
191: * target type (if PTR) */
1.17 christos 192: };
1.1 cgd 193:
194: #define t_dim t_u._t_dim
195: #define t_str t_u._t_str
196: #define t_enum t_u._t_enum
197: #define t_args t_u._t_args
1.8 pk 198: #define t_flen t_b._t_flen
199: #define t_foffs t_b._t_foffs
1.1 cgd 200:
201: /*
202: * types of symbols
203: */
204: typedef enum {
205: FVFT, /* variables, functions, type names, enums */
1.39 rillig 206: FMEMBER, /* members of structs or unions */
1.1 cgd 207: FTAG, /* tags */
1.39 rillig 208: FLABEL /* labels */
1.1 cgd 209: } symt_t;
210:
211: /*
212: * storage classes
213: */
214: typedef enum {
215: NOSCL,
216: EXTERN, /* external symbols (indep. of decl_t) */
217: STATIC, /* static symbols (local and global) */
218: AUTO, /* automatic symbols (except register) */
219: REG, /* register */
220: TYPEDEF, /* typedef */
1.65 rillig 221: STRUCT_TAG,
222: UNION_TAG,
223: ENUM_TAG,
1.1 cgd 224: MOS, /* member of struct */
225: MOU, /* member of union */
1.56 rillig 226: CTCONST, /* enumerator, enum constant or bool constant */
1.1 cgd 227: ABSTRACT, /* abstract symbol (sizeof, casts, unnamed argument) */
228: ARG, /* argument */
1.65 rillig 229: PROTO_ARG, /* used in declaration stack during prototype
1.1 cgd 230: declaration */
1.4 jpo 231: INLINE /* only used by the parser */
1.1 cgd 232: } scl_t;
233:
234: /*
235: * symbol table entry
236: */
237: typedef struct sym {
1.33 rillig 238: const char *s_name;
1.9 cgd 239: const char *s_rename; /* renamed symbol's given name */
1.44 rillig 240: pos_t s_def_pos; /* position of last (prototype) definition,
1.39 rillig 241: prototype declaration, no-prototype-def.,
1.1 cgd 242: tentative definition or declaration,
243: in this order */
1.66 rillig 244: pos_t s_set_pos; /* position of first initialization */
1.44 rillig 245: pos_t s_use_pos; /* position of first use */
1.1 cgd 246: symt_t s_kind; /* type of symbol */
1.43 rillig 247: void *s_keyword;
1.47 rillig 248: bool s_bitfield : 1;
249: bool s_set : 1; /* variable set, label defined */
250: bool s_used : 1; /* variable/label used */
251: bool s_arg : 1; /* symbol is function argument */
252: bool s_reg : 1; /* symbol is register variable */
253: bool s_defarg : 1; /* undefined symbol in old style function
1.1 cgd 254: definition */
1.61 rillig 255: bool s_return_type_implicit_int : 1;
1.47 rillig 256: bool s_osdef : 1; /* symbol stems from old style function def. */
257: bool s_inline : 1; /* true if this is an inline function */
1.43 rillig 258: struct sym *s_ext_sym; /* for local declared external symbols pointer
1.1 cgd 259: to external symbol with same name */
260: def_t s_def; /* declared, tentative defined, defined */
261: scl_t s_scl; /* storage class */
1.71 rillig 262: int s_block_level; /* level of declaration, -1 if not in symbol
1.1 cgd 263: table */
1.33 rillig 264: type_t *s_type;
1.56 rillig 265: val_t s_value; /* value (if enum or bool constant) */
1.1 cgd 266: union {
1.62 rillig 267: struct_or_union *_s_st;
1.63 rillig 268: enumeration *_s_et;
1.1 cgd 269: tspec_t _s_tsp; /* type (only for keywords) */
270: tqual_t _s_tqu; /* qualifier (only for keywords) */
271: struct sym *_s_args; /* arguments in old style function
272: definitions */
273: } u;
274: struct sym *s_link; /* next symbol with same hash value */
275: struct sym **s_rlink; /* pointer to s_link of prev. symbol */
1.38 rillig 276: struct sym *s_next; /* next struct/union member, enumerator,
1.1 cgd 277: argument */
1.34 rillig 278: struct sym *s_dlnxt; /* next symbol declared on same level */
1.1 cgd 279: } sym_t;
280:
281: #define s_styp u._s_st
282: #define s_etyp u._s_et
283: #define s_tspec u._s_tsp
284: #define s_tqual u._s_tqu
285: #define s_args u._s_args
286:
287: /*
1.35 rillig 288: * Used to keep some information about symbols before they are entered
1.1 cgd 289: * into the symbol table.
290: */
291: typedef struct sbuf {
292: const char *sb_name; /* name of symbol */
293: size_t sb_len; /* length (without '\0') */
294: int sb_hash; /* hash value */
295: sym_t *sb_sym; /* symbol table entry */
1.40 rillig 296: struct sbuf *sb_next; /* for freelist */
1.1 cgd 297: } sbuf_t;
298:
299:
300: /*
301: * tree node
302: */
303: typedef struct tnode {
304: op_t tn_op; /* operator */
305: type_t *tn_type; /* type */
1.47 rillig 306: bool tn_lvalue : 1; /* node is lvalue */
307: bool tn_cast : 1; /* if tn_op == CVT, it's an explicit cast */
308: bool tn_parenthesized : 1;
1.110 rillig 309: bool tn_relaxed : 1; /* in strict bool mode, allow mixture between
310: * bool and scalar, for backwards
311: * compatibility
312: */
1.86 rillig 313: bool tn_system_dependent : 1; /* depends on sizeof or offsetof */
1.1 cgd 314: union {
315: struct {
316: struct tnode *_tn_left; /* (left) operand */
317: struct tnode *_tn_right; /* right operand */
318: } tn_s;
319: sym_t *_tn_sym; /* symbol if op == NAME */
320: val_t *_tn_val; /* value if op == CON */
1.42 rillig 321: strg_t *_tn_string; /* string if op == STRING */
1.1 cgd 322: } tn_u;
323: } tnode_t;
324:
1.98 rillig 325: #define tn_left tn_u.tn_s._tn_left
326: #define tn_right tn_u.tn_s._tn_right
327: #define tn_sym tn_u._tn_sym
328: #define tn_val tn_u._tn_val
1.42 rillig 329: #define tn_string tn_u._tn_string
1.1 cgd 330:
1.112 ! rillig 331: struct generic_association {
! 332: type_t *ga_arg; /* NULL means default or error */
! 333: tnode_t *ga_result; /* NULL means error */
! 334: struct generic_association *ga_prev;
1.107 rillig 335: };
336:
1.1 cgd 337: /*
338: * For nested declarations a stack exists, which holds all information
1.76 rillig 339: * needed for the current level. dcs points to the innermost element of this
1.1 cgd 340: * stack.
341: *
1.73 rillig 342: * d_ctx describes the context of the current declaration. Its value is
1.1 cgd 343: * one of
1.65 rillig 344: * EXTERN global declarations
345: * MOS or MOU declarations of struct or union members
1.76 rillig 346: * CTCONST declarations of enums or boolean constants
347: * ARG declaration of arguments in old-style function
1.65 rillig 348: * definitions
349: * PROTO_ARG declaration of arguments in function prototypes
350: * AUTO declaration of local symbols
351: * ABSTRACT abstract declarations (sizeof, casts)
1.1 cgd 352: *
353: */
354: typedef struct dinfo {
1.72 rillig 355: tspec_t d_abstract_type;/* VOID, BOOL, CHAR, INT or COMPLEX */
356: tspec_t d_complex_mod; /* FLOAT or DOUBLE */
357: tspec_t d_sign_mod; /* SIGNED or UNSIGN */
358: tspec_t d_rank_mod; /* SHORT, LONG or QUAD */
1.3 jpo 359: scl_t d_scl; /* storage class */
360: type_t *d_type; /* after deftyp() pointer to the type used
1.1 cgd 361: for all declarators */
1.78 rillig 362: sym_t *d_redeclared_symbol;
1.3 jpo 363: int d_offset; /* offset of next structure member */
1.111 rillig 364: int d_sou_align_in_bits; /* alignment required for current
365: * structure */
1.3 jpo 366: scl_t d_ctx; /* context of declaration */
1.47 rillig 367: bool d_const : 1; /* const in declaration specifiers */
368: bool d_volatile : 1; /* volatile in declaration specifiers */
369: bool d_inline : 1; /* inline in declaration specifiers */
370: bool d_mscl : 1; /* multiple storage classes */
371: bool d_terr : 1; /* invalid type combination */
1.79 rillig 372: bool d_nonempty_decl : 1; /* if at least one tag is declared
373: * ... in the current function decl. */
374: bool d_vararg : 1;
1.47 rillig 375: bool d_proto : 1; /* current function decl. is prototype */
376: bool d_notyp : 1; /* set if no type specifier was present */
377: bool d_asm : 1; /* set if d_ctx == AUTO and asm() present */
1.51 rillig 378: bool d_packed : 1;
379: bool d_used : 1;
1.3 jpo 380: type_t *d_tagtyp; /* tag during member declaration */
1.80 rillig 381: sym_t *d_func_args; /* list of arguments during function def. */
382: pos_t d_func_def_pos; /* position of function definition */
1.3 jpo 383: sym_t *d_dlsyms; /* first symbol declared at this level */
384: sym_t **d_ldlsym; /* points to s_dlnxt in last symbol decl.
1.1 cgd 385: at this level */
1.80 rillig 386: sym_t *d_func_proto_syms; /* symbols defined in prototype */
1.41 rillig 387: struct dinfo *d_next; /* next level */
1.1 cgd 388: } dinfo_t;
389:
1.108 rillig 390: /* One level of pointer indirection in declarators, including qualifiers. */
391: typedef struct qual_ptr {
1.106 rillig 392: bool p_const: 1;
393: bool p_volatile: 1;
1.108 rillig 394: bool p_pointer: 1;
395: struct qual_ptr *p_next;
396: } qual_ptr;
1.1 cgd 397:
398: /*
1.93 rillig 399: * The values of the 'case' labels, linked via cl_next in reverse order of
400: * appearance in the code, that is from bottom to top.
1.1 cgd 401: */
1.77 rillig 402: typedef struct case_label {
1.1 cgd 403: val_t cl_val;
1.77 rillig 404: struct case_label *cl_next;
405: } case_label_t;
1.1 cgd 406:
1.88 rillig 407: typedef enum {
408: CS_DO_WHILE,
409: CS_FOR,
410: CS_FUNCTION_BODY,
411: CS_IF,
412: CS_SWITCH,
413: CS_WHILE
414: } control_statement_kind;
415:
1.1 cgd 416: /*
1.35 rillig 417: * Used to keep information about nested control statements.
1.1 cgd 418: */
1.52 rillig 419: typedef struct control_statement {
1.88 rillig 420: control_statement_kind c_kind; /* to ensure proper nesting */
1.89 rillig 421: bool c_loop : 1; /* 'continue' and 'break' are valid */
422: bool c_switch : 1; /* 'case' and 'break' are valid */
1.83 rillig 423: bool c_break : 1; /* the loop/switch has a reachable
1.89 rillig 424: * 'break' statement */
425: bool c_continue : 1; /* the loop has a reachable 'continue'
426: * statement */
427: bool c_default : 1; /* the switch has a 'default' label */
1.82 rillig 428: bool c_maybe_endless : 1; /* the controlling expression is
429: * always true (as in 'for (;;)' or
430: * 'while (1)'), there may be break
431: * statements though */
1.86 rillig 432: bool c_always_then : 1;
1.85 rillig 433: bool c_reached_end_of_then : 1;
1.59 rillig 434: bool c_had_return_noval : 1; /* had "return;" */
1.89 rillig 435: bool c_had_return_value : 1; /* had "return expr;" */
436:
437: type_t *c_switch_type; /* type of switch expression */
1.101 rillig 438: tnode_t *c_switch_expr;
1.77 rillig 439: case_label_t *c_case_labels; /* list of case values */
1.89 rillig 440:
1.91 rillig 441: struct memory_block *c_for_expr3_mem; /* saved memory for end of loop
1.89 rillig 442: * expression in for() */
443: tnode_t *c_for_expr3; /* end of loop expr in for() */
444: pos_t c_for_expr3_pos; /* position of end of loop expr */
445: pos_t c_for_expr3_csrc_pos; /* same for csrc_pos */
446:
1.52 rillig 447: struct control_statement *c_surrounding;
1.1 cgd 448: } cstk_t;
449:
1.18 christos 450: typedef struct {
1.70 rillig 451: size_t lo; /* inclusive */
452: size_t hi; /* inclusive */
1.18 christos 453: } range_t;
454:
1.1 cgd 455: #include "externs1.h"
1.11 augustss 456:
457: #define ERR_SETSIZE 1024
458: #define __NERRBITS (sizeof(unsigned int))
459:
460: typedef struct err_set {
461: unsigned int errs_bits[(ERR_SETSIZE + __NERRBITS-1) / __NERRBITS];
462: } err_set;
463:
464: #define ERR_SET(n, p) \
1.34 rillig 465: ((p)->errs_bits[(n)/__NERRBITS] |= (1 << ((n) % __NERRBITS)))
1.11 augustss 466: #define ERR_CLR(n, p) \
1.34 rillig 467: ((p)->errs_bits[(n)/__NERRBITS] &= ~(1 << ((n) % __NERRBITS)))
1.11 augustss 468: #define ERR_ISSET(n, p) \
1.55 rillig 469: (((p)->errs_bits[(n)/__NERRBITS] & (1 << ((n) % __NERRBITS))) != 0)
1.11 augustss 470: #define ERR_ZERO(p) (void)memset((p), 0, sizeof(*(p)))
1.14 christos 471:
1.90 rillig 472: #define INTERNAL_ERROR(fmt, args...) \
473: internal_error(__FILE__, __LINE__, fmt, ##args)
1.11 augustss 474:
1.37 rillig 475: #define lint_assert(cond) \
476: do { \
477: if (!(cond)) \
478: assert_failed(__FILE__, __LINE__, __func__, #cond); \
1.100 rillig 479: } while (false)
1.37 rillig 480:
1.28 christos 481: #ifdef BLKDEBUG
482: #define ZERO 0xa5
483: #else
484: #define ZERO 0
485: #endif
486:
1.11 augustss 487: extern err_set msgset;
1.49 rillig 488:
489:
490: #ifdef DEBUG
491: # include "err-msgs.h"
492:
493: /* ARGSUSED */
494: static inline void __attribute__((format(printf, 1, 2)))
495: check_printf(const char *fmt, ...)
496: {
497: }
498:
1.99 rillig 499: # define wrap_check_printf_at(func, msgid, pos, args...) \
1.97 rillig 500: do { \
1.99 rillig 501: check_printf(__CONCAT(MSG_, msgid), ##args); \
502: (func)(msgid, pos, ##args); \
1.100 rillig 503: } while (false)
1.97 rillig 504:
1.99 rillig 505: # define error_at(msgid, pos, args...) \
506: wrap_check_printf_at(error_at, msgid, pos, ##args)
507: # define warning_at(msgid, pos, args...) \
508: wrap_check_printf_at(warning_at, msgid, pos, ##args)
509: # define message_at(msgid, pos, args...) \
510: wrap_check_printf_at(message_at, msgid, pos, ##args)
1.97 rillig 511:
1.99 rillig 512: # define wrap_check_printf(func, msgid, args...) \
1.49 rillig 513: do { \
1.99 rillig 514: check_printf(__CONCAT(MSG_, msgid), ##args); \
515: (func)(msgid, ##args); \
1.100 rillig 516: } while (false)
1.49 rillig 517:
1.99 rillig 518: # define error(msgid, args...) wrap_check_printf(error, msgid, ##args)
519: # define warning(msgid, args...) wrap_check_printf(warning, msgid, ##args)
520: # define message(msgid, args...) wrap_check_printf(message, msgid, ##args)
521: # define gnuism(msgid, args...) wrap_check_printf(gnuism, msgid, ##args)
522: # define c99ism(msgid, args...) wrap_check_printf(c99ism, msgid, ##args)
523: # define c11ism(msgid, args...) wrap_check_printf(c11ism, msgid, ##args)
1.49 rillig 524: #endif
1.54 rillig 525:
526: static inline bool
1.69 rillig 527: is_nonzero_val(const val_t *val)
1.54 rillig 528: {
1.69 rillig 529: return is_floating(val->v_tspec)
530: ? val->v_ldbl != 0.0
531: : val->v_quad != 0;
1.54 rillig 532: }
533:
534: static inline bool
1.68 rillig 535: constant_is_nonzero(const tnode_t *tn)
1.54 rillig 536: {
537: lint_assert(tn->tn_op == CON);
1.69 rillig 538: lint_assert(tn->tn_type->t_tspec == tn->tn_val->v_tspec);
539: return is_nonzero_val(tn->tn_val);
1.54 rillig 540: }
1.87 rillig 541:
542: static inline bool
543: is_zero(const tnode_t *tn)
544: {
545: return tn != NULL && tn->tn_op == CON && !is_nonzero_val(tn->tn_val);
546: }
547:
548: static inline bool
549: is_nonzero(const tnode_t *tn)
550: {
551: return tn != NULL && tn->tn_op == CON && is_nonzero_val(tn->tn_val);
552: }
1.102 rillig 553:
554: static inline uint64_t
555: bit(unsigned i)
556: {
557: lint_assert(i < 64);
558: return (uint64_t)1 << i;
559: }
560:
561: static inline uint64_t
562: value_bits(unsigned bitsize)
563: {
564: lint_assert(bitsize > 0);
565:
566: /* for long double (80 or 128), double _Complex (128) */
567: /*
568: * XXX: double _Complex does not have 128 bits of precision,
569: * therefore it should never be necessary to query the value bits
570: * of such a type; see d_c99_complex_split.c to trigger this case.
571: */
572: if (bitsize >= 64)
573: return ~((uint64_t)0);
574:
575: return ~(~(uint64_t)0 << bitsize);
576: }
1.103 rillig 577:
578: /* C99 6.7.8p7 */
579: static inline bool
580: is_struct_or_union(tspec_t t)
581: {
582: return t == STRUCT || t == UNION;
583: }
CVSweb <webmaster@jp.NetBSD.org>