Home | History | Annotate | Line # | Download | only in lint1
lint1.h revision 1.228
      1 /* $NetBSD: lint1.h,v 1.228 2024/09/28 15:51:40 rillig Exp $ */
      2 
      3 /*
      4  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
      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"
     36 #include "op.h"
     37 
     38 /*
     39  * A memory pool collects allocated objects that must be available until:
     40  * - the end of a block,
     41  * - the end of an expression, or
     42  * - the end of the translation unit.
     43  */
     44 typedef struct memory_pool {
     45 	struct memory_pool_item {
     46 		void *p;
     47 #ifdef DEBUG_MEM
     48 		size_t size;
     49 		const char *descr;
     50 #endif
     51 	} *items;
     52 	size_t	len;
     53 	size_t	cap;
     54 } memory_pool;
     55 
     56 /* See saved_lwarn in cgram.y. */
     57 #define LWARN_ALL	(-2)
     58 #define LWARN_NONE	(-1)
     59 
     60 /*
     61  * Describes the position of a declaration or anything else.
     62  *
     63  * FIXME: Just a single file:lineno pair is not enough to accurately describe
     64  *  the position of a symbol.  The whole inclusion path at that point must be
     65  *  stored as well.  This makes a difference for symbols from included
     66  *  headers, see print_stack_trace.
     67  */
     68 typedef struct {
     69 	const char *p_file;
     70 	int	p_line;
     71 	int	p_uniq;			/* uniquifier */
     72 } pos_t;
     73 
     74 typedef struct {
     75 	bool tq_const;
     76 	bool tq_restrict;
     77 	bool tq_volatile;
     78 	bool tq_atomic;
     79 } type_qualifiers;
     80 
     81 typedef struct {
     82 	bool used;
     83 } type_attributes;
     84 
     85 /* A bool, integer or floating-point value. */
     86 typedef struct {
     87 	tspec_t	v_tspec;
     88 	/*
     89 	 * Set if an integer constant is unsigned only in C90 and later, but
     90 	 * not in traditional C.
     91 	 *
     92 	 * See the operators table in oper.c, columns "l r".
     93 	 */
     94 	bool	v_unsigned_since_c90;
     95 	bool	v_char_constant;
     96 	union {
     97 		int64_t		integer;
     98 		long double	floating;
     99 	} u;
    100 } val_t;
    101 
    102 typedef struct sym sym_t;
    103 
    104 /*
    105  * Structures of type struct_or_union uniquely identify structures. This can't
    106  * be done in structures of type type_t, because these are copied if they must
    107  * be modified. So it would not be possible to check if two structures are
    108  * identical by comparing the pointers to the type structures.
    109  *
    110  * If the structure has no tag name, its first typedef name is used to identify
    111  * the structure in lint2.
    112  */
    113 typedef struct {
    114 	unsigned int sou_size_in_bits;
    115 	unsigned int sou_align;
    116 	bool	sou_incomplete:1;
    117 	sym_t	*sou_first_member;
    118 	sym_t	*sou_tag;
    119 	sym_t	*sou_first_typedef;
    120 } struct_or_union;
    121 
    122 /* The same as in struct_or_union, only for enums. */
    123 typedef struct {
    124 	bool	en_incomplete:1;
    125 	sym_t	*en_first_enumerator;
    126 	sym_t	*en_tag;
    127 	sym_t	*en_first_typedef;
    128 } enumeration;
    129 
    130 /* The type of an expression, object or function. */
    131 struct lint1_type {
    132 	tspec_t	t_tspec;	/* type specifier */
    133 	bool	t_incomplete_array:1;
    134 	bool	t_const:1;
    135 	bool	t_volatile:1;
    136 	bool	t_proto:1;	/* function prototype (u.params valid) */
    137 	bool	t_vararg:1;	/* prototype with '...' */
    138 	bool	t_typedef:1;	/* type defined with typedef */
    139 	bool	t_typeof:1;	/* type defined with GCC's __typeof__ */
    140 	bool	t_bitfield:1;
    141 	/*
    142 	 * Either the type is currently an enum (having t_tspec ENUM), or it
    143 	 * is an integer type (typically INT) that has been implicitly
    144 	 * converted from an enum type.  In both cases, u.enumer is valid.
    145 	 */
    146 	bool	t_is_enum:1;
    147 	bool	t_packed:1;
    148 	union {
    149 		int		dimension;	/* if ARRAY */
    150 		struct_or_union	*sou;
    151 		enumeration	*enumer;
    152 		sym_t		*params;	/* if t_proto */
    153 	} u;
    154 	unsigned int	t_bit_field_width:8;
    155 	unsigned int	t_bit_field_offset:24;
    156 	struct lint1_type *t_subt;	/*- element type (if ARRAY),
    157 					 * return value (if FUNC),
    158 					 * target type (if PTR) */
    159 };
    160 
    161 typedef enum {
    162 	SK_VCFT,		/* variable, constant, function, type */
    163 	SK_MEMBER,		/* member of a struct or union */
    164 	SK_TAG,
    165 	SK_LABEL
    166 } symbol_kind;
    167 
    168 /* storage classes and related things */
    169 typedef enum {
    170 	NO_SCL,
    171 	EXTERN,			/* external symbols (independent of decl_t) */
    172 	STATIC,			/* static symbols (local and global) */
    173 	AUTO,			/* automatic symbols (except register) */
    174 	REG,			/* register */
    175 	TYPEDEF,
    176 	THREAD_LOCAL,
    177 	STRUCT_TAG,
    178 	UNION_TAG,
    179 	ENUM_TAG,
    180 	STRUCT_MEMBER,
    181 	UNION_MEMBER,
    182 	BOOL_CONST,
    183 	ENUM_CONST,
    184 	ABSTRACT,		/* abstract symbol (sizeof, casts, unnamed
    185 				 * argument) */
    186 } scl_t;
    187 
    188 /* C23 6.7.4 */
    189 typedef enum {
    190 	FS_INLINE,		/* since C99 */
    191 	FS_NORETURN,		/* since C11 */
    192 } function_specifier;
    193 
    194 typedef enum {
    195 	NC_FALSE,		/* since C23 */
    196 	NC_TRUE,		/* since C23 */
    197 	NC_NULLPTR,		/* since C23 */
    198 } named_constant;
    199 
    200 /* A type, variable, keyword; basically anything that has a name. */
    201 struct sym {
    202 	const char *s_name;
    203 	const char *s_rename;	/* renamed symbol's given name */
    204 	pos_t	s_def_pos;	/* position of last (prototype) definition,
    205 				 * prototype declaration, no-prototype-def.,
    206 				 * tentative definition or declaration, in this
    207 				 * order */
    208 	pos_t	s_set_pos;	/* position of first initialization */
    209 	pos_t	s_use_pos;	/* position of first use */
    210 	symbol_kind s_kind;
    211 	const struct keyword *s_keyword;
    212 	bool	s_bitfield:1;
    213 	bool	s_set:1;
    214 	bool	s_used:1;
    215 	bool	s_param:1;
    216 	bool	s_register:1;
    217 	bool	s_defparam:1;	/* undefined symbol in old-style function
    218 				 * definition */
    219 	bool	s_return_type_implicit_int:1;
    220 	bool	s_osdef:1;	/* symbol stems from old-style function def. */
    221 	bool	s_inline:1;
    222 	sym_t	*s_ext_sym;	/* for locally declared external symbols, the
    223 				 * pointer to the external symbol with the same
    224 				 * name */
    225 	def_t	s_def;		/* declared, tentative defined, defined */
    226 	scl_t	s_scl;
    227 	int	s_block_level;	/* level of declaration, -1 if not in symbol
    228 				 * table */
    229 	type_t	*s_type;
    230 	union {
    231 		bool s_bool_constant;
    232 		int s_enum_constant;
    233 		struct {
    234 			struct_or_union *sm_containing_type;
    235 			unsigned int sm_offset_in_bits;
    236 		} s_member;
    237 		struct {
    238 			int sk_token;
    239 			union {
    240 				/* if T_TYPE or T_STRUCT_OR_UNION */
    241 				tspec_t sk_tspec;
    242 				/* if T_QUAL */
    243 				type_qualifiers sk_type_qualifier;
    244 				/* if T_FUNCTION_SPECIFIER */
    245 				function_specifier function_specifier;
    246 				/* if T_CON */
    247 				named_constant named_constant;
    248 			} u;
    249 		} s_keyword;
    250 		sym_t	*s_old_style_params;	/* parameters in an old-style
    251 						 * function definition */
    252 	} u;
    253 	sym_t	*s_symtab_next;	/* next symbol in the same symtab bucket */
    254 	sym_t	**s_symtab_ref;	/* pointer to s_symtab_next of the previous
    255 				 * symbol */
    256 	sym_t	*s_next;	/* next struct/union member, enumerator,
    257 				 * parameter */
    258 	sym_t	*s_level_next;	/* next symbol declared on the same level */
    259 };
    260 
    261 /*
    262  * Used to keep some information about symbols before they are entered
    263  * into the symbol table.
    264  */
    265 typedef struct {
    266 	const char *sb_name;		/* name of symbol */
    267 	size_t	sb_len;			/* length (without '\0') */
    268 	sym_t	*sb_sym;		/* symbol table entry */
    269 } sbuf_t;
    270 
    271 
    272 typedef struct {
    273 	struct tnode *func;
    274 	struct tnode **args;
    275 	size_t args_len;
    276 	size_t args_cap;
    277 } function_call;
    278 
    279 typedef struct tnode tnode_t;
    280 
    281 /* An expression, forming an abstract syntax tree. */
    282 struct tnode {
    283 	op_t	tn_op;
    284 	type_t	*tn_type;
    285 	bool	tn_lvalue:1;
    286 	bool	tn_cast:1;	/* if tn_op == CVT, it's an explicit cast */
    287 	bool	tn_parenthesized:1;
    288 	bool	tn_sys:1;	/* comes from a system header */
    289 	bool	tn_system_dependent:1; /* depends on sizeof or offsetof */
    290 	union {
    291 		struct {
    292 			tnode_t *left;	/* (left) operand */
    293 			tnode_t *right;	/* right operand */
    294 		} ops;
    295 		sym_t	*sym;		/* if NAME */
    296 		val_t	value;		/* if CON */
    297 		buffer	*str_literals;	/* if STRING; for
    298 					 * character strings, 'data' points to
    299 					 * the concatenated string literals in
    300 					 * source form, and 'len' is the
    301 					 * length of the concatenation; for
    302 					 * wide strings, 'data' is NULL and
    303 					 * 'len' is the number of resulting
    304 					 * characters */
    305 		function_call *call;	/* if CALL */
    306 	} u;
    307 };
    308 
    309 struct generic_association {
    310 	type_t *ga_arg;		/* NULL means default or error */
    311 	tnode_t *ga_result;	/* NULL means error */
    312 	struct generic_association *ga_prev;
    313 };
    314 
    315 typedef struct {
    316 	bool has_dim;
    317 	int dim;
    318 } array_size;
    319 
    320 typedef enum decl_level_kind {
    321 	DLK_EXTERN,		/* global types, variables or functions */
    322 	DLK_STRUCT,		/* struct members */
    323 	DLK_UNION,		/* union members */
    324 	DLK_ENUM,		/* enum constants */
    325 	DLK_OLD_STYLE_PARAMS,	/* parameters in an old-style function
    326 				 * definition */
    327 	DLK_PROTO_PARAMS,	/* parameters in a prototype function
    328 				 * definition */
    329 	DLK_AUTO,		/* local types or variables */
    330 	DLK_ABSTRACT		/* abstract (unnamed) declaration; type name;
    331 				 * used in casts and sizeof */
    332 } decl_level_kind;
    333 
    334 /*
    335  * A declaration level collects information for a declarator in a struct,
    336  * union or enum declaration, a parameter declaration list, or a plain
    337  * declaration in or outside a function body.
    338  *
    339  * For nested declarations, the global 'dcs' holds all information needed for
    340  * the current level, the outer levels are available via 'd_enclosing'.
    341  */
    342 typedef struct decl_level {
    343 	decl_level_kind d_kind;
    344 	tspec_t	d_abstract_type;/* VOID, BOOL, CHAR, INT or COMPLEX */
    345 	tspec_t	d_complex_mod;	/* FLOAT or DOUBLE */
    346 	tspec_t	d_sign_mod;	/* SIGNED or UNSIGN */
    347 	tspec_t	d_rank_mod;	/* SHORT, LONG or LLONG */
    348 	scl_t	d_scl;		/* storage class */
    349 	type_t	*d_type;	/* after dcs_end_type, the pointer to the type
    350 				 * used for all declarators */
    351 	sym_t	*d_redeclared_symbol;
    352 	unsigned int d_sou_size_in_bits;	/* size of the structure or
    353 						 * union being built, without
    354 						 * trailing padding */
    355 	unsigned int d_sou_align;	/* alignment of the structure
    356 					 * or union being built */
    357 	unsigned int d_mem_align;	/* alignment of the structure
    358 					 * or union member */
    359 	type_qualifiers d_qual;	/* in declaration specifiers */
    360 	bool	d_inline:1;	/* inline in declaration specifiers */
    361 	bool	d_multiple_storage_classes:1; /* reported in dcs_end_type */
    362 	bool	d_invalid_type_combination:1;
    363 	bool	d_nonempty_decl:1; /* in a function declaration, whether at
    364 				 * least one tag was declared */
    365 	bool	d_no_type_specifier:1;
    366 	bool	d_asm:1;	/* set if d_ctx == AUTO and asm() present */
    367 	bool	d_packed:1;
    368 	bool	d_used:1;
    369 	type_t	*d_tag_type;	/* during a member or enumerator declaration,
    370 				 * the tag type to which the member belongs */
    371 	sym_t	*d_func_params;	/* during a function declaration, the
    372 				 * parameters, stored in the enclosing level */
    373 	pos_t	d_func_def_pos;	/* position of the function definition */
    374 	sym_t	*d_first_dlsym;	/* first symbol declared at this level */
    375 	sym_t	**d_last_dlsym;	/* points to s_level_next in the last symbol
    376 				   declaration at this level */
    377 	sym_t	*d_func_proto_syms;	/* symbols defined in prototype, such
    378 					 * as tagged types or parameter names,
    379 					 * may overlap d_func_params */
    380 	struct decl_level *d_enclosing; /* the enclosing declaration level */
    381 } decl_level;
    382 
    383 typedef struct {
    384 	sym_t	*first;
    385 	bool	vararg:1;
    386 	bool	prototype:1;
    387 	bool	used:1;
    388 } parameter_list;
    389 
    390 /*
    391  * A sequence of asterisks and qualifiers, from right to left.  For example,
    392  * 'const ***volatile **const volatile' results in [c-v-, ----, --v-, ----,
    393  * ----].  The leftmost 'const' is not included in this list, it is stored in
    394  * dcs->d_qual instead.
    395  */
    396 typedef struct qual_ptr {
    397 	type_qualifiers qualifiers;
    398 	struct qual_ptr *p_next;
    399 } qual_ptr;
    400 
    401 /* The values of the 'case' labels. */
    402 typedef struct {
    403 	val_t	*vals;
    404 	size_t	len;
    405 	size_t	cap;
    406 } case_labels;
    407 
    408 typedef enum {
    409 	CS_DO_WHILE,
    410 	CS_FOR,
    411 	CS_FUNCTION_BODY,
    412 	CS_IF,
    413 	CS_SWITCH,
    414 	CS_WHILE
    415 } control_statement_kind;
    416 
    417 /*
    418  * Used to keep information about nested control statements.
    419  */
    420 typedef struct control_statement {
    421 	control_statement_kind c_kind;	/* to ensure proper nesting */
    422 	bool	c_loop:1;	/* 'continue' and 'break' are valid */
    423 	bool	c_switch:1;	/* 'case' and 'break' are valid */
    424 	bool	c_break:1;	/* the loop/switch has a reachable 'break'
    425 				 * statement */
    426 	bool	c_continue:1;	/* the loop has a reachable 'continue'
    427 				 * statement */
    428 	bool	c_default:1;	/* the switch has a 'default' label */
    429 	bool	c_maybe_endless:1;	/* the controlling expression is
    430 					 * always true (as in 'for (;;)' or
    431 					 * 'while (1)'), there may be break
    432 					 * statements though */
    433 	bool	c_always_then:1;
    434 	bool	c_reached_end_of_then:1;
    435 	bool	c_had_return_noval:1;	/* had "return;" */
    436 	bool	c_had_return_value:1;	/* had "return expr;" */
    437 
    438 	type_t	*c_switch_type;	/* type of switch expression */
    439 	tnode_t	*c_switch_expr;
    440 	case_labels c_case_labels;	/* list of case values */
    441 
    442 	memory_pool c_for_expr3_mem;	/* saved memory for end of loop
    443 					 * expression in for() */
    444 	tnode_t	*c_for_expr3;	/* end of loop expr in for() */
    445 	pos_t	c_for_expr3_pos;	/* position of end of loop expr */
    446 	pos_t	c_for_expr3_csrc_pos;	/* same for csrc_pos */
    447 
    448 	struct control_statement *c_surrounding;
    449 } control_statement;
    450 
    451 typedef struct {
    452 	size_t lo;		/* inclusive */
    453 	size_t hi;		/* inclusive */
    454 } range_t;
    455 
    456 typedef enum designator_kind {
    457 	DK_MEMBER,		/* .member */
    458 	DK_SUBSCRIPT,		/* [subscript] */
    459 	DK_SCALAR		/* no textual representation, not generated by
    460 				 * the parser; used for scalar initializer
    461 				 * expressions surrounded by braces */
    462 } designator_kind;
    463 
    464 /*
    465  * A single component on the path from the "current object" of a brace level
    466  * to the sub-object that is initialized by an expression.
    467  *
    468  * C99 6.7.8p6, 6.7.8p7
    469  */
    470 typedef struct designator {
    471 	designator_kind	dr_kind;
    472 	const sym_t	*dr_member;	/* for DK_MEMBER */
    473 	size_t		dr_subscript;	/* for DK_SUBSCRIPT */
    474 	bool		dr_done;
    475 } designator;
    476 
    477 /*
    478  * The path from the "current object" of a brace level to the sub-object that
    479  * is initialized by an expression.  Examples of designations are '.member'
    480  * or '.member[123].member.member[1][1]'.
    481  *
    482  * C99 6.7.8p6, 6.7.8p7
    483  */
    484 typedef struct designation {
    485 	designator	*dn_items;
    486 	size_t		dn_len;
    487 	size_t		dn_cap;
    488 } designation;
    489 
    490 typedef enum {
    491 	LC_ARGSUSED,
    492 	LC_BITFIELDTYPE,
    493 	LC_CONSTCOND,
    494 	LC_FALLTHROUGH,
    495 	LC_LINTLIBRARY,
    496 	LC_LINTED,
    497 	LC_LONGLONG,
    498 	LC_NOTREACHED,
    499 	LC_PRINTFLIKE,
    500 	LC_PROTOLIB,
    501 	LC_SCANFLIKE,
    502 	LC_VARARGS,
    503 } lint_comment;
    504 
    505 typedef struct {
    506 	size_t start;
    507 	size_t end;
    508 	uint64_t value;
    509 	bool escaped;		/* \n, \003, \x24 */
    510 	bool named_escape;	/* \a, \n, etc. */
    511 	bool literal_escape;	/* \?, \\, etc. */
    512 	uint8_t octal_digits;	/* 1 to 3; 0 means not applicable */
    513 	uint8_t hex_digits;	/* 1 to 3; 0 means not applicable */
    514 	bool next_literal;	/* when a new string literal begins */
    515 	bool invalid_escape;	/* single-character escape, recoverable */
    516 	bool overflow;		/* for octal and hex escapes */
    517 	bool missing_hex_digits;
    518 	bool unescaped_newline;	/* stops iterating */
    519 } quoted_iterator;
    520 
    521 typedef enum {
    522 	TK_IDENTIFIER,
    523 	TK_CONSTANT,
    524 	TK_STRING_LITERALS,
    525 	TK_PUNCTUATOR,
    526 } token_kind;
    527 
    528 typedef struct token {
    529 	token_kind kind;
    530 	union {
    531 		const char *identifier;
    532 		val_t constant;
    533 		buffer string_literals;
    534 		const char *punctuator;
    535 	} u;
    536 } token;
    537 
    538 typedef struct balanced_token_sequence balanced_token_sequence;
    539 typedef struct balanced_token balanced_token;
    540 
    541 struct balanced_token_sequence {
    542 	balanced_token *tokens;
    543 	size_t len;
    544 	size_t cap;
    545 };
    546 
    547 struct balanced_token {
    548 	char kind;	// '\0', '(', '[', '{'
    549 	union {
    550 		token token;
    551 		balanced_token_sequence tokens;
    552 	} u;
    553 };
    554 
    555 typedef struct {
    556 	const char *prefix;
    557 	const char *name;
    558 	balanced_token_sequence *arg;
    559 } attribute;
    560 
    561 typedef struct {
    562 	attribute *attrs;
    563 	size_t len;
    564 	size_t cap;
    565 } attribute_list;
    566 
    567 #include "externs1.h"
    568 
    569 #define lint_assert(cond)						\
    570 	do {								\
    571 		if (!(cond))						\
    572 			assert_failed(__FILE__, __LINE__, __func__, #cond); \
    573 	} while (false)
    574 
    575 #ifdef DEBUG
    576 #  include "err-msgs.h"
    577 
    578 /* ARGSUSED */
    579 static inline void __printflike(1, 2)
    580 check_printf(const char *fmt, ...)
    581 {
    582 }
    583 
    584 #  define wrap_check_printf_at(func, msgid, pos, args...)		\
    585 	do {								\
    586 		check_printf(__CONCAT(MSG_, msgid), ##args);		\
    587 		(func)(msgid, pos, ##args);				\
    588 	} while (false)
    589 
    590 #  define error_at(msgid, pos, args...) \
    591 	wrap_check_printf_at(error_at, msgid, pos, ##args)
    592 #  define warning_at(msgid, pos, args...) \
    593 	wrap_check_printf_at(warning_at, msgid, pos, ##args)
    594 #  define message_at(msgid, pos, args...) \
    595 	wrap_check_printf_at(message_at, msgid, pos, ##args)
    596 
    597 #  define wrap_check_printf(func, cond, msgid, args...)			\
    598 	({								\
    599 		if (/* CONSTCOND */cond)				\
    600 			debug_step("%s:%d: %s %d '%s' in %s",		\
    601 			    __FILE__, __LINE__,	#func, msgid,		\
    602 			    __CONCAT(MSG_, msgid), __func__);		\
    603 		check_printf(__CONCAT(MSG_, msgid), ##args);		\
    604 		(func)(msgid, ##args);					\
    605 		/* LINTED 129 */					\
    606 	})
    607 
    608 #  define error(msgid, args...) wrap_check_printf(error, \
    609     true, msgid, ##args)
    610 #  define warning(msgid, args...) wrap_check_printf(warning, \
    611     true, msgid, ##args)
    612 #  define gnuism(msgid, args...) wrap_check_printf(gnuism, \
    613     !allow_gcc || (!allow_trad && !allow_c99), msgid, ##args)
    614 #  define c99ism(msgid, args...) wrap_check_printf(c99ism, \
    615     !allow_c99 && (!allow_gcc || !allow_trad), msgid, ##args)
    616 #  define c11ism(msgid, args...) wrap_check_printf(c11ism, \
    617     !allow_c11 && !allow_gcc, msgid, ##args)
    618 #  define c23ism(msgid, args...) wrap_check_printf(c23ism, \
    619     !allow_c23, msgid, ##args)
    620 #endif
    621 
    622 #ifdef DEBUG
    623 #  define query_message(query_id, args...)				\
    624 	do {								\
    625 		debug_step("%s:%d: query %d '%s' in %s",		\
    626 		    __FILE__, __LINE__,					\
    627 		    query_id, __CONCAT(MSG_Q, query_id), __func__);	\
    628 		check_printf(__CONCAT(MSG_Q, query_id), ##args);	\
    629 		(query_message)(query_id, ##args);			\
    630 	} while (false)
    631 #else
    632 #  define query_message(...)						\
    633 	do {								\
    634 		if (any_query_enabled)					\
    635 			(query_message)(__VA_ARGS__);			\
    636 	} while (false)
    637 #endif
    638 
    639 /* Copies curr_pos, keeping things unique. */
    640 static inline pos_t
    641 unique_curr_pos(void)
    642 {
    643 	pos_t curr = curr_pos;
    644 	curr_pos.p_uniq++;
    645 	if (curr_pos.p_file == csrc_pos.p_file)
    646 		csrc_pos.p_uniq++;
    647 	return curr;
    648 }
    649 
    650 static inline bool
    651 is_nonzero_val(const val_t *val)
    652 {
    653 	return is_floating(val->v_tspec)
    654 	    ? val->u.floating != 0.0
    655 	    : val->u.integer != 0;
    656 }
    657 
    658 static inline bool
    659 constant_is_nonzero(const tnode_t *tn)
    660 {
    661 	lint_assert(tn->tn_op == CON);
    662 	lint_assert(tn->tn_type->t_tspec == tn->u.value.v_tspec);
    663 	return is_nonzero_val(&tn->u.value);
    664 }
    665 
    666 static inline bool
    667 is_zero(const tnode_t *tn)
    668 {
    669 	return tn != NULL && tn->tn_op == CON && !is_nonzero_val(&tn->u.value);
    670 }
    671 
    672 static inline bool
    673 is_nonzero(const tnode_t *tn)
    674 {
    675 	return tn != NULL && tn->tn_op == CON && is_nonzero_val(&tn->u.value);
    676 }
    677 
    678 static inline const char *
    679 op_name(op_t op)
    680 {
    681 	return modtab[op].m_name;
    682 }
    683 
    684 static inline bool
    685 is_binary(const tnode_t *tn)
    686 {
    687 	return modtab[tn->tn_op].m_binary;
    688 }
    689 
    690 static inline uint64_t
    691 bit(unsigned i)
    692 {
    693 	/*
    694 	 * TODO: Add proper support for INT128. This involves changing val_t to
    695 	 * 128 bits.
    696 	 */
    697 	if (i >= 64)
    698 		return 0;	/* XXX: not correct for INT128 and UINT128 */
    699 
    700 	lint_assert(i < 64);
    701 	return (uint64_t)1 << i;
    702 }
    703 
    704 static inline bool
    705 msb(int64_t si, tspec_t t)
    706 {
    707 	return ((uint64_t)si & bit(size_in_bits(t) - 1)) != 0;
    708 }
    709 
    710 static inline uint64_t
    711 value_bits(unsigned bitsize)
    712 {
    713 	lint_assert(bitsize > 0);
    714 
    715 	/* for long double (80 or 128), double _Complex (128) */
    716 	/*
    717 	 * XXX: double _Complex does not have 128 bits of precision, therefore
    718 	 * it should never be necessary to query the value bits of such a type;
    719 	 * see d_c99_complex_split.c to trigger this case.
    720 	 */
    721 	if (bitsize >= 64)
    722 		return ~(uint64_t)0;
    723 
    724 	return ~(~(uint64_t)0 << bitsize);
    725 }
    726 
    727 /* C99 6.7.8p7 */
    728 static inline bool
    729 is_struct_or_union(tspec_t t)
    730 {
    731 	return t == STRUCT || t == UNION;
    732 }
    733 
    734 static inline bool
    735 is_member(const sym_t *sym)
    736 {
    737 	return sym->s_scl == STRUCT_MEMBER || sym->s_scl == UNION_MEMBER;
    738 }
    739 
    740 static inline void
    741 set_sym_kind(symbol_kind kind)
    742 {
    743 	if (yflag)
    744 		debug_step("%s: %s -> %s", __func__,
    745 		    symbol_kind_name(sym_kind), symbol_kind_name(kind));
    746 	sym_kind = kind;
    747 }
    748