Home | History | Annotate | Line # | Download | only in lint1
cgram.y revision 1.507
      1 %{
      2 /* $NetBSD: cgram.y,v 1.507 2024/08/29 20:35:19 rillig Exp $ */
      3 
      4 /*
      5  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
      6  * Copyright (c) 1994, 1995 Jochen Pohl
      7  * All Rights Reserved.
      8  *
      9  * Redistribution and use in source and binary forms, with or without
     10  * modification, are permitted provided that the following conditions
     11  * are met:
     12  * 1. Redistributions of source code must retain the above copyright
     13  *    notice, this list of conditions and the following disclaimer.
     14  * 2. Redistributions in binary form must reproduce the above copyright
     15  *    notice, this list of conditions and the following disclaimer in the
     16  *    documentation and/or other materials provided with the distribution.
     17  * 3. All advertising materials mentioning features or use of this software
     18  *    must display the following acknowledgement:
     19  *	This product includes software developed by Jochen Pohl for
     20  *	The NetBSD Project.
     21  * 4. The name of the author may not be used to endorse or promote products
     22  *    derived from this software without specific prior written permission.
     23  *
     24  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     25  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     26  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     27  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     28  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     29  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     30  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     31  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     32  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     33  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     34  */
     35 
     36 #include <sys/cdefs.h>
     37 #if defined(__RCSID)
     38 __RCSID("$NetBSD: cgram.y,v 1.507 2024/08/29 20:35:19 rillig Exp $");
     39 #endif
     40 
     41 #include <limits.h>
     42 #include <stdlib.h>
     43 #include <string.h>
     44 
     45 #include "lint1.h"
     46 
     47 extern char *yytext;
     48 
     49 /*
     50  * Contains the level of current declaration, used for symbol table entries.
     51  * 0 is the top-level, > 0 is inside a function body.
     52  */
     53 int block_level;
     54 
     55 /*
     56  * level for memory allocation. Normally the same as block_level.
     57  * An exception is the declaration of parameters in prototypes. Memory
     58  * for these can't be freed after the declaration, but symbols must
     59  * be removed from the symbol table after the declaration.
     60  */
     61 size_t mem_block_level;
     62 
     63 /*
     64  * Save the no-warns state and restore it to avoid the problem where
     65  * if (expr) { stmt } / * NOLINT * / stmt;
     66  */
     67 #define LWARN_NOTHING_SAVED (-3)
     68 static int saved_lwarn = LWARN_NOTHING_SAVED;
     69 
     70 static void cgram_declare(sym_t *, bool, sbuf_t *);
     71 static void read_until_rparen(void);
     72 static balanced_token_sequence read_balanced_token_sequence(void);
     73 static sym_t *symbolrename(sym_t *, sbuf_t *);
     74 
     75 
     76 /* ARGSUSED */
     77 static void
     78 clear_warning_flags_loc(const char *file, size_t line)
     79 {
     80 	debug_step("%s:%zu: clearing flags", file, line);
     81 	reset_suppressions();
     82 	saved_lwarn = LWARN_NOTHING_SAVED;
     83 }
     84 
     85 /* ARGSUSED */
     86 static void
     87 save_warning_flags_loc(const char *file, size_t line)
     88 {
     89 	debug_step("%s:%zu: saving flags %d", file, line, lwarn);
     90 	saved_lwarn = lwarn;
     91 }
     92 
     93 /* ARGSUSED */
     94 static void
     95 restore_warning_flags_loc(const char *file, size_t line)
     96 {
     97 	if (saved_lwarn != LWARN_NOTHING_SAVED) {
     98 		lwarn = saved_lwarn;
     99 		debug_step("%s:%zu: restoring flags %d", file, line, lwarn);
    100 	} else
    101 		clear_warning_flags_loc(file, line);
    102 }
    103 
    104 #define clear_warning_flags()	clear_warning_flags_loc(__FILE__, __LINE__)
    105 #define save_warning_flags()	save_warning_flags_loc(__FILE__, __LINE__)
    106 #define restore_warning_flags()	restore_warning_flags_loc(__FILE__, __LINE__)
    107 
    108 static bool
    109 is_either(const char *s, const char *a, const char *b)
    110 {
    111 	return strcmp(s, a) == 0 || strcmp(s, b) == 0;
    112 }
    113 
    114 static void
    115 attribute_list_add(attribute_list *list, attribute attr)
    116 {
    117 	if (list->len >= list->cap) {
    118 		attribute *old_attrs = list->attrs;
    119 		list->cap = 16 + 2 * list->cap;
    120 		list->attrs = block_zero_alloc(
    121 		    list->cap * sizeof(*list->attrs), "attribute[]");
    122 		if (list->len > 0)
    123 			memcpy(list->attrs, old_attrs,
    124 			    list->len * sizeof(*list->attrs));
    125 	}
    126 	list->attrs[list->len++] = attr;
    127 }
    128 
    129 static void
    130 attribute_list_add_all(attribute_list *dst, attribute_list src)
    131 {
    132 	for (size_t i = 0, n = src.len; i < n; i++)
    133 		attribute_list_add(dst, src.attrs[i]);
    134 }
    135 
    136 static attribute
    137 new_attribute(const sbuf_t *prefix, const sbuf_t *name,
    138 	      const balanced_token_sequence *arg)
    139 {
    140 	attribute attr = { .name = xstrdup(name->sb_name) };
    141 	if (prefix != NULL)
    142 		attr.prefix = xstrdup(prefix->sb_name);
    143 	if (arg != NULL) {
    144 		attr.arg = block_zero_alloc(sizeof(*attr.arg),
    145 		    "balanced_token_sequence");
    146 		*attr.arg = *arg;
    147 	}
    148 	return attr;
    149 }
    150 
    151 #if YYDEBUG && YYBYACC
    152 #define YYSTYPE_TOSTRING cgram_to_string
    153 #endif
    154 
    155 %}
    156 
    157 %expect 110
    158 
    159 %union {
    160 	val_t	*y_val;
    161 	sbuf_t	*y_name;
    162 	sym_t	*y_sym;
    163 	bool	y_inc;
    164 	op_t	y_op;
    165 	scl_t	y_scl;
    166 	tspec_t	y_tspec;
    167 	type_qualifiers y_type_qualifiers;
    168 	function_specifier y_function_specifier;
    169 	parameter_list y_parameter_list;
    170 	function_call *y_arguments;
    171 	type_t	*y_type;
    172 	tnode_t	*y_tnode;
    173 	range_t	y_range;
    174 	buffer	*y_string;
    175 	qual_ptr *y_qual_ptr;
    176 	bool	y_seen_statement;
    177 	struct generic_association *y_generic;
    178 	array_size y_array_size;
    179 	bool	y_in_system_header;
    180 	designation y_designation;
    181 	named_constant y_named_constant;
    182 	attribute y_attribute;
    183 	attribute_list y_attribute_list;
    184 	balanced_token_sequence y_tokens;
    185 };
    186 
    187 /* for Bison:
    188 %printer {
    189 	if (is_integer($$->v_tspec))
    190 		fprintf(yyo, "%lld", (long long)$$->u.integer);
    191 	else
    192 		fprintf(yyo, "%Lg", $$->u.floating);
    193 } <y_val>
    194 %printer { fprintf(yyo, "'%s'", $$ != NULL ? $$->sb_name : "<null>"); } <y_name>
    195 %printer {
    196 	bool indented = debug_push_indented(true);
    197 	debug_sym("", $$, "");
    198 	debug_pop_indented(indented);
    199 } <y_sym>
    200 %printer { fprintf(yyo, "%s", $$ ? "++" : "--"); } <y_inc>
    201 %printer { fprintf(yyo, "%s", op_name($$)); } <y_op>
    202 %printer { fprintf(yyo, "%s", scl_name($$)); } <y_scl>
    203 %printer { fprintf(yyo, "%s", tspec_name($$)); } <y_tspec>
    204 %printer { fprintf(yyo, "%s", type_qualifiers_string($$)); } <y_type_qualifiers>
    205 %printer {
    206 	fprintf(yyo, "%s", function_specifier_name($$));
    207 } <y_function_specifier>
    208 %printer {
    209 	size_t n = 0;
    210 	for (const sym_t *p = $$.first; p != NULL; p = p->s_next)
    211 		n++;
    212 	fprintf(yyo, "%zu parameter%s", n, n != 1 ? "s" : "");
    213 } <y_parameter_list>
    214 %printer { fprintf(yyo, "%s", type_name($$)); } <y_type>
    215 %printer {
    216 	if ($$ == NULL)
    217 		fprintf(yyo, "<null>");
    218 	else
    219 		fprintf(yyo, "%s '%s'",
    220 		    op_name($$->tn_op), type_name($$->tn_type));
    221 } <y_tnode>
    222 %printer { fprintf(yyo, "%zu to %zu", $$.lo, $$.hi); } <y_range>
    223 %printer { fprintf(yyo, "length %zu", $$->len); } <y_string>
    224 %printer {
    225 	fprintf(yyo, "%s *", type_qualifiers_string($$->qualifiers));
    226 } <y_qual_ptr>
    227 %printer { fprintf(yyo, "%s", $$ ? "yes" : "no"); } <y_seen_statement>
    228 %printer { fprintf(yyo, "%s", type_name($$->ga_arg)); } <y_generic>
    229 %printer { fprintf(yyo, "%d", $$.dim); } <y_array_size>
    230 %printer { fprintf(yyo, "%s", $$ ? "yes" : "no"); } <y_in_system_header>
    231 %printer {
    232 	if ($$.dn_len == 0)
    233 		fprintf(yyo, "(empty)");
    234 	for (size_t i = 0; i < $$.dn_len; i++) {
    235 		const designator *dr = $$.dn_items + i;
    236 		if (dr->dr_kind == DK_MEMBER)
    237 			fprintf(yyo, ".%s", dr->dr_member->s_name);
    238 		else if (dr->dr_kind == DK_SUBSCRIPT)
    239 			fprintf(yyo, "[%zu]", dr->dr_subscript);
    240 		else
    241 			fprintf(yyo, "<scalar>");
    242 	}
    243 } <y_designation>
    244 %printer { fprintf(yyo, "%s", named_constant_name($$)); } <y_named_constant>
    245 */
    246 
    247 %token			T_LBRACE T_RBRACE T_LBRACK T_RBRACK T_LPAREN T_RPAREN
    248 %token			T_POINT T_ARROW
    249 %token			T_COMPLEMENT T_LOGNOT
    250 %token	<y_inc>		T_INCDEC
    251 %token			T_SIZEOF
    252 %token			T_BUILTIN_OFFSETOF
    253 %token			T_TYPEOF
    254 %token			T_EXTENSION
    255 %token			T_ALIGNAS
    256 %token			T_ALIGNOF
    257 %token			T_ASTERISK
    258 %token	<y_op>		T_MULTIPLICATIVE
    259 %token	<y_op>		T_ADDITIVE
    260 %token	<y_op>		T_SHIFT
    261 %token	<y_op>		T_RELATIONAL
    262 %token	<y_op>		T_EQUALITY
    263 %token			T_AMPER
    264 %token			T_BITXOR
    265 %token			T_BITOR
    266 %token			T_LOGAND
    267 %token			T_LOGOR
    268 %token			T_QUEST
    269 %token			T_COLON
    270 %token			T_ASSIGN
    271 %token	<y_op>		T_OPASSIGN
    272 %token			T_COMMA
    273 %token			T_SEMI
    274 %token			T_ELLIPSIS
    275 %token			T_DCOLON
    276 %token			T_REAL
    277 %token			T_IMAG
    278 %token			T_GENERIC
    279 
    280 /* storage classes (extern, static, auto, register and typedef) */
    281 %token	<y_scl>		T_SCLASS
    282 %token	<y_function_specifier> T_FUNCTION_SPECIFIER
    283 
    284 /*
    285  * predefined type keywords (char, int, short, long, unsigned, signed,
    286  * float, double, void); see T_TYPENAME for types from typedef
    287  */
    288 %token	<y_tspec>	T_TYPE
    289 
    290 %token	<y_type_qualifiers>	T_QUAL
    291 %token	<y_type_qualifiers>	T_ATOMIC
    292 
    293 /* struct or union */
    294 %token	<y_tspec>	T_STRUCT_OR_UNION
    295 
    296 /* remaining keywords */
    297 %token			T_ASM
    298 %token			T_BREAK
    299 %token			T_CASE
    300 %token			T_CONTINUE
    301 %token			T_DEFAULT
    302 %token			T_DO
    303 %token			T_ELSE
    304 %token			T_ENUM
    305 %token			T_FOR
    306 %token			T_GOTO
    307 %token			T_IF
    308 %token			T_PACKED
    309 %token			T_RETURN
    310 %token			T_SWITCH
    311 %token			T_SYMBOLRENAME
    312 %token			T_WHILE
    313 %token			T_STATIC_ASSERT
    314 
    315 %token			T_ATTRIBUTE
    316 
    317 %left	T_THEN
    318 %left	T_ELSE
    319 %right	T_QUEST T_COLON
    320 %left	T_LOGOR
    321 %left	T_LOGAND
    322 %left	T_BITOR
    323 %left	T_BITXOR
    324 %left	T_AMPER
    325 %left	T_EQUALITY
    326 %left	T_RELATIONAL
    327 %left	T_SHIFT
    328 %left	T_ADDITIVE
    329 %left	T_ASTERISK T_MULTIPLICATIVE
    330 
    331 %token	<y_name>	T_NAME
    332 %token	<y_name>	T_TYPENAME
    333 %token	<y_val>		T_CON
    334 %token	<y_named_constant> T_NAMED_CONSTANT
    335 %token	<y_string>	T_STRING
    336 
    337 /* No type for program. */
    338 %type	<y_sym>		identifier_sym
    339 %type	<y_name>	identifier
    340 %type	<y_string>	string
    341 %type	<y_tnode>	primary_expression
    342 %type	<y_designation>	member_designator
    343 %type	<y_tnode>	generic_selection
    344 %type	<y_generic>	generic_assoc_list
    345 %type	<y_generic>	generic_association
    346 %type	<y_tnode>	postfix_expression
    347 %type	<y_tnode>	gcc_statement_expr_list
    348 %type	<y_tnode>	gcc_statement_expr_item
    349 %type	<y_op>		point_or_arrow
    350 %type	<y_arguments>	argument_expression_list
    351 %type	<y_scl>		storage_class_specifiers
    352 %type	<y_tnode>	unary_expression
    353 %type	<y_tnode>	cast_expression
    354 %type	<y_tnode>	expression_opt
    355 %type	<y_tnode>	conditional_expression
    356 %type	<y_tnode>	assignment_expression
    357 %type	<y_tnode>	expression
    358 %type	<y_tnode>	constant_expression
    359 /* No type for declaration_or_error. */
    360 /* No type for declaration. */
    361 /* No type for begin_type_declaration_specifiers. */
    362 /* No type for begin_type_declmods. */
    363 /* No type for begin_type_specifier_qualifier_list. */
    364 /* No type for begin_type_specifier_qualifier_list_postfix. */
    365 %type	<y_type>	begin_type_typespec
    366 /* No type for begin_type_qualifier_list. */
    367 /* No type for declmod. */
    368 /* No type for type_attribute_list_opt. */
    369 /* No type for type_attribute_list. */
    370 /* No type for type_attribute_opt. */
    371 /* No type for type_attribute. */
    372 /* No type for begin_type. */
    373 /* No type for end_type. */
    374 /* No type for notype_init_declarator_list. */
    375 /* No type for type_init_declarator_list. */
    376 /* No type for notype_init_declarator. */
    377 /* No type for type_init_declarator. */
    378 %type	<y_scl>		storage_class_specifier
    379 %type	<y_type>	type_type_specifier
    380 %type	<y_type>	notype_type_specifier
    381 %type	<y_type>	struct_or_union_specifier
    382 %type	<y_tspec>	struct_or_union
    383 %type	<y_sym>		braced_member_declaration_list
    384 %type	<y_sym>		member_declaration_list_with_rbrace
    385 %type	<y_sym>		member_declaration_list
    386 %type	<y_sym>		member_declaration
    387 %type	<y_sym>		notype_member_declarator_list
    388 %type	<y_sym>		type_member_declarator_list
    389 %type	<y_sym>		notype_member_declarator
    390 %type	<y_sym>		type_member_declarator
    391 %type	<y_type>	enum_specifier
    392 /* No type for enum. */
    393 %type	<y_sym>		enum_declaration
    394 %type	<y_sym>		enums_with_opt_comma
    395 %type	<y_sym>		enumerator_list
    396 %type	<y_sym>		enumerator
    397 %type	<y_type>	atomic_type_specifier
    398 /* No type for atomic. */
    399 %type	<y_type_qualifiers>	type_qualifier
    400 %type	<y_sym>		notype_declarator
    401 %type	<y_sym>		type_declarator
    402 %type	<y_sym>		notype_direct_declarator
    403 %type	<y_sym>		type_direct_declarator
    404 %type	<y_qual_ptr>	pointer
    405 %type	<y_type_qualifiers>	type_qualifier_list_opt
    406 %type	<y_type_qualifiers>	type_qualifier_list
    407 %type	<y_sym>		parameter_declaration
    408 %type	<y_sym>		type_param_declarator
    409 %type	<y_sym>		notype_param_declarator
    410 %type	<y_sym>		direct_param_declarator
    411 %type	<y_sym>		direct_notype_param_declarator
    412 %type	<y_parameter_list>	param_list
    413 %type	<y_array_size>	array_size_opt
    414 %type	<y_sym>		identifier_list
    415 %type	<y_type>	type_name
    416 %type	<y_sym>		abstract_declaration
    417 %type	<y_parameter_list>	abstract_decl_param_list
    418 /* No type for abstract_decl_lparen. */
    419 %type	<y_parameter_list>	vararg_parameter_type_list
    420 %type	<y_parameter_list>	parameter_type_list
    421 %type	<y_sym>		abstract_declarator
    422 %type	<y_sym>		direct_abstract_declarator
    423 /* No type for braced_initializer. */
    424 /* No type for initializer. */
    425 /* No type for initializer_list. */
    426 /* No type for designation. */
    427 /* No type for designator_list. */
    428 /* No type for designator. */
    429 /* No type for static_assert_declaration. */
    430 %type	<y_range>	range
    431 /* No type for init_lbrace. */
    432 /* No type for init_rbrace. */
    433 %type	<y_attribute_list>	attribute_specifier_sequence
    434 %type	<y_attribute_list>	attribute_specifier
    435 %type	<y_attribute_list>	attribute_list
    436 %type	<y_attribute>		attribute
    437 %type	<y_tokens>		attribute_argument_clause
    438 %type	<y_name>	asm_or_symbolrename_opt
    439 /* No type for statement. */
    440 /* No type for no_attr_statement. */
    441 /* No type for non_expr_statement. */
    442 /* No type for no_attr_non_expr_statement. */
    443 /* No type for label. */
    444 /* No type for labeled_statement. */
    445 /* No type for compound_statement. */
    446 /* No type for compound_statement_lbrace. */
    447 /* No type for compound_statement_rbrace. */
    448 %type	<y_seen_statement> block_item_list
    449 %type	<y_seen_statement> block_item
    450 /* No type for expression_statement. */
    451 /* No type for selection_statement. */
    452 /* No type for if_without_else. */
    453 /* No type for if_expr. */
    454 /* No type for switch_expr. */
    455 /* No type for iteration_statement. */
    456 /* No type for while_expr. */
    457 /* No type for do_statement. */
    458 /* No type for do. */
    459 /* No type for for_start. */
    460 /* No type for for_exprs. */
    461 /* No type for jump_statement. */
    462 /* No type for goto. */
    463 /* No type for asm_statement. */
    464 /* No type for read_until_rparen. */
    465 /* No type for translation_unit. */
    466 /* No type for external_declaration. */
    467 /* No type for top_level_declaration. */
    468 /* No type for function_definition. */
    469 %type	<y_sym>		func_declarator
    470 /* No type for arg_declaration_list_opt. */
    471 /* No type for arg_declaration_list. */
    472 /* No type for arg_declaration. */
    473 /* No type for gcc_attribute_specifier_list_opt. */
    474 /* No type for gcc_attribute_specifier_list. */
    475 /* No type for gcc_attribute_specifier. */
    476 /* No type for gcc_attribute_list. */
    477 /* No type for gcc_attribute. */
    478 %type	<y_in_system_header> sys
    479 
    480 %%
    481 
    482 program:
    483 	/* empty */ {
    484 		/* TODO: Make this an error in C99 mode as well. */
    485 		if (!allow_trad && !allow_c99)
    486 			/* empty translation unit */
    487 			error(272);
    488 		else if (allow_c90)
    489 			/* empty translation unit */
    490 			warning(272);
    491 	}
    492 |	translation_unit
    493 ;
    494 
    495 identifier_sym:			/* helper for struct/union/enum */
    496 	identifier {
    497 		$$ = getsym($1);
    498 	}
    499 ;
    500 
    501 /* K&R ???, C90 ???, C99 6.4.2.1, C11 ??? */
    502 identifier:
    503 	T_NAME {
    504 		debug_step("cgram: name '%s'", $1->sb_name);
    505 		$$ = $1;
    506 	}
    507 |	T_TYPENAME {
    508 		debug_step("cgram: typename '%s'", $1->sb_name);
    509 		$$ = $1;
    510 	}
    511 ;
    512 
    513 /* see C99 6.4.5, string literals are joined by 5.1.1.2 */
    514 string:
    515 	T_STRING
    516 |	string T_STRING {
    517 		if (!allow_c90)
    518 			/* concatenated strings are illegal in traditional C */
    519 			warning(219);
    520 		$$ = cat_strings($1, $2);
    521 	}
    522 ;
    523 
    524 /* K&R 7.1, C90 ???, C99 6.5.1, C11 6.5.1, C23 6.5.2 */
    525 primary_expression:
    526 	T_NAME {
    527 		bool sys_name, sys_next;
    528 		sys_name = in_system_header;
    529 		if (yychar < 0)
    530 			yychar = yylex();
    531 		sys_next = in_system_header;
    532 		in_system_header = sys_name;
    533 		$$ = build_name(getsym($1), yychar == T_LPAREN);
    534 		in_system_header = sys_next;
    535 	}
    536 |	T_CON {
    537 		$$ = build_constant(gettyp($1->v_tspec), $1);
    538 	}
    539 |	T_NAMED_CONSTANT {
    540 		if ($1 == NC_NULLPTR) {
    541 			tnode_t *zero = expr_alloc_tnode();
    542 			zero->tn_op = CON;
    543 			zero->tn_type = gettyp(INT);
    544 			zero->u.value.v_tspec = INT;
    545 
    546 			type_t *void_ptr = block_derive_type(gettyp(VOID), PTR);
    547 			$$ = convert(CVT, 0, void_ptr, zero);
    548 			$$->tn_sys = zero->tn_sys;
    549 		} else {
    550 			tnode_t *nc = expr_alloc_tnode();
    551 			nc->tn_op = CON;
    552 			nc->tn_type = gettyp(BOOL);
    553 			nc->u.value.v_tspec = BOOL;
    554 			nc->u.value.u.integer = $1 == NC_TRUE ? 1 : 0;
    555 			$$ = nc;
    556 		}
    557 	}
    558 |	string {
    559 		$$ = build_string($1);
    560 	}
    561 |	T_LPAREN expression T_RPAREN {
    562 		if ($2 != NULL)
    563 			$2->tn_parenthesized = true;
    564 		$$ = $2;
    565 	}
    566 |	generic_selection
    567 	/* GCC primary-expression, see c_parser_postfix_expression */
    568 |	T_BUILTIN_OFFSETOF T_LPAREN type_name T_COMMA {
    569 		set_sym_kind(SK_MEMBER);
    570 	} member_designator T_RPAREN {
    571 		$$ = build_offsetof($3, $6);
    572 	}
    573 ;
    574 
    575 /* K&R ---, C90 ---, C99 7.17p3, C11 7.19p3, C23 7.21p4 */
    576 member_designator:
    577 	identifier {
    578 		$$ = (designation) { .dn_len = 0 };
    579 		designation_push(&$$, DK_MEMBER, getsym($1), 0);
    580 	}
    581 |	member_designator T_LBRACK range T_RBRACK {
    582 		$$ = $1;
    583 		designation_push(&$$, DK_SUBSCRIPT, NULL, $3.lo);
    584 	}
    585 |	member_designator T_POINT {
    586 		set_sym_kind(SK_MEMBER);
    587 	} identifier {
    588 		$$ = $1;
    589 		designation_push(&$$, DK_MEMBER, getsym($4), 0);
    590 	}
    591 ;
    592 
    593 /* K&R ---, C90 ---, C99 ---, C11 6.5.1.1, C23 6.5.2.1 */
    594 generic_selection:
    595 	T_GENERIC T_LPAREN assignment_expression T_COMMA
    596 	    generic_assoc_list T_RPAREN {
    597 		/* generic selection requires C11 or later */
    598 		c11ism(345);
    599 		$$ = build_generic_selection($3, $5);
    600 	}
    601 ;
    602 
    603 /* K&R ---, C90 ---, C99 ---, C11 6.5.1.1, C23 6.5.2.1 */
    604 generic_assoc_list:
    605 	generic_association
    606 |	generic_assoc_list T_COMMA generic_association {
    607 		$3->ga_prev = $1;
    608 		$$ = $3;
    609 	}
    610 ;
    611 
    612 /* K&R ---, C90 ---, C99 ---, C11 6.5.1.1, C23 6.5.2.1 */
    613 generic_association:
    614 	type_name T_COLON assignment_expression {
    615 		$$ = block_zero_alloc(sizeof(*$$), "generic");
    616 		$$->ga_arg = $1;
    617 		$$->ga_result = $3;
    618 	}
    619 |	T_DEFAULT T_COLON assignment_expression {
    620 		$$ = block_zero_alloc(sizeof(*$$), "generic");
    621 		$$->ga_arg = NULL;
    622 		$$->ga_result = $3;
    623 	}
    624 ;
    625 
    626 /* K&R 7.1, C90 ???, C99 6.5.2, C11 6.5.2, C23 6.5.3.1 */
    627 postfix_expression:
    628 	primary_expression
    629 |	postfix_expression T_LBRACK sys expression T_RBRACK {
    630 		$$ = build_unary(INDIR, $3, build_binary($1, PLUS, $3, $4));
    631 	}
    632 |	postfix_expression T_LPAREN sys T_RPAREN {
    633 		function_call *call =
    634 		    expr_zero_alloc(sizeof(*call), "function_call");
    635 		$$ = build_function_call($1, $3, call);
    636 	}
    637 |	postfix_expression T_LPAREN sys argument_expression_list T_RPAREN {
    638 		$$ = build_function_call($1, $3, $4);
    639 	}
    640 |	postfix_expression point_or_arrow sys T_NAME {
    641 		$$ = build_member_access($1, $2, $3, $4);
    642 	}
    643 |	postfix_expression T_INCDEC sys {
    644 		$$ = build_unary($2 ? INCAFT : DECAFT, $3, $1);
    645 	}
    646 	/* Rule 'compound_literal' from C99 6.5.2.5. */
    647 |	T_LPAREN type_name T_RPAREN {
    648 		sym_t *tmp = mktempsym($2);
    649 		begin_initialization(tmp);
    650 		cgram_declare(tmp, true, NULL);
    651 	} braced_initializer {
    652 		if (!allow_c99)
    653 			 /* compound literals are a C99/GCC extension */
    654 			 gnuism(319);
    655 		$$ = build_name(current_initsym(), false);
    656 		end_initialization();
    657 	}
    658 	/* Rule 'compound_literal' with storage classes from C23 6.5.3.6. */
    659 |	T_LPAREN storage_class_specifiers type_name T_RPAREN {
    660 		sym_t *tmp = mktempsym($3);
    661 		tmp->s_scl = $2;
    662 		begin_initialization(tmp);
    663 		cgram_declare(tmp, true, NULL);
    664 	} braced_initializer {
    665 		if (!allow_c99)
    666 			 /* compound literals are a C99/GCC extension */
    667 			 gnuism(319);
    668 		$$ = build_name(current_initsym(), false);
    669 		end_initialization();
    670 	}
    671 |	T_LPAREN compound_statement_lbrace {
    672 		begin_statement_expr();
    673 	} gcc_statement_expr_list {
    674 		do_statement_expr($4);
    675 	} compound_statement_rbrace T_RPAREN {
    676 		$$ = end_statement_expr();
    677 	}
    678 ;
    679 
    680 /*
    681  * The inner part of a GCC statement-expression of the form ({ ... }).
    682  *
    683  * https://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html
    684  */
    685 gcc_statement_expr_list:
    686 	gcc_statement_expr_item
    687 |	gcc_statement_expr_list gcc_statement_expr_item {
    688 		$$ = $2;
    689 	}
    690 ;
    691 
    692 gcc_statement_expr_item:
    693 	declaration_or_error {
    694 		clear_warning_flags();
    695 		$$ = NULL;
    696 	}
    697 |	non_expr_statement {
    698 		$$ = expr_alloc_tnode();
    699 		$$->tn_type = gettyp(VOID);
    700 	}
    701 |	T_SEMI {
    702 		$$ = expr_alloc_tnode();
    703 		$$->tn_type = gettyp(VOID);
    704 	}
    705 |	expression T_SEMI {
    706 		if ($1 == NULL) {	/* in case of syntax errors */
    707 			$$ = expr_alloc_tnode();
    708 			$$->tn_type = gettyp(VOID);
    709 		} else {
    710 			/* XXX: do that only on the last name */
    711 			if ($1->tn_op == NAME)
    712 				$1->u.sym->s_used = true;
    713 			expr($1, false, false, false, false);
    714 			suppress_fallthrough = false;
    715 			$$ = $1;
    716 		}
    717 	}
    718 ;
    719 
    720 point_or_arrow:			/* helper for 'postfix_expression' */
    721 	T_POINT {
    722 		set_sym_kind(SK_MEMBER);
    723 		$$ = POINT;
    724 	}
    725 |	T_ARROW {
    726 		set_sym_kind(SK_MEMBER);
    727 		$$ = ARROW;
    728 	}
    729 ;
    730 
    731 /* K&R 7.1, C90 ???, C99 6.5.2, C11 6.5.2, C23 6.5.3.1 */
    732 argument_expression_list:
    733 	assignment_expression {
    734 		$$ = expr_zero_alloc(sizeof(*$$), "function_call");
    735 		add_function_argument($$, $1);
    736 	}
    737 |	argument_expression_list T_COMMA assignment_expression {
    738 		$$ = $1;
    739 		add_function_argument($1, $3);
    740 	}
    741 ;
    742 
    743 
    744 /* C23 6.5.3.6 */
    745 /* The rule 'compound_literal' is inlined into 'postfix_expression'. */
    746 
    747 /* C23 6.5.3.6 */
    748 storage_class_specifiers:
    749 	storage_class_specifier
    750 |	storage_class_specifiers storage_class_specifier {
    751 		// TODO C23: maybe merge multiple storage class specifiers
    752 		$$ = $1;
    753 	}
    754 ;
    755 
    756 /* K&R 7.2, C90 ???, C99 6.5.3, C11 6.5.3, C23 6.5.4 */
    757 unary_expression:
    758 	postfix_expression
    759 |	T_INCDEC sys unary_expression {
    760 		$$ = build_unary($1 ? INCBEF : DECBEF, $2, $3);
    761 	}
    762 |	T_AMPER sys cast_expression {
    763 		$$ = build_unary(ADDR, $2, $3);
    764 	}
    765 |	T_ASTERISK sys cast_expression {
    766 		$$ = build_unary(INDIR, $2, $3);
    767 	}
    768 |	T_ADDITIVE sys cast_expression {
    769 		if (!allow_c90 && $1 == PLUS)
    770 			/* unary '+' is illegal in traditional C */
    771 			warning(100);
    772 		$$ = build_unary($1 == PLUS ? UPLUS : UMINUS, $2, $3);
    773 	}
    774 |	T_COMPLEMENT sys cast_expression {
    775 		$$ = build_unary(COMPL, $2, $3);
    776 	}
    777 |	T_LOGNOT sys cast_expression {
    778 		$$ = build_unary(NOT, $2, $3);
    779 	}
    780 |	T_REAL sys cast_expression {	/* GCC c_parser_unary_expression */
    781 		$$ = build_unary(REAL, $2, $3);
    782 	}
    783 |	T_IMAG sys cast_expression {	/* GCC c_parser_unary_expression */
    784 		$$ = build_unary(IMAG, $2, $3);
    785 	}
    786 |	T_EXTENSION cast_expression {	/* GCC c_parser_unary_expression */
    787 		$$ = $2;
    788 	}
    789 |	T_SIZEOF unary_expression {
    790 		$$ = $2 == NULL ? NULL : build_sizeof($2->tn_type);
    791 		if ($$ != NULL)
    792 			check_expr_misc($2,
    793 			    false, false, false, false, false, true);
    794 	}
    795 |	T_SIZEOF T_LPAREN type_name T_RPAREN {
    796 		$$ = build_sizeof($3);
    797 	}
    798 |	T_ALIGNOF unary_expression {
    799 		/* non type argument to alignof is a GCC extension */
    800 		gnuism(349);
    801 		lint_assert($2 != NULL);
    802 		$$ = build_alignof($2->tn_type);
    803 	}
    804 	/* K&R ---, C90 ---, C99 ---, C11 6.5.3, C23 6.5.4.4 */
    805 |	T_ALIGNOF T_LPAREN type_name T_RPAREN {
    806 		/* TODO: c11ism */
    807 		$$ = build_alignof($3);
    808 	}
    809 ;
    810 
    811 /* C23 6.5.4 */
    812 /* The rule 'unary_operator' is inlined into unary_expression. */
    813 
    814 /* K&R 7.2, C90 ???, C99 6.5.4, C11 6.5.4, C23 6.5.5 */
    815 cast_expression:
    816 	unary_expression
    817 |	T_LPAREN type_name T_RPAREN sys cast_expression {
    818 		$$ = cast($5, $4, $2);
    819 	}
    820 ;
    821 
    822 expression_opt:
    823 	/* empty */ {
    824 		$$ = NULL;
    825 	}
    826 |	expression
    827 ;
    828 
    829 /* 'conditional_expression' also implements 'multiplicative_expression'. */
    830 /* 'conditional_expression' also implements 'additive_expression'. */
    831 /* 'conditional_expression' also implements 'shift_expression'. */
    832 /* 'conditional_expression' also implements 'relational_expression'. */
    833 /* 'conditional_expression' also implements 'equality_expression'. */
    834 /* 'conditional_expression' also implements 'AND_expression'. */
    835 /* 'conditional_expression' also implements 'exclusive_OR_expression'. */
    836 /* 'conditional_expression' also implements 'inclusive_OR_expression'. */
    837 /* 'conditional_expression' also implements 'logical_AND_expression'. */
    838 /* 'conditional_expression' also implements 'logical_OR_expression'. */
    839 /* K&R ???, C90 ???, C99 6.5.5 to 6.5.15, C11 6.5.5 to 6.5.15, C23 6.5.6 to 6.5.16 */
    840 conditional_expression:
    841 	cast_expression
    842 |	conditional_expression T_ASTERISK sys conditional_expression {
    843 		$$ = build_binary($1, MULT, $3, $4);
    844 	}
    845 |	conditional_expression T_MULTIPLICATIVE sys conditional_expression {
    846 		$$ = build_binary($1, $2, $3, $4);
    847 	}
    848 |	conditional_expression T_ADDITIVE sys conditional_expression {
    849 		$$ = build_binary($1, $2, $3, $4);
    850 	}
    851 |	conditional_expression T_SHIFT sys conditional_expression {
    852 		$$ = build_binary($1, $2, $3, $4);
    853 	}
    854 |	conditional_expression T_RELATIONAL sys conditional_expression {
    855 		$$ = build_binary($1, $2, $3, $4);
    856 	}
    857 |	conditional_expression T_EQUALITY sys conditional_expression {
    858 		$$ = build_binary($1, $2, $3, $4);
    859 	}
    860 |	conditional_expression T_AMPER sys conditional_expression {
    861 		$$ = build_binary($1, BITAND, $3, $4);
    862 	}
    863 |	conditional_expression T_BITXOR sys conditional_expression {
    864 		$$ = build_binary($1, BITXOR, $3, $4);
    865 	}
    866 |	conditional_expression T_BITOR sys conditional_expression {
    867 		$$ = build_binary($1, BITOR, $3, $4);
    868 	}
    869 |	conditional_expression T_LOGAND sys conditional_expression {
    870 		$$ = build_binary($1, LOGAND, $3, $4);
    871 	}
    872 |	conditional_expression T_LOGOR sys conditional_expression {
    873 		$$ = build_binary($1, LOGOR, $3, $4);
    874 	}
    875 |	conditional_expression T_QUEST sys
    876 	    expression T_COLON sys conditional_expression {
    877 		$$ = build_binary($1, QUEST, $3,
    878 		    build_binary($4, COLON, $6, $7));
    879 	}
    880 ;
    881 
    882 /* K&R ???, C90 ???, C99 6.5.16, C11 6.5.16, C23 6.5.17.1 */
    883 assignment_expression:
    884 	conditional_expression
    885 |	unary_expression T_ASSIGN sys assignment_expression {
    886 		$$ = build_binary($1, ASSIGN, $3, $4);
    887 	}
    888 |	unary_expression T_OPASSIGN sys assignment_expression {
    889 		$$ = build_binary($1, $2, $3, $4);
    890 	}
    891 ;
    892 
    893 /* C23 6.5.17.1 */
    894 /* The rule 'assignment_operator' is inlined into 'assignment_expression'. */
    895 
    896 /* K&R ???, C90 ???, C99 6.5.17, C11 6.5.17, C23 6.5.18 */
    897 expression:
    898 	assignment_expression
    899 |	expression T_COMMA sys assignment_expression {
    900 		$$ = build_binary($1, COMMA, $3, $4);
    901 	}
    902 ;
    903 
    904 /* K&R ???, C90 ???, C99 6.6, C11 ???, C23 6.6 */
    905 constant_expression:
    906 	conditional_expression
    907 ;
    908 
    909 declaration_or_error:
    910 	declaration
    911 |	error T_SEMI
    912 ;
    913 
    914 /* K&R ???, C90 ???, C99 6.7, C11 ???, C23 6.7.1 */
    915 declaration:
    916 	begin_type_declmods end_type T_SEMI {
    917 		if (dcs->d_scl == TYPEDEF)
    918 			/* typedef declares no type name */
    919 			warning(72);
    920 		else
    921 			/* empty declaration */
    922 			warning(2);
    923 	}
    924 |	begin_type_declmods end_type notype_init_declarator_list T_SEMI {
    925 		if (dcs->d_scl == TYPEDEF)
    926 			/* syntax error '%s' */
    927 			error(249, "missing base type for typedef");
    928 		else
    929 			/* old-style declaration; add 'int' */
    930 			error(1);
    931 	}
    932 |	begin_type_declaration_specifiers end_type T_SEMI {
    933 		if (dcs->d_scl == TYPEDEF)
    934 			/* typedef declares no type name */
    935 			warning(72);
    936 		else if (!dcs->d_nonempty_decl)
    937 			/* empty declaration */
    938 			warning(2);
    939 	}
    940 |	begin_type_declaration_specifiers end_type
    941 	    type_init_declarator_list T_SEMI
    942 |	static_assert_declaration
    943 ;
    944 
    945 /* TODO: Implement 'declaration_specifiers' from C23 6.7.1. */
    946 
    947 begin_type_declaration_specifiers:	/* see C99 6.7, C23 6.7.1 */
    948 	begin_type_typespec {
    949 		dcs_add_type($1);
    950 	}
    951 |	begin_type_declmods type_type_specifier {
    952 		dcs_add_type($2);
    953 	}
    954 |	type_attribute begin_type_declaration_specifiers
    955 |	begin_type_declaration_specifiers declmod
    956 |	begin_type_declaration_specifiers notype_type_specifier {
    957 		dcs_add_type($2);
    958 	}
    959 ;
    960 
    961 begin_type_declmods:		/* see C99 6.7 */
    962 	begin_type type_qualifier {
    963 		dcs_add_qualifiers($2);
    964 	}
    965 |	begin_type T_SCLASS {
    966 		dcs_add_storage_class($2);
    967 	}
    968 |	begin_type T_FUNCTION_SPECIFIER {
    969 		dcs_add_function_specifier($2);
    970 	}
    971 |	begin_type_declmods declmod
    972 ;
    973 
    974 begin_type_specifier_qualifier_list:	/* see C11 6.7.2.1 */
    975 	begin_type_specifier_qualifier_list_postfix
    976 |	type_attribute_list begin_type_specifier_qualifier_list_postfix
    977 ;
    978 
    979 begin_type_specifier_qualifier_list_postfix:
    980 	begin_type_typespec {
    981 		dcs_add_type($1);
    982 	}
    983 |	begin_type_qualifier_list type_type_specifier {
    984 		dcs_add_type($2);
    985 	}
    986 |	begin_type_specifier_qualifier_list_postfix type_qualifier {
    987 		dcs_add_qualifiers($2);
    988 	}
    989 |	begin_type_specifier_qualifier_list_postfix notype_type_specifier {
    990 		dcs_add_type($2);
    991 	}
    992 |	begin_type_specifier_qualifier_list_postfix type_attribute
    993 ;
    994 
    995 begin_type_typespec:
    996 	begin_type notype_type_specifier {
    997 		$$ = $2;
    998 	}
    999 |	begin_type T_TYPENAME {
   1000 		$$ = getsym($2)->s_type;
   1001 	}
   1002 ;
   1003 
   1004 begin_type_qualifier_list:
   1005 	begin_type type_qualifier {
   1006 		dcs_add_qualifiers($2);
   1007 	}
   1008 |	begin_type_qualifier_list type_qualifier {
   1009 		dcs_add_qualifiers($2);
   1010 	}
   1011 ;
   1012 
   1013 declmod:
   1014 	type_qualifier {
   1015 		dcs_add_qualifiers($1);
   1016 	}
   1017 |	T_SCLASS {
   1018 		dcs_add_storage_class($1);
   1019 	}
   1020 |	T_FUNCTION_SPECIFIER {
   1021 		dcs_add_function_specifier($1);
   1022 	}
   1023 |	type_attribute_list
   1024 ;
   1025 
   1026 type_attribute_list_opt:
   1027 	/* empty */
   1028 |	type_attribute_list
   1029 ;
   1030 
   1031 type_attribute_list:
   1032 	type_attribute
   1033 |	type_attribute_list type_attribute
   1034 ;
   1035 
   1036 type_attribute_opt:
   1037 	/* empty */
   1038 |	type_attribute
   1039 ;
   1040 
   1041 type_attribute:			/* See C11 6.7 declaration-specifiers */
   1042 	gcc_attribute_specifier
   1043 |	T_ALIGNAS T_LPAREN type_type_specifier T_RPAREN {		/* C11 6.7.5 */
   1044 		dcs_add_alignas(build_sizeof($3));
   1045 	}
   1046 |	T_ALIGNAS T_LPAREN constant_expression T_RPAREN {	/* C11 6.7.5 */
   1047 		dcs_add_alignas($3);
   1048 	}
   1049 |	T_PACKED {
   1050 		dcs_add_packed();
   1051 	}
   1052 ;
   1053 
   1054 begin_type:
   1055 	/* empty */ {
   1056 		dcs_begin_type();
   1057 	}
   1058 |	attribute_specifier_sequence {
   1059 		dcs_begin_type();
   1060 		dcs->d_used = attributes_contain(&$1, "maybe_unused");
   1061 	}
   1062 ;
   1063 
   1064 end_type:
   1065 	/* empty */ {
   1066 		dcs_end_type();
   1067 	}
   1068 ;
   1069 
   1070 /* TODO: Implement 'declaration_specifier' from C23 6.7.1. */
   1071 
   1072 /*
   1073  * For an explanation of 'type' and 'notype' prefixes in the following rules,
   1074  * see https://www.gnu.org/software/bison/manual/bison.html#Semantic-Tokens.
   1075  */
   1076 
   1077 /* C23 6.7.1 */
   1078 /* The rule 'init_declarator_list' is split into the 'notype' and 'type' variants. */
   1079 
   1080 notype_init_declarator_list:
   1081 	notype_init_declarator
   1082 |	notype_init_declarator_list T_COMMA type_init_declarator
   1083 ;
   1084 
   1085 type_init_declarator_list:
   1086 	type_init_declarator
   1087 |	type_init_declarator_list T_COMMA type_init_declarator
   1088 ;
   1089 
   1090 /* C23 6.7.1 */
   1091 /* The rule 'init_declarator' is split into the 'notype' and 'type' variants. */
   1092 
   1093 notype_init_declarator:
   1094 	notype_declarator asm_or_symbolrename_opt {
   1095 		cgram_declare($1, false, $2);
   1096 		check_size($1);
   1097 	}
   1098 |	notype_declarator asm_or_symbolrename_opt {
   1099 		begin_initialization($1);
   1100 		cgram_declare($1, true, $2);
   1101 	} T_ASSIGN initializer {
   1102 		check_size($1);
   1103 		end_initialization();
   1104 	}
   1105 ;
   1106 
   1107 type_init_declarator:
   1108 	type_declarator asm_or_symbolrename_opt {
   1109 		cgram_declare($1, false, $2);
   1110 		check_size($1);
   1111 	}
   1112 |	type_declarator asm_or_symbolrename_opt {
   1113 		begin_initialization($1);
   1114 		cgram_declare($1, true, $2);
   1115 	} T_ASSIGN initializer {
   1116 		if ($1->s_type->t_tspec != AUTO_TYPE)
   1117 			check_size($1);
   1118 		end_initialization();
   1119 	}
   1120 ;
   1121 
   1122 
   1123 /* TODO: Implement 'attribute_declaration' from C23 6.7.1. */
   1124 
   1125 /* K&R ???, C90 ???, C99 ???, C11 ???, C23 6.7.2 */
   1126 storage_class_specifier:
   1127 	T_SCLASS
   1128 ;
   1129 
   1130 /* C99 6.7.2, C23 6.7.3.1 */
   1131 /* The rule 'type_specifier' is split into the 'notype' and 'type' variants. */
   1132 
   1133 type_type_specifier:
   1134 	notype_type_specifier
   1135 |	T_TYPENAME {
   1136 		$$ = getsym($1)->s_type;
   1137 	}
   1138 ;
   1139 
   1140 notype_type_specifier:		/* see C99 6.7.2 */
   1141 	T_TYPE {
   1142 		$$ = gettyp($1);
   1143 	}
   1144 |	T_TYPEOF T_LPAREN expression T_RPAREN {	/* GCC extension */
   1145 		$$ = $3 != NULL ? block_dup_type($3->tn_type) : gettyp(INT);
   1146 		$$->t_typeof = true;
   1147 	}
   1148 |	atomic_type_specifier
   1149 |	struct_or_union_specifier {
   1150 		end_declaration_level();
   1151 		$$ = $1;
   1152 	}
   1153 |	enum_specifier {
   1154 		end_declaration_level();
   1155 		$$ = $1;
   1156 	}
   1157 ;
   1158 
   1159 /* K&R ---, C90 ---, C99 6.7.2.1, C11 ???, C23 6.7.3.2 */
   1160 struct_or_union_specifier:
   1161 	struct_or_union identifier_sym {
   1162 		/*
   1163 		 * STDC requires that "struct a;" always introduces
   1164 		 * a new tag if "a" is not declared at current level
   1165 		 *
   1166 		 * yychar is valid because otherwise the parser would not
   1167 		 * have been able to decide if it must shift or reduce
   1168 		 */
   1169 		$$ = make_tag_type($2, $1, false, yychar == T_SEMI);
   1170 	}
   1171 |	struct_or_union identifier_sym {
   1172 		dcs->d_tag_type = make_tag_type($2, $1, true, false);
   1173 	} braced_member_declaration_list {
   1174 		$$ = complete_struct_or_union($4);
   1175 	}
   1176 |	struct_or_union {
   1177 		dcs->d_tag_type = make_tag_type(NULL, $1, true, false);
   1178 	} braced_member_declaration_list {
   1179 		$$ = complete_struct_or_union($3);
   1180 	}
   1181 |	struct_or_union error {
   1182 		set_sym_kind(SK_VCFT);
   1183 		$$ = gettyp(INT);
   1184 	}
   1185 ;
   1186 
   1187 /* K&R ---, C90 ---, C99 6.7.2.1, C11 ???, C23 6.7.3.2 */
   1188 struct_or_union:
   1189 	T_STRUCT_OR_UNION {
   1190 		set_sym_kind(SK_TAG);
   1191 		begin_declaration_level($1 == STRUCT ? DLK_STRUCT : DLK_UNION);
   1192 		dcs->d_sou_size_in_bits = 0;
   1193 		dcs->d_sou_align = 1;
   1194 		$$ = $1;
   1195 	}
   1196 |	struct_or_union type_attribute
   1197 ;
   1198 
   1199 braced_member_declaration_list:	/* see C99 6.7.2.1 */
   1200 	T_LBRACE {
   1201 		set_sym_kind(SK_VCFT);
   1202 	} member_declaration_list_with_rbrace {
   1203 		$$ = $3;
   1204 	}
   1205 ;
   1206 
   1207 member_declaration_list_with_rbrace:	/* see C99 6.7.2.1 */
   1208 	member_declaration_list T_RBRACE
   1209 |	T_RBRACE {
   1210 		/* XXX: Allowed since C23. */
   1211 		$$ = NULL;
   1212 	}
   1213 ;
   1214 
   1215 /* K&R ???, C90 ???, C99 6.7.2.1, C11 6.7.2.1, C23 6.7.3.2 */
   1216 /* Was named struct_declaration_list until C11. */
   1217 member_declaration_list:
   1218 	member_declaration
   1219 |	member_declaration_list member_declaration {
   1220 		$$ = concat_symbols($1, $2);
   1221 	}
   1222 ;
   1223 
   1224 /* K&R ???, C90 ???, C99 6.7.2.1, C11 6.7.2.1, C23 6.7.3.2 */
   1225 /* Was named struct_declaration until C11. */
   1226 member_declaration:
   1227 	begin_type_qualifier_list end_type {
   1228 		/* ^^ There is no check for the missing type-specifier. */
   1229 		/* too late, i know, but getsym() compensates it */
   1230 		set_sym_kind(SK_MEMBER);
   1231 	} notype_member_declarator_list T_SEMI {
   1232 		set_sym_kind(SK_VCFT);
   1233 		$$ = $4;
   1234 	}
   1235 |	begin_type_specifier_qualifier_list end_type {
   1236 		set_sym_kind(SK_MEMBER);
   1237 	} type_member_declarator_list T_SEMI {
   1238 		set_sym_kind(SK_VCFT);
   1239 		$$ = $4;
   1240 	}
   1241 |	begin_type_qualifier_list end_type type_attribute_opt T_SEMI {
   1242 		/* syntax error '%s' */
   1243 		error(249, "member without type");
   1244 		$$ = NULL;
   1245 	}
   1246 |	begin_type_specifier_qualifier_list end_type type_attribute_opt
   1247 	    T_SEMI {
   1248 		set_sym_kind(SK_VCFT);
   1249 		if (!allow_c11 && !allow_gcc)
   1250 			/* anonymous struct/union members is a C11 feature */
   1251 			warning(49);
   1252 		if (is_struct_or_union(dcs->d_type->t_tspec))
   1253 			$$ = declare_unnamed_member();
   1254 		else {
   1255 			/* syntax error '%s' */
   1256 			error(249, "unnamed member");
   1257 			$$ = NULL;
   1258 		}
   1259 	}
   1260 |	static_assert_declaration {
   1261 		$$ = NULL;
   1262 	}
   1263 |	error T_SEMI {
   1264 		set_sym_kind(SK_VCFT);
   1265 		$$ = NULL;
   1266 	}
   1267 ;
   1268 
   1269 /* TODO: Implement 'specifier_qualifier_list' from C23 6.7.3.2. */
   1270 
   1271 /* TODO: Implement 'type_specifier_qualifier' from C23 6.7.3.2. */
   1272 
   1273 /* C23 6.7.3.2 */
   1274 /* The rule 'member_declarator_list' is split into the 'type' and 'notype' variants. */
   1275 /* Was named struct_declarator_list until C11. */
   1276 
   1277 notype_member_declarator_list:
   1278 	notype_member_declarator {
   1279 		$$ = declare_member($1);
   1280 	}
   1281 |	notype_member_declarator_list {
   1282 		set_sym_kind(SK_MEMBER);
   1283 	} T_COMMA type_member_declarator {
   1284 		$$ = concat_symbols($1, declare_member($4));
   1285 	}
   1286 ;
   1287 
   1288 type_member_declarator_list:
   1289 	type_member_declarator {
   1290 		$$ = declare_member($1);
   1291 	}
   1292 |	type_member_declarator_list {
   1293 		set_sym_kind(SK_MEMBER);
   1294 	} T_COMMA type_member_declarator {
   1295 		$$ = concat_symbols($1, declare_member($4));
   1296 	}
   1297 ;
   1298 
   1299 /* C23 6.7.3.2 */
   1300 /* The rule 'member_declarator' is split into the 'type' and 'notype' variants. */
   1301 /* Was named struct_declarator until C11. */
   1302 
   1303 notype_member_declarator:
   1304 	notype_declarator
   1305 	/* C99 6.7.2.1 */
   1306 |	notype_declarator T_COLON constant_expression {
   1307 		$$ = set_bit_field_width($1, to_int_constant($3, true));
   1308 	}
   1309 	/* C99 6.7.2.1 */
   1310 |	{
   1311 		set_sym_kind(SK_VCFT);
   1312 	} T_COLON constant_expression {
   1313 		$$ = set_bit_field_width(NULL, to_int_constant($3, true));
   1314 	}
   1315 ;
   1316 
   1317 type_member_declarator:
   1318 	type_declarator
   1319 |	type_declarator T_COLON constant_expression type_attribute_list_opt {
   1320 		$$ = set_bit_field_width($1, to_int_constant($3, true));
   1321 	}
   1322 |	{
   1323 		set_sym_kind(SK_VCFT);
   1324 	} T_COLON constant_expression type_attribute_list_opt {
   1325 		$$ = set_bit_field_width(NULL, to_int_constant($3, true));
   1326 	}
   1327 ;
   1328 
   1329 /* K&R ---, C90 6.5.2.2, C99 6.7.2.2, C11 6.7.2.2, C23 6.7.3.5 */
   1330 enum_specifier:
   1331 	enum gcc_attribute_specifier_list_opt identifier_sym {
   1332 		$$ = make_tag_type($3, ENUM, false, false);
   1333 	}
   1334 |	enum gcc_attribute_specifier_list_opt identifier_sym {
   1335 		dcs->d_tag_type = make_tag_type($3, ENUM, true, false);
   1336 	} enum_declaration /*gcc_attribute_specifier_list_opt*/ {
   1337 		$$ = complete_enum($5);
   1338 	}
   1339 |	enum gcc_attribute_specifier_list_opt {
   1340 		dcs->d_tag_type = make_tag_type(NULL, ENUM, true, false);
   1341 	} enum_declaration /*gcc_attribute_specifier_list_opt*/ {
   1342 		$$ = complete_enum($4);
   1343 	}
   1344 |	enum error {
   1345 		set_sym_kind(SK_VCFT);
   1346 		$$ = gettyp(INT);
   1347 	}
   1348 ;
   1349 
   1350 enum:				/* helper for C99 6.7.2.2 */
   1351 	T_ENUM {
   1352 		set_sym_kind(SK_TAG);
   1353 		begin_declaration_level(DLK_ENUM);
   1354 	}
   1355 ;
   1356 
   1357 enum_declaration:		/* helper for C99 6.7.2.2 */
   1358 	T_LBRACE {
   1359 		set_sym_kind(SK_VCFT);
   1360 		enumval = 0;
   1361 	} enums_with_opt_comma T_RBRACE {
   1362 		$$ = $3;
   1363 	}
   1364 ;
   1365 
   1366 enums_with_opt_comma:		/* helper for C99 6.7.2.2 */
   1367 	enumerator_list
   1368 |	enumerator_list T_COMMA {
   1369 		if (!allow_c99 && !allow_trad)
   1370 			/* trailing ',' in enum declaration requires C99 ... */
   1371 			error(54);
   1372 		else
   1373 			/* trailing ',' in enum declaration requires C99 ... */
   1374 			c99ism(54);
   1375 		$$ = $1;
   1376 	}
   1377 ;
   1378 
   1379 /* C99 6.7.2.2, C23 6.7.3.3 */
   1380 enumerator_list:
   1381 	enumerator
   1382 |	enumerator_list T_COMMA enumerator {
   1383 		$$ = concat_symbols($1, $3);
   1384 	}
   1385 |	error {
   1386 		$$ = NULL;
   1387 	}
   1388 ;
   1389 
   1390 /* C99 6.7.2.2, C23 6.7.3.3 */
   1391 enumerator:
   1392 	identifier_sym gcc_attribute_specifier_list_opt {
   1393 		$$ = enumeration_constant($1, enumval, true);
   1394 	}
   1395 |	identifier_sym gcc_attribute_specifier_list_opt
   1396 	    T_ASSIGN constant_expression {
   1397 		$$ = enumeration_constant($1, to_int_constant($4, true),
   1398 		    false);
   1399 	}
   1400 ;
   1401 
   1402 /* TODO: Implement 'enum_type_specifier' from C23 6.7.3.3. */
   1403 
   1404 /* K&R ---, C90 ---, C99 ---, C11 6.7.2.4, C23 6.7.3.5 */
   1405 atomic_type_specifier:
   1406 	atomic T_LPAREN type_name T_RPAREN {
   1407 		$$ = $3;
   1408 	}
   1409 ;
   1410 
   1411 atomic:				/* helper */
   1412 	T_ATOMIC {
   1413 		/* TODO: First fix c11ism, then use it here. */
   1414 		if (!allow_c11)
   1415 			/* '_Atomic' requires C11 or later */
   1416 			error(350);
   1417 	}
   1418 ;
   1419 
   1420 /* TODO: Implement 'typeof_specifier' from C23 6.7.3.6. */
   1421 
   1422 /* TODO: Implement 'typeof_specifier_argument' from C23 6.7.3.6. */
   1423 
   1424 /* C99 6.7.3, C23 6.7.4.1 */
   1425 type_qualifier:
   1426 	T_QUAL
   1427 |	atomic {
   1428 		$$ = (type_qualifiers){ .tq_atomic = true };
   1429 	}
   1430 ;
   1431 
   1432 /* TODO: Implement 'function_specifier' from C23 6.7.5. */
   1433 
   1434 /* TODO: Implement 'alignment_specifier' from C23 6.7.6. */
   1435 
   1436 /* C23 6.7.7.1 */
   1437 /* The rule 'declarator' is split into the 'notype' and 'type' variants. */
   1438 
   1439 notype_declarator:
   1440 	notype_direct_declarator
   1441 |	pointer notype_direct_declarator {
   1442 		$$ = add_pointer($2, $1);
   1443 	}
   1444 ;
   1445 
   1446 type_declarator:
   1447 	type_direct_declarator
   1448 |	pointer type_direct_declarator {
   1449 		$$ = add_pointer($2, $1);
   1450 	}
   1451 ;
   1452 
   1453 /* C23 6.7.7.1 */
   1454 /* The rule 'direct_declarator' is split into the 'notype' and 'type' variants. */
   1455 
   1456 notype_direct_declarator:
   1457 	type_attribute_list_opt T_NAME {
   1458 		$$ = declarator_name(getsym($2));
   1459 	}
   1460 |	type_attribute_list_opt T_LPAREN type_declarator T_RPAREN {
   1461 		$$ = $3;
   1462 	}
   1463 |	notype_direct_declarator T_LBRACK array_size_opt T_RBRACK {
   1464 		$$ = add_array($1, $3.has_dim, $3.dim);
   1465 	}
   1466 |	notype_direct_declarator param_list asm_or_symbolrename_opt {
   1467 		$$ = add_function(symbolrename($1, $3), $2);
   1468 		end_declaration_level();
   1469 		block_level--;
   1470 	}
   1471 |	notype_direct_declarator type_attribute
   1472 ;
   1473 
   1474 type_direct_declarator:
   1475 	type_attribute_list_opt identifier {
   1476 		$$ = declarator_name(getsym($2));
   1477 	}
   1478 |	type_attribute_list_opt T_LPAREN type_declarator T_RPAREN {
   1479 		$$ = $3;
   1480 	}
   1481 |	type_direct_declarator T_LBRACK array_size_opt T_RBRACK {
   1482 		$$ = add_array($1, $3.has_dim, $3.dim);
   1483 	}
   1484 |	type_direct_declarator param_list asm_or_symbolrename_opt {
   1485 		$$ = add_function(symbolrename($1, $3), $2);
   1486 		end_declaration_level();
   1487 		block_level--;
   1488 	}
   1489 |	type_direct_declarator type_attribute
   1490 ;
   1491 
   1492 
   1493 /* TODO: Implement 'array_declarator' from C23 6.7.7.1. */
   1494 
   1495 /* TODO: Implement 'function_declarator' from C23 6.7.7.1. */
   1496 
   1497 /* C99 6.7.5, C23 6.7.7.1 */
   1498 pointer:
   1499 	T_ASTERISK type_qualifier_list_opt {
   1500 		$$ = xcalloc(1, sizeof(*$$));
   1501 		add_type_qualifiers(&$$->qualifiers, $2);
   1502 	}
   1503 |	T_ASTERISK type_qualifier_list_opt pointer {
   1504 		$$ = xcalloc(1, sizeof(*$$));
   1505 		add_type_qualifiers(&$$->qualifiers, $2);
   1506 		$$ = append_qualified_pointer($$, $3);
   1507 	}
   1508 ;
   1509 
   1510 /* see C99 6.7.5, C23 6.7.7.1 */
   1511 type_qualifier_list_opt:
   1512 	/* empty */ {
   1513 		$$ = (type_qualifiers){ .tq_const = false };
   1514 	}
   1515 |	type_qualifier_list
   1516 ;
   1517 
   1518 /* C99 6.7.5 */
   1519 type_qualifier_list:
   1520 	type_qualifier
   1521 |	type_qualifier_list type_qualifier {
   1522 		$$ = $1;
   1523 		add_type_qualifiers(&$$, $2);
   1524 	}
   1525 ;
   1526 
   1527 /* TODO: Implement 'parameter_type_list' from C23 6.7.7.1. */
   1528 
   1529 /* TODO: Implement 'parameter_list' from C23 6.7.7.1. */
   1530 
   1531 /* C23 6.7.7.1 */
   1532 /* XXX: C99 6.7.5 defines the same name, but it looks completely different. */
   1533 parameter_declaration:
   1534 	begin_type_declmods end_type {
   1535 		/* ^^ There is no check for the missing type-specifier. */
   1536 		$$ = declare_parameter(abstract_name(), false);
   1537 	}
   1538 |	begin_type_declaration_specifiers end_type {
   1539 		$$ = declare_parameter(abstract_name(), false);
   1540 	}
   1541 |	begin_type_declmods end_type notype_param_declarator {
   1542 		/* ^^ There is no check for the missing type-specifier. */
   1543 		$$ = declare_parameter($3, false);
   1544 	}
   1545 	/*
   1546 	 * type_param_declarator is needed because of following conflict:
   1547 	 * "typedef int a; f(int (a));" could be parsed as
   1548 	 * "function with argument a of type int", or
   1549 	 * "function with an unnamed (abstract) argument of type function".
   1550 	 * This grammar realizes the second case.
   1551 	 */
   1552 |	begin_type_declaration_specifiers end_type type_param_declarator {
   1553 		$$ = declare_parameter($3, false);
   1554 	}
   1555 |	begin_type_declmods end_type abstract_declarator {
   1556 		/* ^^ There is no check for the missing type-specifier. */
   1557 		$$ = declare_parameter($3, false);
   1558 	}
   1559 |	begin_type_declaration_specifiers end_type abstract_declarator {
   1560 		$$ = declare_parameter($3, false);
   1561 	}
   1562 ;
   1563 
   1564 /*
   1565  * The two distinct rules type_param_declarator and notype_param_declarator
   1566  * avoid a conflict in parameter lists. A typename enclosed in parentheses is
   1567  * always treated as a typename, not an argument name. For example, after
   1568  * "typedef double a;", the declaration "f(int (a));" is interpreted as
   1569  * "f(int (double));", not "f(int a);".
   1570  */
   1571 type_param_declarator:
   1572 	direct_param_declarator
   1573 |	pointer direct_param_declarator {
   1574 		$$ = add_pointer($2, $1);
   1575 	}
   1576 ;
   1577 
   1578 notype_param_declarator:
   1579 	direct_notype_param_declarator
   1580 |	pointer direct_notype_param_declarator {
   1581 		$$ = add_pointer($2, $1);
   1582 	}
   1583 ;
   1584 
   1585 direct_param_declarator:
   1586 	identifier type_attribute_list {
   1587 		$$ = declarator_name(getsym($1));
   1588 	}
   1589 |	identifier {
   1590 		$$ = declarator_name(getsym($1));
   1591 	}
   1592 |	T_LPAREN notype_param_declarator T_RPAREN {
   1593 		$$ = $2;
   1594 	}
   1595 |	direct_param_declarator T_LBRACK array_size_opt T_RBRACK
   1596 	    gcc_attribute_specifier_list_opt {
   1597 		$$ = add_array($1, $3.has_dim, $3.dim);
   1598 	}
   1599 |	direct_param_declarator param_list asm_or_symbolrename_opt {
   1600 		$$ = add_function(symbolrename($1, $3), $2);
   1601 		end_declaration_level();
   1602 		block_level--;
   1603 	}
   1604 ;
   1605 
   1606 direct_notype_param_declarator:
   1607 	identifier {
   1608 		$$ = declarator_name(getsym($1));
   1609 	}
   1610 |	T_LPAREN notype_param_declarator T_RPAREN {
   1611 		$$ = $2;
   1612 	}
   1613 |	direct_notype_param_declarator T_LBRACK array_size_opt T_RBRACK {
   1614 		$$ = add_array($1, $3.has_dim, $3.dim);
   1615 	}
   1616 |	direct_notype_param_declarator param_list asm_or_symbolrename_opt {
   1617 		$$ = add_function(symbolrename($1, $3), $2);
   1618 		end_declaration_level();
   1619 		block_level--;
   1620 	}
   1621 ;
   1622 
   1623 param_list:
   1624 	T_LPAREN {
   1625 		block_level++;
   1626 		begin_declaration_level(DLK_PROTO_PARAMS);
   1627 	} identifier_list T_RPAREN {
   1628 		$$ = (parameter_list){ .first = $3 };
   1629 	}
   1630 |	abstract_decl_param_list
   1631 ;
   1632 
   1633 array_size_opt:
   1634 	/* empty */ {
   1635 		$$.has_dim = false;
   1636 		$$.dim = 0;
   1637 	}
   1638 |	T_ASTERISK {
   1639 		/* since C99; variable length array of unspecified size */
   1640 		$$.has_dim = false; /* TODO: maybe change to true */
   1641 		$$.dim = 0;	/* just as a placeholder */
   1642 	}
   1643 |	type_qualifier_list_opt T_SCLASS constant_expression {
   1644 		/* C11 6.7.6.3p7 */
   1645 		if ($2 != STATIC)
   1646 			yyerror("Bad attribute");
   1647 		/* static array size requires C11 or later */
   1648 		c11ism(343);
   1649 		$$.has_dim = true;
   1650 		$$.dim = $3 == NULL ? 0 : to_int_constant($3, false);
   1651 	}
   1652 |	type_qualifier {
   1653 		/* C11 6.7.6.2 */
   1654 		if (!$1.tq_restrict)
   1655 			yyerror("Bad attribute");
   1656 		$$.has_dim = true;
   1657 		$$.dim = 0;
   1658 	}
   1659 |	constant_expression {
   1660 		$$.has_dim = true;
   1661 		$$.dim = $1 == NULL ? 0 : to_int_constant($1, false);
   1662 	}
   1663 ;
   1664 
   1665 identifier_list:		/* C99 6.7.5 */
   1666 	T_NAME {
   1667 		$$ = old_style_function_parameter_name(getsym($1));
   1668 	}
   1669 |	identifier_list T_COMMA T_NAME {
   1670 		$$ = concat_symbols($1,
   1671 		    old_style_function_parameter_name(getsym($3)));
   1672 	}
   1673 |	identifier_list error
   1674 ;
   1675 
   1676 /* C99 6.7.6, C23 6.7.8 */
   1677 /* XXX: C99 requires an additional specifier-qualifier-list. */
   1678 type_name:
   1679 	{
   1680 		begin_declaration_level(DLK_ABSTRACT);
   1681 	} abstract_declaration {
   1682 		end_declaration_level();
   1683 		$$ = $2->s_type;
   1684 	}
   1685 ;
   1686 
   1687 abstract_declaration:		/* specific to lint */
   1688 	begin_type_qualifier_list end_type {
   1689 		$$ = declare_abstract_type(abstract_name());
   1690 	}
   1691 |	begin_type_specifier_qualifier_list end_type {
   1692 		$$ = declare_abstract_type(abstract_name());
   1693 	}
   1694 |	begin_type_qualifier_list end_type abstract_declarator {
   1695 		$$ = declare_abstract_type($3);
   1696 	}
   1697 |	begin_type_specifier_qualifier_list end_type abstract_declarator {
   1698 		$$ = declare_abstract_type($3);
   1699 	}
   1700 ;
   1701 
   1702 abstract_decl_param_list:	/* specific to lint */
   1703 	abstract_decl_lparen T_RPAREN type_attribute_opt {
   1704 		$$ = (parameter_list){ .first = NULL };
   1705 	}
   1706 |	abstract_decl_lparen vararg_parameter_type_list T_RPAREN
   1707 	    type_attribute_opt {
   1708 		$$ = $2;
   1709 		$$.prototype = true;
   1710 	}
   1711 |	abstract_decl_lparen error T_RPAREN type_attribute_opt {
   1712 		$$ = (parameter_list){ .first = NULL };
   1713 	}
   1714 ;
   1715 
   1716 abstract_decl_lparen:		/* specific to lint */
   1717 	T_LPAREN {
   1718 		block_level++;
   1719 		begin_declaration_level(DLK_PROTO_PARAMS);
   1720 	}
   1721 ;
   1722 
   1723 vararg_parameter_type_list:	/* specific to lint */
   1724 	parameter_type_list
   1725 |	parameter_type_list T_COMMA T_ELLIPSIS {
   1726 		$$ = $1;
   1727 		$$.vararg = true;
   1728 	}
   1729 |	T_ELLIPSIS {
   1730 		/* TODO: C99 6.7.5 makes this an error as well. */
   1731 		if (!allow_trad && !allow_c99)
   1732 			/* C90 to C17 require formal parameter before '...' */
   1733 			error(84);
   1734 		else if (allow_c90)
   1735 			/* C90 to C17 require formal parameter before '...' */
   1736 			warning(84);
   1737 		$$ = (parameter_list){ .vararg = true };
   1738 	}
   1739 ;
   1740 
   1741 /* XXX: C99 6.7.5 defines the same name, but it looks different. */
   1742 parameter_type_list:
   1743 	parameter_declaration {
   1744 		$$ = (parameter_list){ .first = $1 };
   1745 	}
   1746 |	parameter_type_list T_COMMA parameter_declaration {
   1747 		$$ = $1;
   1748 		$$.first = concat_symbols($1.first, $3);
   1749 	}
   1750 ;
   1751 
   1752 /* K&R 8.7, C90 ???, C99 6.7.6, C11 6.7.7, C23 6.7.8 */
   1753 /* In K&R, abstract-declarator could be empty and was still simpler. */
   1754 abstract_declarator:
   1755 	pointer {
   1756 		$$ = add_pointer(abstract_name(), $1);
   1757 	}
   1758 |	direct_abstract_declarator
   1759 |	pointer direct_abstract_declarator {
   1760 		$$ = add_pointer($2, $1);
   1761 	}
   1762 |	type_attribute_list direct_abstract_declarator {
   1763 		$$ = $2;
   1764 	}
   1765 |	pointer type_attribute_list direct_abstract_declarator {
   1766 		$$ = add_pointer($3, $1);
   1767 	}
   1768 ;
   1769 
   1770 /* K&R ---, C90 ???, C99 6.7.6, C11 6.7.7, C23 6.7.8 */
   1771 direct_abstract_declarator:
   1772 	/* TODO: sort rules according to C99 */
   1773 	T_LPAREN abstract_declarator T_RPAREN {
   1774 		$$ = $2;
   1775 	}
   1776 |	T_LBRACK array_size_opt T_RBRACK {
   1777 		$$ = add_array(abstract_name(), $2.has_dim, $2.dim);
   1778 	}
   1779 |	direct_abstract_declarator T_LBRACK array_size_opt T_RBRACK {
   1780 		$$ = add_array($1, $3.has_dim, $3.dim);
   1781 	}
   1782 |	abstract_decl_param_list asm_or_symbolrename_opt {
   1783 		sym_t *name = abstract_enclosing_name();
   1784 		$$ = add_function(symbolrename(name, $2), $1);
   1785 		end_declaration_level();
   1786 		block_level--;
   1787 	}
   1788 |	direct_abstract_declarator abstract_decl_param_list
   1789 	    asm_or_symbolrename_opt {
   1790 		$$ = add_function(symbolrename($1, $3), $2);
   1791 		end_declaration_level();
   1792 		block_level--;
   1793 	}
   1794 |	direct_abstract_declarator type_attribute_list
   1795 ;
   1796 
   1797 /* TODO: Implement 'array_abstract_declarator' from C23 6.7.8. */
   1798 
   1799 /* TODO: Implement 'function_abstract_declarator' from C23 6.7.8. */
   1800 
   1801 /* TODO: Implement 'typedef_name' from C23 6.7.9. */
   1802 
   1803 /* C23 6.7.11 */
   1804 /* K&R ---, C90 ---, C99 6.7.8, C11 6.7.9, C23 6.7.10 */
   1805 braced_initializer:
   1806 	init_lbrace init_rbrace {
   1807 		/* empty initializer braces require C23 or later */
   1808 		c23ism(353);
   1809 	}
   1810 |	init_lbrace initializer_list init_rbrace
   1811 |	init_lbrace initializer_list T_COMMA init_rbrace
   1812 ;
   1813 
   1814 /* C99 6.7.8, C23 6.7.11 */
   1815 initializer:
   1816 	assignment_expression {
   1817 		init_expr($1);
   1818 	}
   1819 |	init_lbrace init_rbrace {
   1820 		/* XXX: Empty braces are not covered by C99 6.7.8. */
   1821 	}
   1822 |	init_lbrace initializer_list init_rbrace
   1823 |	init_lbrace initializer_list T_COMMA init_rbrace
   1824 	/* XXX: What is this error handling for? */
   1825 |	error
   1826 ;
   1827 
   1828 /* C99 6.7.8, C23 6.7.11 */
   1829 initializer_list:
   1830 	initializer
   1831 |	designation initializer
   1832 |	initializer_list T_COMMA initializer
   1833 |	initializer_list T_COMMA designation initializer
   1834 ;
   1835 
   1836 /* C99 6.7.8, C23 6.7.11 */
   1837 designation:
   1838 	{
   1839 		begin_designation();
   1840 	} designator_list T_ASSIGN
   1841 |	identifier T_COLON {
   1842 		/* GCC style struct or union member name in initializer */
   1843 		gnuism(315);
   1844 		begin_designation();
   1845 		add_designator_member($1);
   1846 	}
   1847 ;
   1848 
   1849 /* C99 6.7.8, C23 6.7.11 */
   1850 designator_list:
   1851 	designator
   1852 |	designator_list designator
   1853 ;
   1854 
   1855 /* C99 6.7.8, C23 6.7.11 */
   1856 designator:
   1857 	T_LBRACK range T_RBRACK {
   1858 		if (!allow_c99)
   1859 			/* array initializer with designators is a C99 ... */
   1860 			warning(321);
   1861 		add_designator_subscript($2);
   1862 	}
   1863 |	T_POINT identifier {
   1864 		if (!allow_c99)
   1865 			/* struct or union member name in initializer is ... */
   1866 			warning(313);
   1867 		add_designator_member($2);
   1868 	}
   1869 ;
   1870 
   1871 /* C23 6.7.12 */
   1872 static_assert_declaration:
   1873 	T_STATIC_ASSERT T_LPAREN constant_expression T_COMMA T_STRING
   1874 	    T_RPAREN T_SEMI {
   1875 		/* '_Static_assert' requires C11 or later */
   1876 		c11ism(354);
   1877 	}
   1878 |	T_STATIC_ASSERT T_LPAREN constant_expression T_RPAREN T_SEMI {
   1879 		/* '_Static_assert' without message requires C23 or later */
   1880 		c23ism(355);
   1881 	}
   1882 ;
   1883 
   1884 range:
   1885 	constant_expression {
   1886 		$$.lo = to_int_constant($1, true);
   1887 		$$.hi = $$.lo;
   1888 	}
   1889 |	constant_expression T_ELLIPSIS constant_expression {
   1890 		$$.lo = to_int_constant($1, true);
   1891 		$$.hi = to_int_constant($3, true);
   1892 		/* initialization with '[a...b]' is a GCC extension */
   1893 		gnuism(340);
   1894 	}
   1895 ;
   1896 
   1897 init_lbrace:			/* helper */
   1898 	T_LBRACE {
   1899 		init_lbrace();
   1900 	}
   1901 ;
   1902 
   1903 init_rbrace:			/* helper */
   1904 	T_RBRACE {
   1905 		init_rbrace();
   1906 	}
   1907 ;
   1908 
   1909 /* C23 6.7.13.2 */
   1910 attribute_specifier_sequence:
   1911 	attribute_specifier {
   1912 		$$ = (attribute_list) { NULL, 0, 0 };
   1913 		attribute_list_add_all(&$$, $1);
   1914 	}
   1915 |	attribute_specifier_sequence attribute_specifier {
   1916 		$$ = $1;
   1917 		attribute_list_add_all(&$$, $2);
   1918 	}
   1919 ;
   1920 
   1921 /* C23 6.7.13.2 */
   1922 attribute_specifier:
   1923 	T_LBRACK T_LBRACK attribute_list T_RBRACK T_RBRACK {
   1924 		$$ = $3;
   1925 	}
   1926 ;
   1927 
   1928 /* C23 6.7.13.2 */
   1929 attribute_list:
   1930 	/* empty */ {
   1931 		$$ = (attribute_list) { NULL, 0, 0 };
   1932 	}
   1933 |	attribute {
   1934 		$$ = (attribute_list) { NULL, 0, 0 };
   1935 		attribute_list_add(&$$, $1);
   1936 	}
   1937 |	attribute_list T_COMMA
   1938 |	attribute_list T_COMMA attribute {
   1939 		$$ = $1;
   1940 		attribute_list_add(&$$, $3);
   1941 	}
   1942 ;
   1943 
   1944 /* C23 6.7.13.2 */
   1945 attribute:
   1946 	identifier {
   1947 		$$ = new_attribute(NULL, $1, NULL);
   1948 	}
   1949 |	identifier T_DCOLON identifier {
   1950 		$$ = new_attribute($1, $3, NULL);
   1951 	}
   1952 |	identifier attribute_argument_clause {
   1953 		$$ = new_attribute(NULL, $1, &$2);
   1954 	}
   1955 |	identifier T_DCOLON identifier attribute_argument_clause {
   1956 		$$ = new_attribute($1, $3, &$4);
   1957 	}
   1958 ;
   1959 
   1960 /* The rule 'attribute_token' is inlined into 'attribute'. */
   1961 /* The rule 'standard_attribute' is inlined into 'attribute_token'. */
   1962 /* The rule 'attribute_prefixed_token' is inlined into 'attribute_token'. */
   1963 /* The rule 'attribute_prefix' is inlined into 'attribute_token'. */
   1964 
   1965 /* C23 6.7.13.2 */
   1966 attribute_argument_clause:
   1967 	T_LPAREN {
   1968 		$$ = read_balanced_token_sequence();
   1969 	}
   1970 ;
   1971 
   1972 /* The rule 'balanced_token_sequence' is inlined into 'attribute_argument_clause'. */
   1973 /* The rule 'balanced_token' is inlined into 'balanced_token_sequence'. */
   1974 
   1975 asm_or_symbolrename_opt:	/* GCC extensions */
   1976 	/* empty */ {
   1977 		$$ = NULL;
   1978 	}
   1979 |	T_ASM T_LPAREN T_STRING T_RPAREN gcc_attribute_specifier_list_opt {
   1980 		freeyyv(&$3, T_STRING);
   1981 		$$ = NULL;
   1982 	}
   1983 |	T_SYMBOLRENAME T_LPAREN T_NAME T_RPAREN
   1984 	    gcc_attribute_specifier_list_opt {
   1985 		$$ = $3;
   1986 	}
   1987 ;
   1988 
   1989 /* K&R ???, C90 ???, C99 6.8, C11 ???, C23 6.8.1 */
   1990 statement:
   1991 	expression_statement
   1992 |	non_expr_statement
   1993 ;
   1994 
   1995 /* Helper to avoid shift/reduce conflict in 'label: __attribute__ ;'. */
   1996 no_attr_statement:
   1997 	expression_statement
   1998 |	no_attr_non_expr_statement
   1999 ;
   2000 
   2001 non_expr_statement:		/* helper for C99 6.8 */
   2002 	gcc_attribute_specifier /* ((__fallthrough__)) */ T_SEMI
   2003 |	no_attr_non_expr_statement
   2004 ;
   2005 
   2006 /* Helper to avoid shift/reduce conflict in 'label: __attribute__ ;'. */
   2007 no_attr_non_expr_statement:
   2008 	labeled_statement
   2009 |	compound_statement
   2010 |	selection_statement
   2011 |	iteration_statement
   2012 |	jump_statement {
   2013 		suppress_fallthrough = false;
   2014 	}
   2015 |	asm_statement
   2016 ;
   2017 
   2018 /* TODO: Implement 'unlabeled_statement' from C23 6.8.1. */
   2019 
   2020 /* TODO: Implement 'primary_block' from C23 6.8.1. */
   2021 
   2022 /* TODO: Implement 'secondary_block' from C23 6.8.1. */
   2023 
   2024 /* C23 6.8.2 */
   2025 label:
   2026 	T_NAME T_COLON {
   2027 		set_sym_kind(SK_LABEL);
   2028 		named_label(getsym($1));
   2029 	}
   2030 |	T_CASE constant_expression T_COLON {
   2031 		case_label($2);
   2032 		suppress_fallthrough = true;
   2033 	}
   2034 |	T_CASE constant_expression T_ELLIPSIS constant_expression T_COLON {
   2035 		/* XXX: We don't fill all cases */
   2036 		case_label($2);
   2037 		suppress_fallthrough = true;
   2038 	}
   2039 |	T_DEFAULT T_COLON {
   2040 		default_label();
   2041 		suppress_fallthrough = true;
   2042 	}
   2043 ;
   2044 
   2045 /* C99 6.8.1, C23 6.8.2 */
   2046 labeled_statement:
   2047 	label gcc_attribute_specifier_list_opt no_attr_statement
   2048 ;
   2049 
   2050 /* C99 6.8.2, C23 6.8.3 */
   2051 compound_statement:
   2052 	compound_statement_lbrace compound_statement_rbrace
   2053 |	compound_statement_lbrace block_item_list compound_statement_rbrace
   2054 ;
   2055 
   2056 compound_statement_lbrace:
   2057 	T_LBRACE {
   2058 		block_level++;
   2059 		mem_block_level++;
   2060 		debug_step("%s: mem_block_level = %zu",
   2061 		    "compound_statement_lbrace", mem_block_level);
   2062 		begin_declaration_level(DLK_AUTO);
   2063 	}
   2064 ;
   2065 
   2066 compound_statement_rbrace:
   2067 	T_RBRACE {
   2068 		end_declaration_level();
   2069 		if (!in_statement_expr())
   2070 			level_free_all(mem_block_level);	/* leak */
   2071 		mem_block_level--;
   2072 		debug_step("%s: mem_block_level = %zu",
   2073 		    "compound_statement_rbrace", mem_block_level);
   2074 		block_level--;
   2075 		suppress_fallthrough = false;
   2076 	}
   2077 ;
   2078 
   2079 /* C99 6.8.2, C23 6.8.3 */
   2080 block_item_list:
   2081 	block_item
   2082 |	block_item_list block_item {
   2083 		if ($1 && !$2)
   2084 			/* declarations after statements is a C99 feature */
   2085 			c99ism(327);
   2086 		$$ = $1 || $2;
   2087 	}
   2088 ;
   2089 
   2090 /* C99 6.8.2, C23 6.8.3 */
   2091 block_item:
   2092 	declaration_or_error {
   2093 		$$ = false;
   2094 		restore_warning_flags();
   2095 	}
   2096 |	statement {
   2097 		$$ = true;
   2098 		restore_warning_flags();
   2099 	}
   2100 ;
   2101 
   2102 /* C99 6.8.3, C23 6.8.4 */
   2103 expression_statement:
   2104 	expression T_SEMI {
   2105 		expr($1, false, false, false, false);
   2106 		suppress_fallthrough = false;
   2107 	}
   2108 |	T_SEMI {
   2109 		check_statement_reachable();
   2110 		suppress_fallthrough = false;
   2111 	}
   2112 |	attribute_specifier_sequence expression T_SEMI {
   2113 		debug_attribute_list(&$1);
   2114 		expr($2, false, false, false, false);
   2115 		suppress_fallthrough = false;
   2116 	}
   2117 |	attribute_specifier_sequence T_SEMI {
   2118 		debug_attribute_list(&$1);
   2119 		check_statement_reachable();
   2120 		suppress_fallthrough = attributes_contain(&$1, "fallthrough");
   2121 	}
   2122 ;
   2123 
   2124 /* C99 6.8.4, C23 6.8.5.1 */
   2125 selection_statement:
   2126 	if_without_else %prec T_THEN {
   2127 		save_warning_flags();
   2128 		stmt_if_then_stmt();
   2129 		stmt_if_else_stmt(false);
   2130 	}
   2131 |	if_without_else T_ELSE {
   2132 		save_warning_flags();
   2133 		stmt_if_then_stmt();
   2134 	} statement {
   2135 		clear_warning_flags();
   2136 		stmt_if_else_stmt(true);
   2137 	}
   2138 |	if_without_else T_ELSE error {
   2139 		clear_warning_flags();
   2140 		stmt_if_else_stmt(false);
   2141 	}
   2142 |	switch_expr statement {
   2143 		clear_warning_flags();
   2144 		stmt_switch_expr_stmt();
   2145 	}
   2146 |	switch_expr error {
   2147 		clear_warning_flags();
   2148 		stmt_switch_expr_stmt();
   2149 	}
   2150 ;
   2151 
   2152 if_without_else:		/* see C99 6.8.4 */
   2153 	if_expr statement
   2154 |	if_expr error
   2155 ;
   2156 
   2157 if_expr:			/* see C99 6.8.4 */
   2158 	T_IF T_LPAREN expression T_RPAREN {
   2159 		stmt_if_expr($3);
   2160 		clear_warning_flags();
   2161 	}
   2162 ;
   2163 
   2164 switch_expr:			/* see C99 6.8.4 */
   2165 	T_SWITCH T_LPAREN expression T_RPAREN {
   2166 		stmt_switch_expr($3);
   2167 		clear_warning_flags();
   2168 	}
   2169 ;
   2170 
   2171 /* C99 6.8.5, C23 6.8.6.1 */
   2172 iteration_statement:
   2173 	while_expr statement {
   2174 		clear_warning_flags();
   2175 		stmt_while_expr_stmt();
   2176 	}
   2177 |	while_expr error {
   2178 		clear_warning_flags();
   2179 		stmt_while_expr_stmt();
   2180 	}
   2181 |	do_statement T_WHILE T_LPAREN expression T_RPAREN T_SEMI {
   2182 		stmt_do_while_expr($4);
   2183 		suppress_fallthrough = false;
   2184 	}
   2185 |	do error {
   2186 		clear_warning_flags();
   2187 		stmt_do_while_expr(NULL);
   2188 	}
   2189 |	for_exprs statement {
   2190 		clear_warning_flags();
   2191 		stmt_for_exprs_stmt();
   2192 		end_declaration_level();
   2193 		block_level--;
   2194 	}
   2195 |	for_exprs error {
   2196 		clear_warning_flags();
   2197 		stmt_for_exprs_stmt();
   2198 		end_declaration_level();
   2199 		block_level--;
   2200 	}
   2201 ;
   2202 
   2203 while_expr:			/* see C99 6.8.5 */
   2204 	T_WHILE T_LPAREN expression T_RPAREN {
   2205 		stmt_while_expr($3);
   2206 		clear_warning_flags();
   2207 	}
   2208 ;
   2209 
   2210 do_statement:			/* see C99 6.8.5 */
   2211 	do statement {
   2212 		clear_warning_flags();
   2213 	}
   2214 ;
   2215 
   2216 do:				/* see C99 6.8.5 */
   2217 	T_DO {
   2218 		stmt_do();
   2219 	}
   2220 ;
   2221 
   2222 for_start:			/* see C99 6.8.5 */
   2223 	T_FOR T_LPAREN {
   2224 		begin_declaration_level(DLK_AUTO);
   2225 		block_level++;
   2226 	}
   2227 ;
   2228 
   2229 for_exprs:			/* see C99 6.8.5 */
   2230 	for_start
   2231 	    begin_type_declaration_specifiers end_type
   2232 	    notype_init_declarator_list T_SEMI
   2233 	    expression_opt T_SEMI
   2234 	    expression_opt T_RPAREN {
   2235 		/* variable declaration in for loop */
   2236 		c99ism(325);
   2237 		stmt_for_exprs(NULL, $6, $8);
   2238 		clear_warning_flags();
   2239 	}
   2240 |	for_start
   2241 	    expression_opt T_SEMI
   2242 	    expression_opt T_SEMI
   2243 	    expression_opt T_RPAREN {
   2244 		stmt_for_exprs($2, $4, $6);
   2245 		clear_warning_flags();
   2246 	}
   2247 ;
   2248 
   2249 /* C99 6.8.6, C23 6.8.7.1 */
   2250 jump_statement:
   2251 	goto identifier T_SEMI {
   2252 		stmt_goto(getsym($2));
   2253 	}
   2254 |	goto error T_SEMI {
   2255 		set_sym_kind(SK_VCFT);
   2256 	}
   2257 |	T_CONTINUE T_SEMI {
   2258 		stmt_continue();
   2259 	}
   2260 |	T_BREAK T_SEMI {
   2261 		stmt_break();
   2262 	}
   2263 |	T_RETURN sys T_SEMI {
   2264 		stmt_return($2, NULL);
   2265 	}
   2266 |	T_RETURN sys expression T_SEMI {
   2267 		stmt_return($2, $3);
   2268 	}
   2269 ;
   2270 
   2271 goto:				/* see C99 6.8.6 */
   2272 	T_GOTO {
   2273 		set_sym_kind(SK_LABEL);
   2274 	}
   2275 ;
   2276 
   2277 asm_statement:			/* GCC extension */
   2278 	T_ASM T_LPAREN read_until_rparen T_SEMI {
   2279 		dcs_set_asm();
   2280 	}
   2281 |	T_ASM type_qualifier T_LPAREN read_until_rparen T_SEMI {
   2282 		dcs_set_asm();
   2283 	}
   2284 |	T_ASM error
   2285 ;
   2286 
   2287 read_until_rparen:		/* helper for 'asm_statement' */
   2288 	/* empty */ {
   2289 		read_until_rparen();
   2290 	}
   2291 ;
   2292 
   2293 /* C99 6.9, C23 6.9.1 */
   2294 translation_unit:
   2295 	external_declaration
   2296 |	translation_unit external_declaration
   2297 ;
   2298 
   2299 /* C99 6.9, C23 6.9.1 */
   2300 external_declaration:
   2301 	function_definition {
   2302 		global_clean_up_decl(false);
   2303 		clear_warning_flags();
   2304 	}
   2305 |	top_level_declaration {
   2306 		global_clean_up_decl(false);
   2307 		clear_warning_flags();
   2308 	}
   2309 |	asm_statement		/* GCC extension */
   2310 |	T_SEMI {		/* GCC extension */
   2311 		/*
   2312 		 * TODO: Only allow this in GCC mode, not in plain C99.
   2313 		 * This is one of the top 10 warnings in the NetBSD build.
   2314 		 */
   2315 		if (!allow_trad && !allow_c99)
   2316 			/* empty declaration */
   2317 			error(0);
   2318 		else if (allow_c90)
   2319 			/* empty declaration */
   2320 			warning(0);
   2321 	}
   2322 ;
   2323 
   2324 /*
   2325  * On the top level, lint allows several forms of declarations that it doesn't
   2326  * allow in functions.  For example, a single ';' is an empty declaration and
   2327  * is supported by some compilers, but in a function it would be an empty
   2328  * statement, not a declaration.  This makes a difference in C90 mode, where
   2329  * a statement must not be followed by a declaration.
   2330  *
   2331  * See 'declaration' for all other declarations.
   2332  */
   2333 top_level_declaration:		/* C99 6.9 calls this 'declaration' */
   2334 	begin_type end_type notype_init_declarator_list T_SEMI {
   2335 		/* TODO: Make this an error in C99 mode as well. */
   2336 		if (!allow_trad && !allow_c99)
   2337 			/* old-style declaration; add 'int' */
   2338 			error(1);
   2339 		else if (allow_c90)
   2340 			/* old-style declaration; add 'int' */
   2341 			warning(1);
   2342 	}
   2343 |	declaration
   2344 |	error T_SEMI {
   2345 		global_clean_up();
   2346 	}
   2347 |	error T_RBRACE {
   2348 		global_clean_up();
   2349 	}
   2350 ;
   2351 
   2352 /* C99 6.9.1, C23 6.9.2 */
   2353 function_definition:
   2354 	func_declarator {
   2355 		if ($1->s_type->t_tspec != FUNC) {
   2356 			/* syntax error '%s' */
   2357 			error(249, yytext);
   2358 			YYERROR;
   2359 		}
   2360 		if ($1->s_type->t_typedef) {
   2361 			/* ()-less function definition */
   2362 			error(64);
   2363 			YYERROR;
   2364 		}
   2365 		check_extern_declaration($1);
   2366 		begin_function($1);
   2367 		block_level++;
   2368 		begin_declaration_level(DLK_OLD_STYLE_PARAMS);
   2369 		if (lwarn == LWARN_NONE)
   2370 			$1->s_used = true;
   2371 	} arg_declaration_list_opt {
   2372 		end_declaration_level();
   2373 		block_level--;
   2374 		check_func_lint_directives();
   2375 		check_func_old_style_parameters();
   2376 		begin_control_statement(CS_FUNCTION_BODY);
   2377 	} compound_statement {
   2378 		end_function();
   2379 		end_control_statement(CS_FUNCTION_BODY);
   2380 	}
   2381 ;
   2382 
   2383 func_declarator:
   2384 	begin_type end_type notype_declarator {
   2385 		if (!allow_trad)
   2386 			/* old-style declaration; add 'int' */
   2387 			error(1);
   2388 		$$ = $3;
   2389 	}
   2390 |	begin_type_declmods end_type notype_declarator {
   2391 		if (!allow_trad)
   2392 			/* old-style declaration; add 'int' */
   2393 			error(1);
   2394 		$$ = $3;
   2395 	}
   2396 |	begin_type_declaration_specifiers end_type type_declarator {
   2397 		$$ = $3;
   2398 	}
   2399 ;
   2400 
   2401 arg_declaration_list_opt:	/* C99 6.9.1p13 example 1 */
   2402 	/* empty */
   2403 |	arg_declaration_list
   2404 ;
   2405 
   2406 arg_declaration_list:		/* C99 6.9.1p13 example 1 */
   2407 	arg_declaration
   2408 |	arg_declaration_list arg_declaration
   2409 	/* XXX or better "arg_declaration error" ? */
   2410 |	error
   2411 ;
   2412 
   2413 /*
   2414  * "arg_declaration" is separated from "declaration" because it
   2415  * needs other error handling.
   2416  */
   2417 arg_declaration:
   2418 	begin_type_declmods end_type T_SEMI {
   2419 		/* empty declaration */
   2420 		warning(2);
   2421 	}
   2422 |	begin_type_declmods end_type notype_init_declarator_list T_SEMI
   2423 |	begin_type_declaration_specifiers end_type T_SEMI {
   2424 		if (!dcs->d_nonempty_decl)
   2425 			/* empty declaration */
   2426 			warning(2);
   2427 		else
   2428 			/* '%s' declared in parameter declaration list */
   2429 			warning(3, type_name(dcs->d_type));
   2430 	}
   2431 |	begin_type_declaration_specifiers end_type
   2432 	    type_init_declarator_list T_SEMI {
   2433 		if (dcs->d_nonempty_decl)
   2434 			/* '%s' declared in parameter declaration list */
   2435 			warning(3, type_name(dcs->d_type));
   2436 	}
   2437 |	begin_type_declmods error
   2438 |	begin_type_declaration_specifiers error
   2439 ;
   2440 
   2441 /* https://gcc.gnu.org/onlinedocs/gcc/Attribute-Syntax.html */
   2442 gcc_attribute_specifier_list_opt:
   2443 	/* empty */
   2444 |	gcc_attribute_specifier_list
   2445 ;
   2446 
   2447 gcc_attribute_specifier_list:
   2448 	gcc_attribute_specifier
   2449 |	gcc_attribute_specifier_list gcc_attribute_specifier
   2450 ;
   2451 
   2452 gcc_attribute_specifier:
   2453 	T_ATTRIBUTE T_LPAREN T_LPAREN {
   2454 		in_gcc_attribute = true;
   2455 	} gcc_attribute_list {
   2456 		in_gcc_attribute = false;
   2457 	} T_RPAREN T_RPAREN
   2458 ;
   2459 
   2460 gcc_attribute_list:
   2461 	gcc_attribute
   2462 |	gcc_attribute_list T_COMMA gcc_attribute
   2463 ;
   2464 
   2465 gcc_attribute:
   2466 	/* empty */
   2467 |	T_NAME {
   2468 		const char *name = $1->sb_name;
   2469 		if (is_either(name, "packed", "__packed__"))
   2470 			dcs_add_packed();
   2471 		else if (is_either(name, "used", "__used__") ||
   2472 		    is_either(name, "unused", "__unused__"))
   2473 			dcs_set_used();
   2474 		else if (is_either(name, "fallthrough", "__fallthrough__"))
   2475 			suppress_fallthrough = true;
   2476 	}
   2477 |	T_NAME T_LPAREN T_RPAREN
   2478 |	T_NAME T_LPAREN argument_expression_list T_RPAREN {
   2479 		const char *name = $1->sb_name;
   2480 		if (is_either(name, "aligned", "__aligned__")
   2481 		    && $3->args_len == 1)
   2482 			dcs_add_alignas($3->args[0]);
   2483 	}
   2484 |	type_qualifier {
   2485 		if (!$1.tq_const)
   2486 			yyerror("Bad attribute");
   2487 	}
   2488 ;
   2489 
   2490 /* The rule 'function_body' from C23 6.9.2 is inlined into 'function_definition'. */
   2491 
   2492 sys:
   2493 	/* empty */ {
   2494 		$$ = in_system_header;
   2495 	}
   2496 ;
   2497 
   2498 %%
   2499 
   2500 /* ARGSUSED */
   2501 int
   2502 yyerror(const char *msg)
   2503 {
   2504 	/* syntax error '%s' */
   2505 	error(249, yytext);
   2506 	if (++sytxerr >= 5)
   2507 		norecover();
   2508 	return 0;
   2509 }
   2510 
   2511 #if YYDEBUG && YYBYACC
   2512 static const char *
   2513 cgram_to_string(int tok, YYSTYPE val)
   2514 {
   2515 
   2516 	switch (tok) {
   2517 	case T_INCDEC:
   2518 		return val.y_inc ? "++" : "--";
   2519 	case T_MULTIPLICATIVE:
   2520 	case T_ADDITIVE:
   2521 	case T_SHIFT:
   2522 	case T_RELATIONAL:
   2523 	case T_EQUALITY:
   2524 	case T_OPASSIGN:
   2525 		return op_name(val.y_op);
   2526 	case T_SCLASS:
   2527 		return scl_name(val.y_scl);
   2528 	case T_TYPE:
   2529 	case T_STRUCT_OR_UNION:
   2530 		return tspec_name(val.y_tspec);
   2531 	case T_QUAL:
   2532 		return type_qualifiers_string(val.y_type_qualifiers);
   2533 	case T_FUNCTION_SPECIFIER:
   2534 		return function_specifier_name(val.y_function_specifier);
   2535 	case T_NAME:
   2536 		return val.y_name->sb_name;
   2537 	default:
   2538 		return "<none>";
   2539 	}
   2540 }
   2541 #endif
   2542 
   2543 static void
   2544 cgram_declare(sym_t *decl, bool has_initializer, sbuf_t *renaming)
   2545 {
   2546 	declare(decl, has_initializer, renaming);
   2547 	if (renaming != NULL)
   2548 		freeyyv(&renaming, T_NAME);
   2549 }
   2550 
   2551 /*
   2552  * Discard all input tokens up to and including the next unmatched right
   2553  * parenthesis.
   2554  */
   2555 static void
   2556 read_until_rparen(void)
   2557 {
   2558 	int level;
   2559 
   2560 	if (yychar < 0)
   2561 		yychar = yylex();
   2562 	freeyyv(&yylval, yychar);
   2563 
   2564 	level = 1;
   2565 	while (yychar > 0) {
   2566 		if (yychar == T_LPAREN)
   2567 			level++;
   2568 		if (yychar == T_RPAREN && --level == 0)
   2569 			break;
   2570 		freeyyv(&yylval, yychar = yylex());
   2571 	}
   2572 
   2573 	yyclearin;
   2574 }
   2575 
   2576 static balanced_token_sequence
   2577 read_balanced_token_sequence(void)
   2578 {
   2579 	lint_assert(yychar < 0);
   2580 	balanced_token_sequence seq = lex_balanced();
   2581 	yyclearin;
   2582 	return seq;
   2583 }
   2584 
   2585 static sym_t *
   2586 symbolrename(sym_t *s, sbuf_t *sb)
   2587 {
   2588 	if (sb != NULL)
   2589 		s->s_rename = sb->sb_name;
   2590 	return s;
   2591 }
   2592