Home | History | Annotate | Line # | Download | only in lint1
cgram.y revision 1.378
      1 %{
      2 /* $NetBSD: cgram.y,v 1.378 2021/12/26 18:16:41 christos 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) && !defined(lint)
     38 __RCSID("$NetBSD: cgram.y,v 1.378 2021/12/26 18:16:41 christos 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 arguments 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 int	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 static int olwarn = LWARN_BAD;
     68 
     69 static	void	cgram_declare(sym_t *, bool, sbuf_t *);
     70 static	void	read_until_rparen(void);
     71 static	sym_t	*symbolrename(sym_t *, sbuf_t *);
     72 
     73 
     74 #ifdef DEBUG
     75 static void
     76 CLEAR_WARN_FLAGS(const char *file, size_t line)
     77 {
     78 	debug_step("%s:%zu: clearing flags", file, line);
     79 	clear_warn_flags();
     80 	olwarn = LWARN_BAD;
     81 }
     82 
     83 static void
     84 SAVE_WARN_FLAGS(const char *file, size_t line)
     85 {
     86 	lint_assert(olwarn == LWARN_BAD);
     87 	debug_step("%s:%zu: saving flags %d", file, line, lwarn);
     88 	olwarn = lwarn;
     89 }
     90 
     91 static void
     92 RESTORE_WARN_FLAGS(const char *file, size_t line)
     93 {
     94 	if (olwarn != LWARN_BAD) {
     95 		lwarn = olwarn;
     96 		debug_step("%s:%zu: restoring flags %d", file, line, lwarn);
     97 		olwarn = LWARN_BAD;
     98 	} else
     99 		CLEAR_WARN_FLAGS(file, line);
    100 }
    101 #else
    102 #define CLEAR_WARN_FLAGS(f, l)	clear_warn_flags(), olwarn = LWARN_BAD
    103 #define SAVE_WARN_FLAGS(f, l)	olwarn = lwarn
    104 #define RESTORE_WARN_FLAGS(f, l) \
    105 	(void)(olwarn == LWARN_BAD ? (clear_warn_flags(), 0) : (lwarn = olwarn))
    106 #endif
    107 
    108 #define clear_warning_flags()	CLEAR_WARN_FLAGS(__FILE__, __LINE__)
    109 #define save_warning_flags()	SAVE_WARN_FLAGS(__FILE__, __LINE__)
    110 #define restore_warning_flags()	RESTORE_WARN_FLAGS(__FILE__, __LINE__)
    111 
    112 /* unbind the anonymous struct members from the struct */
    113 static void
    114 anonymize(sym_t *s)
    115 {
    116 	for ( ; s != NULL; s = s->s_next)
    117 		s->s_styp = NULL;
    118 }
    119 
    120 #if defined(YYDEBUG) && (defined(YYBYACC) || defined(YYBISON))
    121 #define YYSTYPE_TOSTRING cgram_to_string
    122 #endif
    123 #if defined(YYDEBUG) && defined(YYBISON)
    124 #define YYPRINT cgram_print
    125 #endif
    126 
    127 %}
    128 
    129 %expect 150
    130 
    131 %union {
    132 	val_t	*y_val;
    133 	sbuf_t	*y_name;
    134 	sym_t	*y_sym;
    135 	op_t	y_op;
    136 	scl_t	y_scl;
    137 	tspec_t	y_tspec;
    138 	tqual_t	y_tqual;
    139 	type_t	*y_type;
    140 	tnode_t	*y_tnode;
    141 	range_t	y_range;
    142 	strg_t	*y_string;
    143 	qual_ptr *y_qual_ptr;
    144 	bool	y_seen_statement;
    145 	struct generic_association *y_generic;
    146 	struct array_size y_array_size;
    147 	bool	y_in_system_header;
    148 };
    149 
    150 %token			T_LBRACE T_RBRACE T_LBRACK T_RBRACK T_LPAREN T_RPAREN
    151 %token			T_POINT T_ARROW
    152 %token			T_COMPLEMENT T_LOGNOT
    153 %token	<y_op>		T_INCDEC
    154 %token			T_SIZEOF
    155 %token			T_BUILTIN_OFFSETOF
    156 %token			T_TYPEOF
    157 %token			T_EXTENSION
    158 %token			T_ALIGNAS
    159 %token			T_ALIGNOF
    160 %token			T_ASTERISK
    161 %token	<y_op>		T_MULTIPLICATIVE
    162 %token	<y_op>		T_ADDITIVE
    163 %token	<y_op>		T_SHIFT
    164 %token	<y_op>		T_RELATIONAL
    165 %token	<y_op>		T_EQUALITY
    166 %token			T_AMPER
    167 %token			T_BITXOR
    168 %token			T_BITOR
    169 %token			T_LOGAND
    170 %token			T_LOGOR
    171 %token			T_QUEST
    172 %token			T_COLON
    173 %token			T_ASSIGN
    174 %token	<y_op>		T_OPASSIGN
    175 %token			T_COMMA
    176 %token			T_SEMI
    177 %token			T_ELLIPSIS
    178 %token			T_REAL
    179 %token			T_IMAG
    180 %token			T_GENERIC
    181 %token			T_NORETURN
    182 
    183 /* storage classes (extern, static, auto, register and typedef) */
    184 %token	<y_scl>		T_SCLASS
    185 
    186 /*
    187  * predefined type keywords (char, int, short, long, unsigned, signed,
    188  * float, double, void); see T_TYPENAME for types from typedef
    189  */
    190 %token	<y_tspec>	T_TYPE
    191 
    192 /* qualifiers (const, volatile, restrict, _Thread_local) */
    193 %token	<y_tqual>	T_QUAL
    194 
    195 /* struct or union */
    196 %token	<y_tspec>	T_STRUCT_OR_UNION
    197 
    198 /* remaining keywords */
    199 %token			T_ASM
    200 %token			T_BREAK
    201 %token			T_CASE
    202 %token			T_CONTINUE
    203 %token			T_DEFAULT
    204 %token			T_DO
    205 %token			T_ELSE
    206 %token			T_ENUM
    207 %token			T_FOR
    208 %token			T_GOTO
    209 %token			T_IF
    210 %token			T_PACKED
    211 %token			T_RETURN
    212 %token			T_SWITCH
    213 %token			T_SYMBOLRENAME
    214 %token			T_WHILE
    215 %token			T_STATIC_ASSERT
    216 
    217 %token			T_ATTRIBUTE
    218 %token			T_AT_ALIAS
    219 %token			T_AT_ALIGNED
    220 %token			T_AT_ALLOC_SIZE
    221 %token			T_AT_ALWAYS_INLINE
    222 %token			T_AT_BOUNDED
    223 %token			T_AT_BUFFER
    224 %token			T_AT_COLD
    225 %token			T_AT_COMMON
    226 %token			T_AT_CONSTRUCTOR
    227 %token			T_AT_DEPRECATED
    228 %token			T_AT_DESTRUCTOR
    229 %token			T_AT_DISABLE_SANITIZER_INSTRUMENTATION
    230 %token			T_AT_FALLTHROUGH
    231 %token			T_AT_FORMAT
    232 %token			T_AT_FORMAT_ARG
    233 %token			T_AT_FORMAT_GNU_PRINTF
    234 %token			T_AT_FORMAT_PRINTF
    235 %token			T_AT_FORMAT_SCANF
    236 %token			T_AT_FORMAT_STRFMON
    237 %token			T_AT_FORMAT_STRFTIME
    238 %token			T_AT_FORMAT_SYSLOG
    239 %token			T_AT_GNU_INLINE
    240 %token			T_AT_HOT
    241 %token			T_AT_MALLOC
    242 %token			T_AT_MAY_ALIAS
    243 %token			T_AT_MINBYTES
    244 %token			T_AT_MODE
    245 %token			T_AT_NO_SANITIZE
    246 %token			T_AT_NO_SANITIZE_THREAD
    247 %token			T_AT_NOINLINE
    248 %token			T_AT_NONNULL
    249 %token			T_AT_NONSTRING
    250 %token			T_AT_NORETURN
    251 %token			T_AT_NOTHROW
    252 %token			T_AT_NO_INSTRUMENT_FUNCTION
    253 %token			T_AT_OPTIMIZE
    254 %token			T_AT_OPTNONE
    255 %token			T_AT_PACKED
    256 %token			T_AT_PCS
    257 %token			T_AT_PURE
    258 %token			T_AT_REGPARM
    259 %token			T_AT_RETURNS_NONNULL
    260 %token			T_AT_RETURNS_TWICE
    261 %token			T_AT_SECTION
    262 %token			T_AT_SENTINEL
    263 %token			T_AT_STRING
    264 %token			T_AT_TARGET
    265 %token			T_AT_TLS_MODEL
    266 %token			T_AT_TUNION
    267 %token			T_AT_UNUSED
    268 %token			T_AT_USED
    269 %token			T_AT_VISIBILITY
    270 %token			T_AT_WARN_UNUSED_RESULT
    271 %token			T_AT_WEAK
    272 
    273 %left	T_THEN
    274 %left	T_ELSE
    275 %right	T_QUEST T_COLON
    276 %left	T_LOGOR
    277 %left	T_LOGAND
    278 %left	T_BITOR
    279 %left	T_BITXOR
    280 %left	T_AMPER
    281 %left	T_EQUALITY
    282 %left	T_RELATIONAL
    283 %left	T_SHIFT
    284 %left	T_ADDITIVE
    285 %left	T_ASTERISK T_MULTIPLICATIVE
    286 
    287 %token	<y_name>	T_NAME
    288 %token	<y_name>	T_TYPENAME
    289 %token	<y_val>		T_CON
    290 %token	<y_string>	T_STRING
    291 
    292 %type	<y_sym>		identifier_sym
    293 %type	<y_name>	identifier
    294 %type	<y_string>	string
    295 %type	<y_string>	string2
    296 
    297 %type	<y_tnode>	primary_expression
    298 %type	<y_tnode>	generic_selection
    299 %type	<y_generic>	generic_assoc_list
    300 %type	<y_generic>	generic_association
    301 %type	<y_tnode>	postfix_expression
    302 %type	<y_tnode>	gcc_statement_expr_list
    303 %type	<y_tnode>	gcc_statement_expr_item
    304 %type	<y_op>		point_or_arrow
    305 %type	<y_tnode>	argument_expression_list
    306 %type	<y_tnode>	unary_expression
    307 %type	<y_tnode>	cast_expression
    308 %type	<y_tnode>	conditional_expression
    309 %type	<y_tnode>	assignment_expression
    310 %type	<y_tnode>	expression_opt
    311 %type	<y_tnode>	expression
    312 %type	<y_tnode>	constant_expr
    313 
    314 %type	<y_type>	begin_type_typespec
    315 %type	<y_type>	type_specifier
    316 %type	<y_type>	notype_type_specifier
    317 %type	<y_type>	struct_or_union_specifier
    318 %type	<y_tspec>	struct_or_union
    319 %type	<y_sym>		braced_struct_declaration_list
    320 %type	<y_sym>		struct_declaration_list_with_rbrace
    321 %type	<y_sym>		struct_declaration_list
    322 %type	<y_sym>		struct_declaration
    323 %type	<y_sym>		notype_struct_declarators
    324 %type	<y_sym>		type_struct_declarators
    325 %type	<y_sym>		notype_struct_declarator
    326 %type	<y_sym>		type_struct_declarator
    327 %type	<y_type>	enum_specifier
    328 %type	<y_sym>		enum_declaration
    329 %type	<y_sym>		enums_with_opt_comma
    330 %type	<y_sym>		enumerator_list
    331 %type	<y_sym>		enumerator
    332 %type	<y_qual_ptr>	type_qualifier
    333 %type	<y_qual_ptr>	pointer
    334 %type	<y_qual_ptr>	asterisk
    335 %type	<y_qual_ptr>	type_qualifier_list_opt
    336 %type	<y_qual_ptr>	type_qualifier_list
    337 %type	<y_sym>		notype_declarator
    338 %type	<y_sym>		type_declarator
    339 %type	<y_sym>		notype_direct_declarator
    340 %type	<y_sym>		type_direct_declarator
    341 %type	<y_sym>		type_param_declarator
    342 %type	<y_sym>		notype_param_declarator
    343 %type	<y_sym>		direct_param_declarator
    344 %type	<y_sym>		direct_notype_param_declarator
    345 %type	<y_sym>		param_list
    346 %type	<y_array_size>	array_size_opt
    347 %type	<y_tnode>	array_size
    348 %type	<y_sym>		identifier_list
    349 %type	<y_type>	type_name
    350 %type	<y_sym>		abstract_declaration
    351 %type	<y_sym>		abstract_declarator
    352 %type	<y_sym>		direct_abstract_declarator
    353 %type	<y_sym>		abstract_decl_param_list
    354 %type	<y_sym>		vararg_parameter_type_list
    355 %type	<y_sym>		parameter_type_list
    356 %type	<y_sym>		parameter_declaration
    357 %type	<y_range>	range
    358 %type	<y_name>	asm_or_symbolrename_opt
    359 
    360 %type	<y_seen_statement> block_item_list
    361 %type	<y_seen_statement> block_item
    362 %type	<y_tnode>	do_while_expr
    363 %type	<y_sym>		func_declarator
    364 %type	<y_in_system_header> sys
    365 
    366 %{
    367 #if defined(YYDEBUG) && defined(YYBISON)
    368 static inline void cgram_print(FILE *, int, YYSTYPE);
    369 #endif
    370 %}
    371 
    372 %%
    373 
    374 program:
    375 	  /* empty */ {
    376 		if (sflag) {
    377 			/* empty translation unit */
    378 			error(272);
    379 		} else if (!tflag) {
    380 			/* empty translation unit */
    381 			warning(272);
    382 		}
    383 	  }
    384 	| translation_unit
    385 	;
    386 
    387 identifier_sym:			/* helper for struct/union/enum */
    388 	  identifier {
    389 		$$ = getsym($1);
    390 	  }
    391 	;
    392 
    393 /* K&R ???, C90 ???, C99 6.4.2.1, C11 ??? */
    394 identifier:
    395 	  T_NAME {
    396 		debug_step("cgram: name '%s'", $1->sb_name);
    397 		$$ = $1;
    398 	  }
    399 	| T_TYPENAME {
    400 		debug_step("cgram: typename '%s'", $1->sb_name);
    401 		$$ = $1;
    402 	  }
    403 	;
    404 
    405 /* see C99 6.4.5, string literals are joined by 5.1.1.2 */
    406 string:
    407 	  T_STRING
    408 	| T_STRING string2 {
    409 		$$ = cat_strings($1, $2);
    410 	  }
    411 	;
    412 
    413 /* see C99 6.4.5, string literals are joined by 5.1.1.2 */
    414 string2:
    415 	  T_STRING {
    416 		if (tflag) {
    417 			/* concatenated strings are illegal in traditional C */
    418 			warning(219);
    419 		}
    420 		$$ = $1;
    421 	  }
    422 	| string2 T_STRING {
    423 		$$ = cat_strings($1, $2);
    424 	  }
    425 	;
    426 
    427 /* K&R 7.1, C90 ???, C99 6.5.1, C11 6.5.1 */
    428 primary_expression:
    429 	  T_NAME {
    430 	  	bool sys_name, sys_next;
    431 		sys_name = in_system_header;
    432 		if (yychar < 0)
    433 			yychar = yylex();
    434 		sys_next = in_system_header;
    435 		in_system_header = sys_name;
    436 		$$ = build_name(getsym($1), yychar == T_LPAREN);
    437 		in_system_header = sys_next;
    438 	  }
    439 	| T_CON {
    440 		$$ = build_constant(gettyp($1->v_tspec), $1);
    441 	  }
    442 	| string {
    443 		$$ = build_string($1);
    444 	  }
    445 	| T_LPAREN expression T_RPAREN {
    446 		if ($2 != NULL)
    447 			$2->tn_parenthesized = true;
    448 		$$ = $2;
    449 	  }
    450 	| generic_selection
    451 	/* GCC primary-expression, see c_parser_postfix_expression */
    452 	| T_BUILTIN_OFFSETOF T_LPAREN type_name T_COMMA identifier T_RPAREN {
    453 		symtyp = FMEMBER;
    454 		$$ = build_offsetof($3, getsym($5));
    455 	  }
    456 	;
    457 
    458 /* K&R ---, C90 ---, C99 ---, C11 6.5.1.1 */
    459 generic_selection:
    460 	  T_GENERIC T_LPAREN assignment_expression T_COMMA
    461 	    generic_assoc_list T_RPAREN {
    462 		/* generic selection requires C11 or later */
    463 		c11ism(345);
    464 		$$ = build_generic_selection($3, $5);
    465 	  }
    466 	;
    467 
    468 /* K&R ---, C90 ---, C99 ---, C11 6.5.1.1 */
    469 generic_assoc_list:
    470 	  generic_association
    471 	| generic_assoc_list T_COMMA generic_association {
    472 		$3->ga_prev = $1;
    473 		$$ = $3;
    474 	  }
    475 	;
    476 
    477 /* K&R ---, C90 ---, C99 ---, C11 6.5.1.1 */
    478 generic_association:
    479 	  type_name T_COLON assignment_expression {
    480 		$$ = getblk(sizeof(*$$));
    481 		$$->ga_arg = $1;
    482 		$$->ga_result = $3;
    483 	  }
    484 	| T_DEFAULT T_COLON assignment_expression {
    485 		$$ = getblk(sizeof(*$$));
    486 		$$->ga_arg = NULL;
    487 		$$->ga_result = $3;
    488 	  }
    489 	;
    490 
    491 /* K&R 7.1, C90 ???, C99 6.5.2, C11 6.5.2 */
    492 postfix_expression:
    493 	  primary_expression
    494 	| postfix_expression T_LBRACK sys expression T_RBRACK {
    495 		$$ = build_unary(INDIR, $3, build_binary($1, PLUS, $3, $4));
    496 	  }
    497 	| postfix_expression T_LPAREN sys T_RPAREN {
    498 		$$ = build_function_call($1, $3, NULL);
    499 	  }
    500 	| postfix_expression T_LPAREN sys argument_expression_list T_RPAREN {
    501 		$$ = build_function_call($1, $3, $4);
    502 	  }
    503 	| postfix_expression point_or_arrow sys T_NAME {
    504 		$$ = build_member_access($1, $2, $3, $4);
    505 	  }
    506 	| postfix_expression T_INCDEC sys {
    507 		$$ = build_unary($2 == INC ? INCAFT : DECAFT, $3, $1);
    508 	  }
    509 	| T_LPAREN type_name T_RPAREN {	/* C99 6.5.2.5 "Compound literals" */
    510 		sym_t *tmp = mktempsym($2);
    511 		begin_initialization(tmp);
    512 		cgram_declare(tmp, true, NULL);
    513 	  } init_lbrace initializer_list comma_opt init_rbrace {
    514 		if (!Sflag)
    515 			 /* compound literals are a C9X/GCC extension */
    516 			 gnuism(319);
    517 		$$ = build_name(*current_initsym(), false);
    518 		end_initialization();
    519 	  }
    520 	| T_LPAREN compound_statement_lbrace gcc_statement_expr_list {
    521 		block_level--;
    522 		mem_block_level--;
    523 		begin_initialization(mktempsym(dup_type($3->tn_type)));
    524 		mem_block_level++;
    525 		block_level++;
    526 		/* ({ }) is a GCC extension */
    527 		gnuism(320);
    528 	  } compound_statement_rbrace T_RPAREN {
    529 		$$ = build_name(*current_initsym(), false);
    530 		end_initialization();
    531 	  }
    532 	;
    533 
    534 comma_opt:			/* helper for 'postfix_expression' */
    535 	  /* empty */
    536 	| T_COMMA
    537 	;
    538 
    539 /*
    540  * The inner part of a GCC statement-expression of the form ({ ... }).
    541  *
    542  * https://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html
    543  */
    544 gcc_statement_expr_list:
    545 	  gcc_statement_expr_item
    546 	| gcc_statement_expr_list gcc_statement_expr_item {
    547 		$$ = $2;
    548 	  }
    549 	;
    550 
    551 gcc_statement_expr_item:
    552 	  declaration_or_error {
    553 		clear_warning_flags();
    554 		$$ = NULL;
    555 	  }
    556 	| non_expr_statement {
    557 		$$ = expr_zalloc_tnode();
    558 		$$->tn_type = gettyp(VOID);
    559 	  }
    560 	| expression T_SEMI {
    561 		if ($1 == NULL) {	/* in case of syntax errors */
    562 			$$ = expr_zalloc_tnode();
    563 			$$->tn_type = gettyp(VOID);
    564 		} else {
    565 			/* XXX: do that only on the last name */
    566 			if ($1->tn_op == NAME)
    567 				$1->tn_sym->s_used = true;
    568 			expr($1, false, false, false, false);
    569 			seen_fallthrough = false;
    570 			$$ = $1;
    571 		}
    572 	  }
    573 	;
    574 
    575 point_or_arrow:			/* helper for 'postfix_expression' */
    576 	  T_POINT {
    577 		symtyp = FMEMBER;
    578 		$$ = POINT;
    579 	  }
    580 	| T_ARROW {
    581 		symtyp = FMEMBER;
    582 		$$ = ARROW;
    583 	  }
    584 	;
    585 
    586 /* K&R 7.1, C90 ???, C99 6.5.2, C11 6.5.2 */
    587 argument_expression_list:
    588 	  assignment_expression {
    589 		$$ = build_function_argument(NULL, $1);
    590 	  }
    591 	| argument_expression_list T_COMMA assignment_expression {
    592 		$$ = build_function_argument($1, $3);
    593 	  }
    594 	;
    595 
    596 /* K&R 7.2, C90 ???, C99 6.5.3, C11 6.5.3 */
    597 unary_expression:
    598 	  postfix_expression
    599 	| T_INCDEC sys unary_expression {
    600 		$$ = build_unary($1 == INC ? INCBEF : DECBEF, $2, $3);
    601 	  }
    602 	| T_AMPER sys cast_expression {
    603 		$$ = build_unary(ADDR, $2, $3);
    604 	  }
    605 	| T_ASTERISK sys cast_expression {
    606 		$$ = build_unary(INDIR, $2, $3);
    607 	  }
    608 	| T_ADDITIVE sys cast_expression {
    609 		if (tflag && $1 == PLUS) {
    610 			/* unary + is illegal in traditional C */
    611 			warning(100);
    612 		}
    613 		$$ = build_unary($1 == PLUS ? UPLUS : UMINUS, $2, $3);
    614 	  }
    615 	| T_COMPLEMENT sys cast_expression {
    616 		$$ = build_unary(COMPL, $2, $3);
    617 	  }
    618 	| T_LOGNOT sys cast_expression {
    619 		$$ = build_unary(NOT, $2, $3);
    620 	  }
    621 	| T_REAL sys cast_expression {	/* GCC c_parser_unary_expression */
    622 		$$ = build_unary(REAL, $2, $3);
    623 	  }
    624 	| T_IMAG sys cast_expression {	/* GCC c_parser_unary_expression */
    625 		$$ = build_unary(IMAG, $2, $3);
    626 	  }
    627 	| T_EXTENSION cast_expression {	/* GCC c_parser_unary_expression */
    628 		$$ = $2;
    629 	  }
    630 	| T_SIZEOF unary_expression {
    631 		$$ = $2 == NULL ? NULL : build_sizeof($2->tn_type);
    632 		if ($$ != NULL)
    633 			check_expr_misc($2,
    634 			    false, false, false, false, false, true);
    635 	  }
    636 	| T_SIZEOF T_LPAREN type_name T_RPAREN {
    637 		$$ = build_sizeof($3);
    638 	  }
    639 	/* K&R ---, C90 ---, C99 ---, C11 6.5.3 */
    640 	| T_ALIGNOF T_LPAREN type_name T_RPAREN {
    641 		/* TODO: c11ism */
    642 		$$ = build_alignof($3);
    643 	  }
    644 	;
    645 
    646 /* The rule 'unary_operator' is inlined into unary_expression. */
    647 
    648 /* K&R 7.2, C90 ???, C99 6.5.4, C11 6.5.4 */
    649 cast_expression:
    650 	  unary_expression
    651 	| T_LPAREN type_name T_RPAREN cast_expression {
    652 		$$ = cast($4, $2);
    653 	  }
    654 	;
    655 
    656 expression_opt:
    657 	  /* empty */ {
    658 		$$ = NULL;
    659 	  }
    660 	| expression
    661 	;
    662 
    663 /* 'conditional_expression' also implements 'multiplicative_expression'. */
    664 /* 'conditional_expression' also implements 'additive_expression'. */
    665 /* 'conditional_expression' also implements 'shift_expression'. */
    666 /* 'conditional_expression' also implements 'relational_expression'. */
    667 /* 'conditional_expression' also implements 'equality_expression'. */
    668 /* 'conditional_expression' also implements 'AND_expression'. */
    669 /* 'conditional_expression' also implements 'exclusive_OR_expression'. */
    670 /* 'conditional_expression' also implements 'inclusive_OR_expression'. */
    671 /* 'conditional_expression' also implements 'logical_AND_expression'. */
    672 /* 'conditional_expression' also implements 'logical_OR_expression'. */
    673 /* K&R ???, C90 ???, C99 6.5.5 to 6.5.15, C11 6.5.5 to 6.5.15 */
    674 conditional_expression:
    675 	  cast_expression
    676 	| conditional_expression T_ASTERISK sys conditional_expression {
    677 		$$ = build_binary($1, MULT, $3, $4);
    678 	  }
    679 	| conditional_expression T_MULTIPLICATIVE sys conditional_expression {
    680 		$$ = build_binary($1, $2, $3, $4);
    681 	  }
    682 	| conditional_expression T_ADDITIVE sys conditional_expression {
    683 		$$ = build_binary($1, $2, $3, $4);
    684 	  }
    685 	| conditional_expression T_SHIFT sys conditional_expression {
    686 		$$ = build_binary($1, $2, $3, $4);
    687 	  }
    688 	| conditional_expression T_RELATIONAL sys conditional_expression {
    689 		$$ = build_binary($1, $2, $3, $4);
    690 	  }
    691 	| conditional_expression T_EQUALITY sys conditional_expression {
    692 		$$ = build_binary($1, $2, $3, $4);
    693 	  }
    694 	| conditional_expression T_AMPER sys conditional_expression {
    695 		$$ = build_binary($1, BITAND, $3, $4);
    696 	  }
    697 	| conditional_expression T_BITXOR sys conditional_expression {
    698 		$$ = build_binary($1, BITXOR, $3, $4);
    699 	  }
    700 	| conditional_expression T_BITOR sys conditional_expression {
    701 		$$ = build_binary($1, BITOR, $3, $4);
    702 	  }
    703 	| conditional_expression T_LOGAND sys conditional_expression {
    704 		$$ = build_binary($1, LOGAND, $3, $4);
    705 	  }
    706 	| conditional_expression T_LOGOR sys conditional_expression {
    707 		$$ = build_binary($1, LOGOR, $3, $4);
    708 	  }
    709 	| conditional_expression T_QUEST sys
    710 	    expression T_COLON sys conditional_expression {
    711 		$$ = build_binary($1, QUEST, $3,
    712 		    build_binary($4, COLON, $6, $7));
    713 	  }
    714 	;
    715 
    716 /* K&R ???, C90 ???, C99 6.5.16, C11 6.5.16 */
    717 assignment_expression:
    718 	  conditional_expression
    719 	| unary_expression T_ASSIGN sys assignment_expression {
    720 		$$ = build_binary($1, ASSIGN, $3, $4);
    721 	  }
    722 	| unary_expression T_OPASSIGN sys assignment_expression {
    723 		$$ = build_binary($1, $2, $3, $4);
    724 	  }
    725 	;
    726 
    727 /* K&R ???, C90 ???, C99 6.5.17, C11 6.5.17 */
    728 expression:
    729 	  assignment_expression
    730 	| expression T_COMMA sys assignment_expression {
    731 		$$ = build_binary($1, COMMA, $3, $4);
    732 	  }
    733 	;
    734 
    735 constant_expr_list_opt:		/* helper for gcc_attribute */
    736 	  /* empty */
    737 	| constant_expr_list
    738 	;
    739 
    740 constant_expr_list:		/* helper for gcc_attribute */
    741 	  constant_expr
    742 	| constant_expr_list T_COMMA constant_expr
    743 	;
    744 
    745 constant_expr:			/* C99 6.6 */
    746 	  conditional_expression
    747 	;
    748 
    749 declaration_or_error:
    750 	  declaration
    751 	| error T_SEMI
    752 	;
    753 
    754 declaration:			/* C99 6.7 */
    755 	  begin_type_declmods end_type T_SEMI {
    756 		if (dcs->d_scl == TYPEDEF) {
    757 			/* typedef declares no type name */
    758 			warning(72);
    759 		} else {
    760 			/* empty declaration */
    761 			warning(2);
    762 		}
    763 	  }
    764 	| begin_type_declmods end_type notype_init_declarators T_SEMI
    765 	/* ^^ There is no check for the missing type-specifier. */
    766 	| begin_type_declaration_specifiers end_type T_SEMI {
    767 		if (dcs->d_scl == TYPEDEF) {
    768 			/* typedef declares no type name */
    769 			warning(72);
    770 		} else if (!dcs->d_nonempty_decl) {
    771 			/* empty declaration */
    772 			warning(2);
    773 		}
    774 	  }
    775 	| begin_type_declaration_specifiers end_type
    776 	    type_init_declarators T_SEMI
    777 	| static_assert_declaration
    778 	;
    779 
    780 begin_type_declaration_specifiers:	/* see C99 6.7 */
    781 	  begin_type_typespec {
    782 		add_type($1);
    783 	  }
    784 	| begin_type_declmods type_specifier {
    785 		add_type($2);
    786 	  }
    787 	| type_attribute begin_type_declaration_specifiers
    788 	| begin_type_declaration_specifiers declmod
    789 	| begin_type_declaration_specifiers notype_type_specifier {
    790 		add_type($2);
    791 	  }
    792 	;
    793 
    794 begin_type_declmods:		/* see C99 6.7 */
    795 	  begin_type T_QUAL {
    796 		add_qualifier($2);
    797 	  }
    798 	| begin_type T_SCLASS {
    799 		add_storage_class($2);
    800 	  }
    801 	| begin_type_declmods declmod
    802 	;
    803 
    804 begin_type_specifier_qualifier_list:	/* see C11 6.7.2.1 */
    805 	  begin_type_specifier_qualifier_list_postfix
    806 	| type_attribute_list begin_type_specifier_qualifier_list_postfix
    807 	;
    808 
    809 begin_type_specifier_qualifier_list_postfix:
    810 	  begin_type_typespec {
    811 		add_type($1);
    812 	  }
    813 	| begin_type_qualifier_list type_specifier {
    814 		add_type($2);
    815 	  }
    816 	| begin_type_specifier_qualifier_list_postfix T_QUAL {
    817 		add_qualifier($2);
    818 	  }
    819 	| begin_type_specifier_qualifier_list_postfix notype_type_specifier {
    820 		add_type($2);
    821 	  }
    822 	| begin_type_specifier_qualifier_list_postfix type_attribute
    823 	;
    824 
    825 begin_type_typespec:
    826 	  begin_type notype_type_specifier {
    827 		$$ = $2;
    828 	  }
    829 	| T_TYPENAME begin_type {
    830 		$$ = getsym($1)->s_type;
    831 	  }
    832 	;
    833 
    834 begin_type_qualifier_list:
    835 	  begin_type T_QUAL {
    836 		add_qualifier($2);
    837 	  }
    838 	| begin_type_qualifier_list T_QUAL {
    839 		add_qualifier($2);
    840 	  }
    841 	;
    842 
    843 declmod:
    844 	  T_QUAL {
    845 		add_qualifier($1);
    846 	  }
    847 	| T_SCLASS {
    848 		add_storage_class($1);
    849 	  }
    850 	| type_attribute_list
    851 	;
    852 
    853 type_attribute_list:
    854 	  type_attribute
    855 	| type_attribute_list type_attribute
    856 	;
    857 
    858 type_attribute_opt:
    859 	  /* empty */
    860 	| type_attribute
    861 	;
    862 
    863 type_attribute:			/* See C11 6.7 declaration-specifiers */
    864 	  gcc_attribute
    865 	| T_ALIGNAS T_LPAREN type_specifier T_RPAREN	/* C11 6.7.5 */
    866 	| T_ALIGNAS T_LPAREN constant_expr T_RPAREN	/* C11 6.7.5 */
    867 	| T_PACKED {
    868 		addpacked();
    869 	  }
    870 	| T_NORETURN
    871 	;
    872 
    873 begin_type:
    874 	  /* empty */ {
    875 		begin_type();
    876 	  }
    877 	;
    878 
    879 end_type:
    880 	  /* empty */ {
    881 		end_type();
    882 	  }
    883 	;
    884 
    885 type_specifier:			/* C99 6.7.2 */
    886 	  notype_type_specifier
    887 	| T_TYPENAME {
    888 		$$ = getsym($1)->s_type;
    889 	  }
    890 	;
    891 
    892 notype_type_specifier:		/* see C99 6.7.2 */
    893 	  T_TYPE {
    894 		$$ = gettyp($1);
    895 	  }
    896 	| T_TYPEOF T_LPAREN expression T_RPAREN {	/* GCC extension */
    897 		$$ = $3->tn_type;
    898 	  }
    899 	| struct_or_union_specifier {
    900 		end_declaration_level();
    901 		$$ = $1;
    902 	  }
    903 	| enum_specifier {
    904 		end_declaration_level();
    905 		$$ = $1;
    906 	  }
    907 	;
    908 
    909 struct_or_union_specifier:	/* C99 6.7.2.1 */
    910 	  struct_or_union identifier_sym {
    911 		/*
    912 		 * STDC requires that "struct a;" always introduces
    913 		 * a new tag if "a" is not declared at current level
    914 		 *
    915 		 * yychar is valid because otherwise the parser would not
    916 		 * have been able to decide if it must shift or reduce
    917 		 */
    918 		$$ = mktag($2, $1, false, yychar == T_SEMI);
    919 	  }
    920 	| struct_or_union identifier_sym {
    921 		dcs->d_tagtyp = mktag($2, $1, true, false);
    922 	  } braced_struct_declaration_list {
    923 		$$ = complete_tag_struct_or_union(dcs->d_tagtyp, $4);
    924 	  }
    925 	| struct_or_union {
    926 		dcs->d_tagtyp = mktag(NULL, $1, true, false);
    927 	  } braced_struct_declaration_list {
    928 		$$ = complete_tag_struct_or_union(dcs->d_tagtyp, $3);
    929 	  }
    930 	| struct_or_union error {
    931 		symtyp = FVFT;
    932 		$$ = gettyp(INT);
    933 	  }
    934 	;
    935 
    936 struct_or_union:		/* C99 6.7.2.1 */
    937 	  T_STRUCT_OR_UNION {
    938 		symtyp = FTAG;
    939 		begin_declaration_level($1 == STRUCT ? MOS : MOU);
    940 		dcs->d_offset = 0;
    941 		dcs->d_sou_align_in_bits = CHAR_SIZE;
    942 		$$ = $1;
    943 	  }
    944 	| struct_or_union type_attribute
    945 	;
    946 
    947 braced_struct_declaration_list:	/* see C99 6.7.2.1 */
    948 	  struct_declaration_lbrace struct_declaration_list_with_rbrace {
    949 		$$ = $2;
    950 	  }
    951 	;
    952 
    953 struct_declaration_lbrace:	/* see C99 6.7.2.1 */
    954 	  T_LBRACE {
    955 		symtyp = FVFT;
    956 	  }
    957 	;
    958 
    959 struct_declaration_list_with_rbrace:	/* see C99 6.7.2.1 */
    960 	  struct_declaration_list T_RBRACE
    961 	| T_RBRACE {
    962 		/* XXX: This is not allowed by any C standard. */
    963 		$$ = NULL;
    964 	  }
    965 	;
    966 
    967 struct_declaration_list:	/* C99 6.7.2.1 */
    968 	  struct_declaration
    969 	| struct_declaration_list struct_declaration {
    970 		$$ = lnklst($1, $2);
    971 	  }
    972 	;
    973 
    974 struct_declaration:		/* C99 6.7.2.1 */
    975 	  begin_type_qualifier_list end_type {
    976 		/* ^^ There is no check for the missing type-specifier. */
    977 		/* too late, i know, but getsym() compensates it */
    978 		symtyp = FMEMBER;
    979 	  } notype_struct_declarators type_attribute_opt T_SEMI {
    980 		symtyp = FVFT;
    981 		$$ = $4;
    982 	  }
    983 	| begin_type_specifier_qualifier_list end_type {
    984 		symtyp = FMEMBER;
    985 	  } type_struct_declarators type_attribute_opt T_SEMI {
    986 		symtyp = FVFT;
    987 		$$ = $4;
    988 	  }
    989 	| begin_type_qualifier_list end_type type_attribute_opt T_SEMI {
    990 		/* syntax error '%s' */
    991 		error(249, "member without type");
    992 		$$ = NULL;
    993 	  }
    994 	| begin_type_specifier_qualifier_list end_type type_attribute_opt
    995 	    T_SEMI {
    996 		symtyp = FVFT;
    997 		if (!Sflag)
    998 			/* anonymous struct/union members is a C9X feature */
    999 			warning(49);
   1000 		if (is_struct_or_union(dcs->d_type->t_tspec)) {
   1001 			$$ = dcs->d_type->t_str->sou_first_member;
   1002 			/* add all the members of the anonymous struct/union */
   1003 			anonymize($$);
   1004 		} else {
   1005 			/* syntax error '%s' */
   1006 			error(249, "unnamed member");
   1007 			$$ = NULL;
   1008 		}
   1009 	  }
   1010 	| static_assert_declaration {
   1011 		$$ = NULL;
   1012 	  }
   1013 	| error T_SEMI {
   1014 		symtyp = FVFT;
   1015 		$$ = NULL;
   1016 	  }
   1017 	;
   1018 
   1019 notype_struct_declarators:
   1020 	  notype_struct_declarator {
   1021 		$$ = declarator_1_struct_union($1);
   1022 	  }
   1023 	| notype_struct_declarators {
   1024 		symtyp = FMEMBER;
   1025 	  } T_COMMA type_struct_declarator {
   1026 		$$ = lnklst($1, declarator_1_struct_union($4));
   1027 	  }
   1028 	;
   1029 
   1030 type_struct_declarators:
   1031 	  type_struct_declarator {
   1032 		$$ = declarator_1_struct_union($1);
   1033 	  }
   1034 	| type_struct_declarators {
   1035 		symtyp = FMEMBER;
   1036 	  } T_COMMA type_struct_declarator {
   1037 		$$ = lnklst($1, declarator_1_struct_union($4));
   1038 	  }
   1039 	;
   1040 
   1041 notype_struct_declarator:
   1042 	  notype_declarator
   1043 	| notype_declarator T_COLON constant_expr {	/* C99 6.7.2.1 */
   1044 		$$ = bitfield($1, to_int_constant($3, true));
   1045 	  }
   1046 	| {
   1047 		symtyp = FVFT;
   1048 	  } T_COLON constant_expr {			/* C99 6.7.2.1 */
   1049 		$$ = bitfield(NULL, to_int_constant($3, true));
   1050 	  }
   1051 	;
   1052 
   1053 type_struct_declarator:
   1054 	  type_declarator
   1055 	| type_declarator T_COLON constant_expr {
   1056 		$$ = bitfield($1, to_int_constant($3, true));
   1057 	  }
   1058 	| {
   1059 		symtyp = FVFT;
   1060 	  } T_COLON constant_expr {
   1061 		$$ = bitfield(NULL, to_int_constant($3, true));
   1062 	  }
   1063 	;
   1064 
   1065 enum_specifier:			/* C99 6.7.2.2 */
   1066 	  enum gcc_attribute_list_opt identifier_sym {
   1067 		$$ = mktag($3, ENUM, false, false);
   1068 	  }
   1069 	| enum gcc_attribute_list_opt identifier_sym {
   1070 		dcs->d_tagtyp = mktag($3, ENUM, true, false);
   1071 	  } enum_declaration /*gcc_attribute_list_opt*/ {
   1072 		$$ = complete_tag_enum(dcs->d_tagtyp, $5);
   1073 	  }
   1074 	| enum gcc_attribute_list_opt {
   1075 		dcs->d_tagtyp = mktag(NULL, ENUM, true, false);
   1076 	  } enum_declaration /*gcc_attribute_list_opt*/ {
   1077 		$$ = complete_tag_enum(dcs->d_tagtyp, $4);
   1078 	  }
   1079 	| enum error {
   1080 		symtyp = FVFT;
   1081 		$$ = gettyp(INT);
   1082 	  }
   1083 	;
   1084 
   1085 enum:				/* helper for C99 6.7.2.2 */
   1086 	  T_ENUM {
   1087 		symtyp = FTAG;
   1088 		begin_declaration_level(CTCONST);
   1089 	  }
   1090 	;
   1091 
   1092 enum_declaration:		/* helper for C99 6.7.2.2 */
   1093 	  enum_decl_lbrace enums_with_opt_comma T_RBRACE {
   1094 		$$ = $2;
   1095 	  }
   1096 	;
   1097 
   1098 enum_decl_lbrace:		/* helper for C99 6.7.2.2 */
   1099 	  T_LBRACE {
   1100 		symtyp = FVFT;
   1101 		enumval = 0;
   1102 	  }
   1103 	;
   1104 
   1105 enums_with_opt_comma:		/* helper for C99 6.7.2.2 */
   1106 	  enumerator_list
   1107 	| enumerator_list T_COMMA {
   1108 		if (sflag) {
   1109 			/* trailing ',' prohibited in enum declaration */
   1110 			error(54);
   1111 		} else {
   1112 			/* trailing ',' prohibited in enum declaration */
   1113 			c99ism(54);
   1114 		}
   1115 		$$ = $1;
   1116 	  }
   1117 	;
   1118 
   1119 enumerator_list:		/* C99 6.7.2.2 */
   1120 	  enumerator
   1121 	| enumerator_list T_COMMA enumerator {
   1122 		$$ = lnklst($1, $3);
   1123 	  }
   1124 	| error {
   1125 		$$ = NULL;
   1126 	  }
   1127 	;
   1128 
   1129 enumerator:			/* C99 6.7.2.2 */
   1130 	  identifier_sym gcc_attribute_list_opt {
   1131 		$$ = enumeration_constant($1, enumval, true);
   1132 	  }
   1133 	| identifier_sym gcc_attribute_list_opt T_ASSIGN constant_expr {
   1134 		$$ = enumeration_constant($1, to_int_constant($4, true),
   1135 		    false);
   1136 	  }
   1137 	;
   1138 
   1139 type_qualifier:			/* C99 6.7.3 */
   1140 	  T_QUAL {
   1141 		$$ = xcalloc(1, sizeof(*$$));
   1142 		if ($1 == CONST)
   1143 			$$->p_const = true;
   1144 		if ($1 == VOLATILE)
   1145 			$$->p_volatile = true;
   1146 	  }
   1147 	;
   1148 
   1149 pointer:			/* C99 6.7.5 */
   1150 	  asterisk type_qualifier_list_opt {
   1151 		$$ = merge_qualified_pointer($1, $2);
   1152 	  }
   1153 	| asterisk type_qualifier_list_opt pointer {
   1154 		$$ = merge_qualified_pointer($1, $2);
   1155 		$$ = merge_qualified_pointer($$, $3);
   1156 	  }
   1157 	;
   1158 
   1159 asterisk:			/* helper for 'pointer' */
   1160 	  T_ASTERISK {
   1161 		$$ = xcalloc(1, sizeof(*$$));
   1162 		$$->p_pointer = true;
   1163 	  }
   1164 	;
   1165 
   1166 type_qualifier_list_opt:	/* see C99 6.7.5 */
   1167 	  /* empty */ {
   1168 		$$ = NULL;
   1169 	  }
   1170 	| type_qualifier_list
   1171 	;
   1172 
   1173 type_qualifier_list:		/* C99 6.7.5 */
   1174 	  type_qualifier
   1175 	| type_qualifier_list type_qualifier {
   1176 		$$ = merge_qualified_pointer($1, $2);
   1177 	  }
   1178 	;
   1179 
   1180 /*
   1181  * For an explanation of 'notype' in the following rules, see
   1182  * https://www.gnu.org/software/bison/manual/bison.html#Semantic-Tokens.
   1183  */
   1184 
   1185 notype_init_declarators:
   1186 	  notype_init_declarator
   1187 	| notype_init_declarators T_COMMA type_init_declarator
   1188 	;
   1189 
   1190 type_init_declarators:
   1191 	  type_init_declarator
   1192 	| type_init_declarators T_COMMA type_init_declarator
   1193 	;
   1194 
   1195 notype_init_declarator:
   1196 	  notype_declarator asm_or_symbolrename_opt {
   1197 		cgram_declare($1, false, $2);
   1198 		check_size($1);
   1199 	  }
   1200 	| notype_declarator asm_or_symbolrename_opt {
   1201 		begin_initialization($1);
   1202 		cgram_declare($1, true, $2);
   1203 	  } T_ASSIGN initializer {
   1204 		check_size($1);
   1205 		end_initialization();
   1206 	  }
   1207 	;
   1208 
   1209 type_init_declarator:
   1210 	  type_declarator asm_or_symbolrename_opt {
   1211 		cgram_declare($1, false, $2);
   1212 		check_size($1);
   1213 	  }
   1214 	| type_declarator asm_or_symbolrename_opt {
   1215 		begin_initialization($1);
   1216 		cgram_declare($1, true, $2);
   1217 	  } T_ASSIGN initializer {
   1218 		check_size($1);
   1219 		end_initialization();
   1220 	  }
   1221 	;
   1222 
   1223 notype_declarator:
   1224 	  notype_direct_declarator
   1225 	| pointer notype_direct_declarator {
   1226 		$$ = add_pointer($2, $1);
   1227 	  }
   1228 	;
   1229 
   1230 type_declarator:
   1231 	  type_direct_declarator
   1232 	| pointer type_direct_declarator {
   1233 		$$ = add_pointer($2, $1);
   1234 	  }
   1235 	;
   1236 
   1237 notype_direct_declarator:
   1238 	  T_NAME {
   1239 		$$ = declarator_name(getsym($1));
   1240 	  }
   1241 	| T_LPAREN type_declarator T_RPAREN {
   1242 		$$ = $2;
   1243 	  }
   1244 	| type_attribute notype_direct_declarator {
   1245 		$$ = $2;
   1246 	  }
   1247 	| notype_direct_declarator T_LBRACK array_size_opt T_RBRACK {
   1248 		$$ = add_array($1, $3.has_dim, $3.dim);
   1249 	  }
   1250 	| notype_direct_declarator param_list asm_or_symbolrename_opt {
   1251 		$$ = add_function(symbolrename($1, $3), $2);
   1252 		end_declaration_level();
   1253 		block_level--;
   1254 	  }
   1255 	| notype_direct_declarator type_attribute
   1256 	;
   1257 
   1258 type_direct_declarator:
   1259 	  identifier {
   1260 		$$ = declarator_name(getsym($1));
   1261 	  }
   1262 	| T_LPAREN type_declarator T_RPAREN {
   1263 		$$ = $2;
   1264 	  }
   1265 	| type_attribute type_direct_declarator {
   1266 		$$ = $2;
   1267 	  }
   1268 	| type_direct_declarator T_LBRACK array_size_opt T_RBRACK {
   1269 		$$ = add_array($1, $3.has_dim, $3.dim);
   1270 	  }
   1271 	| type_direct_declarator param_list asm_or_symbolrename_opt {
   1272 		$$ = add_function(symbolrename($1, $3), $2);
   1273 		end_declaration_level();
   1274 		block_level--;
   1275 	  }
   1276 	| type_direct_declarator type_attribute
   1277 	;
   1278 
   1279 /*
   1280  * The two distinct rules type_param_declarator and notype_param_declarator
   1281  * avoid a conflict in argument lists. A typename enclosed in parentheses is
   1282  * always treated as a typename, not an argument name. For example, after
   1283  * "typedef double a;", the declaration "f(int (a));" is interpreted as
   1284  * "f(int (double));", not "f(int a);".
   1285  */
   1286 type_param_declarator:
   1287 	  direct_param_declarator
   1288 	| pointer direct_param_declarator {
   1289 		$$ = add_pointer($2, $1);
   1290 	  }
   1291 	;
   1292 
   1293 notype_param_declarator:
   1294 	  direct_notype_param_declarator
   1295 	| pointer direct_notype_param_declarator {
   1296 		$$ = add_pointer($2, $1);
   1297 	  }
   1298 	;
   1299 
   1300 direct_param_declarator:
   1301 	  identifier type_attribute_list {
   1302 		$$ = declarator_name(getsym($1));
   1303 	  }
   1304 	| identifier {
   1305 		$$ = declarator_name(getsym($1));
   1306 	  }
   1307 	| T_LPAREN notype_param_declarator T_RPAREN {
   1308 		$$ = $2;
   1309 	  }
   1310 	| direct_param_declarator T_LBRACK array_size_opt T_RBRACK
   1311 	    gcc_attribute_list_opt {
   1312 		$$ = add_array($1, $3.has_dim, $3.dim);
   1313 	  }
   1314 	| direct_param_declarator param_list asm_or_symbolrename_opt {
   1315 		$$ = add_function(symbolrename($1, $3), $2);
   1316 		end_declaration_level();
   1317 		block_level--;
   1318 	  }
   1319 	;
   1320 
   1321 direct_notype_param_declarator:
   1322 	  identifier {
   1323 		$$ = declarator_name(getsym($1));
   1324 	  }
   1325 	| T_LPAREN notype_param_declarator T_RPAREN {
   1326 		$$ = $2;
   1327 	  }
   1328 	| direct_notype_param_declarator T_LBRACK array_size_opt T_RBRACK {
   1329 		$$ = add_array($1, $3.has_dim, $3.dim);
   1330 	  }
   1331 	| direct_notype_param_declarator param_list asm_or_symbolrename_opt {
   1332 		$$ = add_function(symbolrename($1, $3), $2);
   1333 		end_declaration_level();
   1334 		block_level--;
   1335 	  }
   1336 	;
   1337 
   1338 param_list:
   1339 	  id_list_lparen identifier_list T_RPAREN {
   1340 		$$ = $2;
   1341 	  }
   1342 	| abstract_decl_param_list
   1343 	;
   1344 
   1345 id_list_lparen:
   1346 	  T_LPAREN {
   1347 		block_level++;
   1348 		begin_declaration_level(PROTO_ARG);
   1349 	  }
   1350 	;
   1351 
   1352 array_size_opt:
   1353 	  /* empty */ {
   1354 		$$.has_dim = false;
   1355 		$$.dim = 0;
   1356 	  }
   1357 	| T_ASTERISK {
   1358 		/* since C99; variable length array of unspecified size */
   1359 		$$.has_dim = false; /* TODO: maybe change to true */
   1360 		$$.dim = 0;	/* just as a placeholder */
   1361 	  }
   1362 	| array_size {
   1363 		$$.has_dim = true;
   1364 		$$.dim = $1 == NULL ? 0 : to_int_constant($1, false);
   1365 	  }
   1366 	;
   1367 
   1368 array_size:
   1369 	  type_qualifier_list_opt T_SCLASS constant_expr {
   1370 		/* C11 6.7.6.3p7 */
   1371 		if ($2 != STATIC)
   1372 			yyerror("Bad attribute");
   1373 		/* static array size is a C11 extension */
   1374 		c11ism(343);
   1375 		$$ = $3;
   1376 	  }
   1377 	| T_QUAL {
   1378 		/* C11 6.7.6.2 */
   1379 		if ($1 != RESTRICT)
   1380 			yyerror("Bad attribute");
   1381 		$$ = NULL;
   1382 	  }
   1383 	| constant_expr
   1384 	;
   1385 
   1386 identifier_list:		/* C99 6.7.5 */
   1387 	  T_NAME {
   1388 		$$ = old_style_function_name(getsym($1));
   1389 	  }
   1390 	| identifier_list T_COMMA T_NAME {
   1391 		$$ = lnklst($1, old_style_function_name(getsym($3)));
   1392 	  }
   1393 	| identifier_list error
   1394 	;
   1395 
   1396 /* XXX: C99 requires an additional specifier-qualifier-list. */
   1397 type_name:			/* C99 6.7.6 */
   1398 	  {
   1399 		begin_declaration_level(ABSTRACT);
   1400 	  } abstract_declaration {
   1401 		end_declaration_level();
   1402 		$$ = $2->s_type;
   1403 	  }
   1404 	;
   1405 
   1406 abstract_declaration:		/* specific to lint */
   1407 	  begin_type_qualifier_list end_type {
   1408 		$$ = declare_1_abstract(abstract_name());
   1409 	  }
   1410 	| begin_type_specifier_qualifier_list end_type {
   1411 		$$ = declare_1_abstract(abstract_name());
   1412 	  }
   1413 	| begin_type_qualifier_list end_type abstract_declarator {
   1414 		$$ = declare_1_abstract($3);
   1415 	  }
   1416 	| begin_type_specifier_qualifier_list end_type abstract_declarator {
   1417 		$$ = declare_1_abstract($3);
   1418 	  }
   1419 	;
   1420 
   1421 /* K&R 8.7, C90 ???, C99 6.7.6, C11 6.7.7 */
   1422 /* In K&R, abstract-declarator could be empty and was still simpler. */
   1423 abstract_declarator:
   1424 	  pointer {
   1425 		$$ = add_pointer(abstract_name(), $1);
   1426 	  }
   1427 	| direct_abstract_declarator
   1428 	| pointer direct_abstract_declarator {
   1429 		$$ = add_pointer($2, $1);
   1430 	  }
   1431 	;
   1432 
   1433 /* K&R ---, C90 ???, C99 6.7.6, C11 6.7.7 */
   1434 direct_abstract_declarator:
   1435 	/* TODO: sort rules according to C99 */
   1436 	  T_LPAREN abstract_declarator T_RPAREN {
   1437 		$$ = $2;
   1438 	  }
   1439 	| T_LBRACK array_size_opt T_RBRACK {
   1440 		$$ = add_array(abstract_name(), $2.has_dim, $2.dim);
   1441 	  }
   1442 	| type_attribute direct_abstract_declarator {
   1443 		$$ = $2;
   1444 	  }
   1445 	| direct_abstract_declarator T_LBRACK array_size_opt T_RBRACK {
   1446 		$$ = add_array($1, $3.has_dim, $3.dim);
   1447 	  }
   1448 	| abstract_decl_param_list asm_or_symbolrename_opt {
   1449 		$$ = add_function(symbolrename(abstract_name(), $2), $1);
   1450 		end_declaration_level();
   1451 		block_level--;
   1452 	  }
   1453 	| direct_abstract_declarator abstract_decl_param_list
   1454 	    asm_or_symbolrename_opt {
   1455 		$$ = add_function(symbolrename($1, $3), $2);
   1456 		end_declaration_level();
   1457 		block_level--;
   1458 	  }
   1459 	| direct_abstract_declarator type_attribute_list
   1460 	;
   1461 
   1462 abstract_decl_param_list:	/* specific to lint */
   1463 	  abstract_decl_lparen T_RPAREN type_attribute_opt {
   1464 		$$ = NULL;
   1465 	  }
   1466 	| abstract_decl_lparen vararg_parameter_type_list T_RPAREN
   1467 	    type_attribute_opt {
   1468 		dcs->d_proto = true;
   1469 		$$ = $2;
   1470 	  }
   1471 	| abstract_decl_lparen error T_RPAREN type_attribute_opt {
   1472 		$$ = NULL;
   1473 	  }
   1474 	;
   1475 
   1476 abstract_decl_lparen:		/* specific to lint */
   1477 	  T_LPAREN {
   1478 		block_level++;
   1479 		begin_declaration_level(PROTO_ARG);
   1480 	  }
   1481 	;
   1482 
   1483 vararg_parameter_type_list:	/* specific to lint */
   1484 	  parameter_type_list
   1485 	| parameter_type_list T_COMMA T_ELLIPSIS {
   1486 		dcs->d_vararg = true;
   1487 		$$ = $1;
   1488 	  }
   1489 	| T_ELLIPSIS {
   1490 		if (sflag) {
   1491 			/* ANSI C requires formal parameter before '...' */
   1492 			error(84);
   1493 		} else if (!tflag) {
   1494 			/* ANSI C requires formal parameter before '...' */
   1495 			warning(84);
   1496 		}
   1497 		dcs->d_vararg = true;
   1498 		$$ = NULL;
   1499 	  }
   1500 	;
   1501 
   1502 /* XXX: C99 6.7.5 defines the same name, but it looks different. */
   1503 parameter_type_list:
   1504 	  parameter_declaration
   1505 	| parameter_type_list T_COMMA parameter_declaration {
   1506 		$$ = lnklst($1, $3);
   1507 	  }
   1508 	;
   1509 
   1510 /* XXX: C99 6.7.5 defines the same name, but it looks completely different. */
   1511 parameter_declaration:
   1512 	  begin_type_declmods end_type {
   1513 		/* ^^ There is no check for the missing type-specifier. */
   1514 		$$ = declare_argument(abstract_name(), false);
   1515 	  }
   1516 	| begin_type_declaration_specifiers end_type {
   1517 		$$ = declare_argument(abstract_name(), false);
   1518 	  }
   1519 	| begin_type_declmods end_type notype_param_declarator {
   1520 		/* ^^ There is no check for the missing type-specifier. */
   1521 		$$ = declare_argument($3, false);
   1522 	  }
   1523 	/*
   1524 	 * type_param_declarator is needed because of following conflict:
   1525 	 * "typedef int a; f(int (a));" could be parsed as
   1526 	 * "function with argument a of type int", or
   1527 	 * "function with an abstract argument of type function".
   1528 	 * This grammar realizes the second case.
   1529 	 */
   1530 	| begin_type_declaration_specifiers end_type type_param_declarator {
   1531 		$$ = declare_argument($3, false);
   1532 	  }
   1533 	| begin_type_declmods end_type abstract_declarator {
   1534 		/* ^^ There is no check for the missing type-specifier. */
   1535 		$$ = declare_argument($3, false);
   1536 	  }
   1537 	| begin_type_declaration_specifiers end_type abstract_declarator {
   1538 		$$ = declare_argument($3, false);
   1539 	  }
   1540 	;
   1541 
   1542 initializer:			/* C99 6.7.8 "Initialization" */
   1543 	  assignment_expression {
   1544 		init_expr($1);
   1545 	  }
   1546 	| init_lbrace init_rbrace {
   1547 		/* XXX: Empty braces are not covered by C99 6.7.8. */
   1548 	  }
   1549 	| init_lbrace initializer_list comma_opt init_rbrace
   1550 	  /* XXX: What is this error handling for? */
   1551 	| error
   1552 	;
   1553 
   1554 initializer_list:		/* C99 6.7.8 "Initialization" */
   1555 	  initializer_list_item
   1556 	| initializer_list T_COMMA initializer_list_item
   1557 	;
   1558 
   1559 initializer_list_item:		/* helper */
   1560 	  designation initializer
   1561 	| initializer
   1562 	;
   1563 
   1564 designation:			/* C99 6.7.8 "Initialization" */
   1565 	  begin_designation designator_list T_ASSIGN
   1566 	| identifier T_COLON {
   1567 		/* GCC style struct or union member name in initializer */
   1568 		gnuism(315);
   1569 		begin_designation();
   1570 		add_designator_member($1);
   1571 	  }
   1572 	;
   1573 
   1574 begin_designation:		/* lint-specific helper */
   1575 	  /* empty */ {
   1576 		begin_designation();
   1577 	  }
   1578 	;
   1579 
   1580 designator_list:		/* C99 6.7.8 "Initialization" */
   1581 	  designator
   1582 	| designator_list designator
   1583 	;
   1584 
   1585 designator:			/* C99 6.7.8 "Initialization" */
   1586 	  T_LBRACK range T_RBRACK {
   1587 		add_designator_subscript($2);
   1588 		if (!Sflag)
   1589 			/* array initializer with designators is a C9X ... */
   1590 			warning(321);
   1591 	  }
   1592 	| T_POINT identifier {
   1593 		if (!Sflag)
   1594 			/* struct or union member name in initializer is ... */
   1595 			warning(313);
   1596 		add_designator_member($2);
   1597 	  }
   1598 	;
   1599 
   1600 static_assert_declaration:
   1601 	  T_STATIC_ASSERT T_LPAREN constant_expr T_COMMA T_STRING T_RPAREN T_SEMI /* C11 */
   1602 	| T_STATIC_ASSERT T_LPAREN constant_expr T_RPAREN T_SEMI /* C23 */
   1603  	;
   1604 
   1605 range:
   1606 	  constant_expr {
   1607 		$$.lo = to_int_constant($1, true);
   1608 		$$.hi = $$.lo;
   1609 	  }
   1610 	| constant_expr T_ELLIPSIS constant_expr {
   1611 		$$.lo = to_int_constant($1, true);
   1612 		$$.hi = to_int_constant($3, true);
   1613 		/* initialization with '[a...b]' is a GCC extension */
   1614 		gnuism(340);
   1615 	  }
   1616 	;
   1617 
   1618 init_lbrace:			/* helper */
   1619 	  T_LBRACE {
   1620 		init_lbrace();
   1621 	  }
   1622 	;
   1623 
   1624 init_rbrace:			/* helper */
   1625 	  T_RBRACE {
   1626 		init_rbrace();
   1627 	  }
   1628 	;
   1629 
   1630 asm_or_symbolrename_opt:	/* GCC extensions */
   1631 	  /* empty */ {
   1632 		$$ = NULL;
   1633 	  }
   1634 	| T_ASM T_LPAREN T_STRING T_RPAREN gcc_attribute_list_opt {
   1635 		freeyyv(&$3, T_STRING);
   1636 		$$ = NULL;
   1637 	  }
   1638 	| T_SYMBOLRENAME T_LPAREN T_NAME T_RPAREN gcc_attribute_list_opt {
   1639 		$$ = $3;
   1640 	  }
   1641 	;
   1642 
   1643 statement:			/* C99 6.8 */
   1644 	  expression_statement
   1645 	| non_expr_statement
   1646 	;
   1647 
   1648 non_expr_statement:		/* helper for C99 6.8 */
   1649 	  type_attribute T_SEMI
   1650 	| labeled_statement
   1651 	| compound_statement
   1652 	| selection_statement
   1653 	| iteration_statement
   1654 	| jump_statement {
   1655 		seen_fallthrough = false;
   1656 	  }
   1657 	| asm_statement
   1658 	;
   1659 
   1660 labeled_statement:		/* C99 6.8.1 */
   1661 	  label type_attribute_opt statement
   1662 	;
   1663 
   1664 label:
   1665 	  T_NAME T_COLON {
   1666 		symtyp = FLABEL;
   1667 		named_label(getsym($1));
   1668 	  }
   1669 	| T_CASE constant_expr T_COLON {
   1670 		case_label($2);
   1671 		seen_fallthrough = true;
   1672 	  }
   1673 	| T_CASE constant_expr T_ELLIPSIS constant_expr T_COLON {
   1674 		/* XXX: We don't fill all cases */
   1675 		case_label($2);
   1676 		seen_fallthrough = true;
   1677 	  }
   1678 	| T_DEFAULT T_COLON {
   1679 		default_label();
   1680 		seen_fallthrough = true;
   1681 	  }
   1682 	;
   1683 
   1684 compound_statement:		/* C99 6.8.2 */
   1685 	  compound_statement_lbrace compound_statement_rbrace
   1686 	| compound_statement_lbrace block_item_list compound_statement_rbrace
   1687 	;
   1688 
   1689 compound_statement_lbrace:
   1690 	  T_LBRACE {
   1691 		block_level++;
   1692 		mem_block_level++;
   1693 		begin_declaration_level(AUTO);
   1694 	  }
   1695 	;
   1696 
   1697 compound_statement_rbrace:
   1698 	  T_RBRACE {
   1699 		end_declaration_level();
   1700 		freeblk();
   1701 		mem_block_level--;
   1702 		block_level--;
   1703 		seen_fallthrough = false;
   1704 	  }
   1705 	;
   1706 
   1707 block_item_list:		/* C99 6.8.2 */
   1708 	  block_item
   1709 	| block_item_list block_item {
   1710 		if (!Sflag && $1 && !$2)
   1711 			/* declarations after statements is a C99 feature */
   1712 			c99ism(327);
   1713 		$$ = $1 || $2;
   1714 	  }
   1715 	;
   1716 
   1717 block_item:			/* C99 6.8.2 */
   1718 	  declaration_or_error {
   1719 		$$ = false;
   1720 		restore_warning_flags();
   1721 	  }
   1722 	| statement {
   1723 		$$ = true;
   1724 		restore_warning_flags();
   1725 	  }
   1726 	;
   1727 
   1728 expression_statement:		/* C99 6.8.3 */
   1729 	  expression T_SEMI {
   1730 		expr($1, false, false, false, false);
   1731 		seen_fallthrough = false;
   1732 	  }
   1733 	| T_SEMI {
   1734 		seen_fallthrough = false;
   1735 	  }
   1736 	;
   1737 
   1738 selection_statement:		/* C99 6.8.4 */
   1739 	  if_without_else %prec T_THEN {
   1740 		save_warning_flags();
   1741 		if2();
   1742 		if3(false);
   1743 	  }
   1744 	| if_without_else T_ELSE {
   1745 		save_warning_flags();
   1746 		if2();
   1747 	  } statement {
   1748 		clear_warning_flags();
   1749 		if3(true);
   1750 	  }
   1751 	| if_without_else T_ELSE error {
   1752 		clear_warning_flags();
   1753 		if3(false);
   1754 	  }
   1755 	| switch_expr statement {
   1756 		clear_warning_flags();
   1757 		switch2();
   1758 	  }
   1759 	| switch_expr error {
   1760 		clear_warning_flags();
   1761 		switch2();
   1762 	  }
   1763 	;
   1764 
   1765 if_without_else:		/* see C99 6.8.4 */
   1766 	  if_expr statement
   1767 	| if_expr error
   1768 	;
   1769 
   1770 if_expr:			/* see C99 6.8.4 */
   1771 	  T_IF T_LPAREN expression T_RPAREN {
   1772 		if1($3);
   1773 		clear_warning_flags();
   1774 	  }
   1775 	;
   1776 
   1777 switch_expr:			/* see C99 6.8.4 */
   1778 	  T_SWITCH T_LPAREN expression T_RPAREN {
   1779 		switch1($3);
   1780 		clear_warning_flags();
   1781 	  }
   1782 	;
   1783 
   1784 iteration_statement:		/* C99 6.8.5 */
   1785 	  while_expr statement {
   1786 		clear_warning_flags();
   1787 		while2();
   1788 	  }
   1789 	| while_expr error {
   1790 		clear_warning_flags();
   1791 		while2();
   1792 	  }
   1793 	| do_statement do_while_expr {
   1794 		do2($2);
   1795 		seen_fallthrough = false;
   1796 	  }
   1797 	| do error {
   1798 		clear_warning_flags();
   1799 		do2(NULL);
   1800 	  }
   1801 	| for_exprs statement {
   1802 		clear_warning_flags();
   1803 		for2();
   1804 		end_declaration_level();
   1805 		block_level--;
   1806 	  }
   1807 	| for_exprs error {
   1808 		clear_warning_flags();
   1809 		for2();
   1810 		end_declaration_level();
   1811 		block_level--;
   1812 	  }
   1813 	;
   1814 
   1815 while_expr:			/* see C99 6.8.5 */
   1816 	  T_WHILE T_LPAREN expression T_RPAREN {
   1817 		while1($3);
   1818 		clear_warning_flags();
   1819 	  }
   1820 	;
   1821 
   1822 do_statement:			/* see C99 6.8.5 */
   1823 	  do statement {
   1824 		clear_warning_flags();
   1825 	  }
   1826 	;
   1827 
   1828 do:				/* see C99 6.8.5 */
   1829 	  T_DO {
   1830 		do1();
   1831 	  }
   1832 	;
   1833 
   1834 do_while_expr:			/* see C99 6.8.5 */
   1835 	  T_WHILE T_LPAREN expression T_RPAREN T_SEMI {
   1836 		$$ = $3;
   1837 	  }
   1838 	;
   1839 
   1840 for_start:			/* see C99 6.8.5 */
   1841 	  T_FOR T_LPAREN {
   1842 		begin_declaration_level(AUTO);
   1843 		block_level++;
   1844 	  }
   1845 	;
   1846 
   1847 for_exprs:			/* see C99 6.8.5 */
   1848 	  for_start
   1849 	    begin_type_declaration_specifiers end_type
   1850 	    notype_init_declarators T_SEMI
   1851 	    expression_opt T_SEMI expression_opt T_RPAREN {
   1852 		/* variable declaration in for loop */
   1853 		c99ism(325);
   1854 		for1(NULL, $6, $8);
   1855 		clear_warning_flags();
   1856 	    }
   1857 	  | for_start
   1858 	      expression_opt T_SEMI
   1859 	      expression_opt T_SEMI
   1860 	      expression_opt T_RPAREN {
   1861 		for1($2, $4, $6);
   1862 		clear_warning_flags();
   1863 	  }
   1864 	;
   1865 
   1866 jump_statement:			/* C99 6.8.6 */
   1867 	  goto identifier T_SEMI {
   1868 		do_goto(getsym($2));
   1869 	  }
   1870 	| goto error T_SEMI {
   1871 		symtyp = FVFT;
   1872 	  }
   1873 	| T_CONTINUE T_SEMI {
   1874 		do_continue();
   1875 	  }
   1876 	| T_BREAK T_SEMI {
   1877 		do_break();
   1878 	  }
   1879 	| T_RETURN sys T_SEMI {
   1880 		do_return($2, NULL);
   1881 	  }
   1882 	| T_RETURN sys expression T_SEMI {
   1883 		do_return($2, $3);
   1884 	  }
   1885 	;
   1886 
   1887 goto:				/* see C99 6.8.6 */
   1888 	  T_GOTO {
   1889 		symtyp = FLABEL;
   1890 	  }
   1891 	;
   1892 
   1893 asm_statement:			/* GCC extension */
   1894 	  T_ASM T_LPAREN read_until_rparen T_SEMI {
   1895 		setasm();
   1896 	  }
   1897 	| T_ASM T_QUAL T_LPAREN read_until_rparen T_SEMI {
   1898 		setasm();
   1899 	  }
   1900 	| T_ASM error
   1901 	;
   1902 
   1903 read_until_rparen:		/* helper for 'asm_statement' */
   1904 	  /* empty */ {
   1905 		read_until_rparen();
   1906 	  }
   1907 	;
   1908 
   1909 translation_unit:		/* C99 6.9 */
   1910 	  external_declaration
   1911 	| translation_unit external_declaration
   1912 	;
   1913 
   1914 external_declaration:		/* C99 6.9 */
   1915 	  function_definition {
   1916 		global_clean_up_decl(false);
   1917 		clear_warning_flags();
   1918 	  }
   1919 	| top_level_declaration {
   1920 		global_clean_up_decl(false);
   1921 		clear_warning_flags();
   1922 	  }
   1923 	| asm_statement		/* GCC extension */
   1924 	| T_SEMI {		/* GCC extension */
   1925 		if (sflag) {
   1926 			/* empty declaration */
   1927 			error(0);
   1928 		} else if (!tflag) {
   1929 			/* empty declaration */
   1930 			warning(0);
   1931 		}
   1932 	  }
   1933 	;
   1934 
   1935 /*
   1936  * On the top level, lint allows several forms of declarations that it doesn't
   1937  * allow in functions.  For example, a single ';' is an empty declaration and
   1938  * is supported by some compilers, but in a function it would be an empty
   1939  * statement, not a declaration.  This makes a difference in C90 mode, where
   1940  * a statement must not be followed by a declaration.
   1941  *
   1942  * See 'declaration' for all other declarations.
   1943  */
   1944 top_level_declaration:		/* C99 6.9 calls this 'declaration' */
   1945 	  begin_type end_type notype_init_declarators T_SEMI {
   1946 		if (sflag) {
   1947 			/* old style declaration; add 'int' */
   1948 			error(1);
   1949 		} else if (!tflag) {
   1950 			/* old style declaration; add 'int' */
   1951 			warning(1);
   1952 		}
   1953 	  }
   1954 	| declaration
   1955 	| error T_SEMI {
   1956 		global_clean_up();
   1957 	  }
   1958 	| error T_RBRACE {
   1959 		global_clean_up();
   1960 	  }
   1961 	;
   1962 
   1963 function_definition:		/* C99 6.9.1 */
   1964 	  func_declarator {
   1965 		if ($1->s_type->t_tspec != FUNC) {
   1966 			/* syntax error '%s' */
   1967 			error(249, yytext);
   1968 			YYERROR;
   1969 		}
   1970 		if ($1->s_type->t_typedef) {
   1971 			/* ()-less function definition */
   1972 			error(64);
   1973 			YYERROR;
   1974 		}
   1975 		funcdef($1);
   1976 		block_level++;
   1977 		begin_declaration_level(ARG);
   1978 		if (lwarn == LWARN_NONE)
   1979 			$1->s_used = true;
   1980 	  } arg_declaration_list_opt {
   1981 		end_declaration_level();
   1982 		block_level--;
   1983 		check_func_lint_directives();
   1984 		check_func_old_style_arguments();
   1985 		begin_control_statement(CS_FUNCTION_BODY);
   1986 	  } compound_statement {
   1987 		funcend();
   1988 		end_control_statement(CS_FUNCTION_BODY);
   1989 	  }
   1990 	;
   1991 
   1992 func_declarator:
   1993 	  begin_type end_type notype_declarator {
   1994 		/* ^^ There is no check for the missing type-specifier. */
   1995 		$$ = $3;
   1996 	  }
   1997 	| begin_type_declmods end_type notype_declarator {
   1998 		/* ^^ There is no check for the missing type-specifier. */
   1999 		$$ = $3;
   2000 	  }
   2001 	| begin_type_declaration_specifiers end_type type_declarator {
   2002 		$$ = $3;
   2003 	  }
   2004 	;
   2005 
   2006 arg_declaration_list_opt:	/* C99 6.9.1p13 example 1 */
   2007 	  /* empty */
   2008 	| arg_declaration_list
   2009 	;
   2010 
   2011 arg_declaration_list:		/* C99 6.9.1p13 example 1 */
   2012 	  arg_declaration
   2013 	| arg_declaration_list arg_declaration
   2014 	/* XXX or better "arg_declaration error" ? */
   2015 	| error
   2016 	;
   2017 
   2018 /*
   2019  * "arg_declaration" is separated from "declaration" because it
   2020  * needs other error handling.
   2021  */
   2022 arg_declaration:
   2023 	  begin_type_declmods end_type T_SEMI {
   2024 		/* empty declaration */
   2025 		warning(2);
   2026 	  }
   2027 	| begin_type_declmods end_type notype_init_declarators T_SEMI
   2028 	| begin_type_declaration_specifiers end_type T_SEMI {
   2029 		if (!dcs->d_nonempty_decl) {
   2030 			/* empty declaration */
   2031 			warning(2);
   2032 		} else {
   2033 			/* '%s' declared in argument declaration list */
   2034 			warning(3, type_name(dcs->d_type));
   2035 		}
   2036 	  }
   2037 	| begin_type_declaration_specifiers end_type
   2038 	    type_init_declarators T_SEMI {
   2039 		if (dcs->d_nonempty_decl) {
   2040 			/* '%s' declared in argument declaration list */
   2041 			warning(3, type_name(dcs->d_type));
   2042 		}
   2043 	  }
   2044 	| begin_type_declmods error
   2045 	| begin_type_declaration_specifiers error
   2046 	;
   2047 
   2048 gcc_attribute_list_opt:
   2049 	  /* empty */
   2050 	| gcc_attribute_list
   2051 	;
   2052 
   2053 gcc_attribute_list:
   2054 	  gcc_attribute
   2055 	| gcc_attribute_list gcc_attribute
   2056 	;
   2057 
   2058 gcc_attribute:
   2059 	  T_ATTRIBUTE T_LPAREN T_LPAREN {
   2060 	    in_gcc_attribute = true;
   2061 	  } gcc_attribute_spec_list {
   2062 	    in_gcc_attribute = false;
   2063 	  } T_RPAREN T_RPAREN
   2064 	;
   2065 
   2066 gcc_attribute_spec_list:
   2067 	  gcc_attribute_spec
   2068 	| gcc_attribute_spec_list T_COMMA gcc_attribute_spec
   2069 	;
   2070 
   2071 gcc_attribute_spec:
   2072 	  /* empty */
   2073 	| T_AT_ALWAYS_INLINE
   2074 	| T_AT_ALIAS T_LPAREN string T_RPAREN
   2075 	| T_AT_ALIGNED T_LPAREN constant_expr T_RPAREN
   2076 	| T_AT_ALIGNED
   2077 	| T_AT_ALLOC_SIZE T_LPAREN constant_expr T_COMMA constant_expr T_RPAREN
   2078 	| T_AT_ALLOC_SIZE T_LPAREN constant_expr T_RPAREN
   2079 	| T_AT_BOUNDED T_LPAREN gcc_attribute_bounded
   2080 	  T_COMMA constant_expr T_COMMA constant_expr T_RPAREN
   2081 	| T_AT_COLD
   2082 	| T_AT_COMMON
   2083 	| T_AT_CONSTRUCTOR T_LPAREN constant_expr T_RPAREN
   2084 	| T_AT_CONSTRUCTOR
   2085 	| T_AT_DEPRECATED T_LPAREN string T_RPAREN
   2086 	| T_AT_DEPRECATED
   2087 	| T_AT_DESTRUCTOR T_LPAREN constant_expr T_RPAREN
   2088 	| T_AT_DESTRUCTOR
   2089 	| T_AT_DISABLE_SANITIZER_INSTRUMENTATION
   2090 	| T_AT_FALLTHROUGH {
   2091 		fallthru(1);
   2092 	  }
   2093 	| T_AT_FORMAT T_LPAREN gcc_attribute_format T_COMMA
   2094 	    constant_expr T_COMMA constant_expr T_RPAREN
   2095 	| T_AT_FORMAT_ARG T_LPAREN constant_expr T_RPAREN
   2096 	| T_AT_GNU_INLINE
   2097 	| T_AT_HOT
   2098 	| T_AT_MALLOC
   2099 	| T_AT_MAY_ALIAS
   2100 	| T_AT_MODE T_LPAREN T_NAME T_RPAREN
   2101 	| T_AT_NO_SANITIZE T_LPAREN T_NAME T_RPAREN
   2102 	| T_AT_NO_SANITIZE_THREAD
   2103 	| T_AT_NOINLINE
   2104 	| T_AT_NONNULL T_LPAREN constant_expr_list_opt T_RPAREN
   2105 	| T_AT_NONNULL
   2106 	| T_AT_NONSTRING
   2107 	| T_AT_NORETURN
   2108 	| T_AT_NOTHROW
   2109 	| T_AT_NO_INSTRUMENT_FUNCTION
   2110 	| T_AT_OPTIMIZE T_LPAREN string T_RPAREN
   2111 	| T_AT_OPTNONE
   2112 	| T_AT_PACKED {
   2113 		addpacked();
   2114 	  }
   2115 	| T_AT_PCS T_LPAREN string T_RPAREN
   2116 	| T_AT_PURE
   2117 	| T_AT_REGPARM T_LPAREN constant_expr T_RPAREN
   2118 	| T_AT_RETURNS_NONNULL
   2119 	| T_AT_RETURNS_TWICE
   2120 	| T_AT_SECTION T_LPAREN string T_RPAREN
   2121 	| T_AT_SENTINEL T_LPAREN constant_expr T_RPAREN
   2122 	| T_AT_SENTINEL
   2123 	| T_AT_TARGET T_LPAREN string T_RPAREN
   2124 	| T_AT_TLS_MODEL T_LPAREN string T_RPAREN
   2125 	| T_AT_TUNION
   2126 	| T_AT_UNUSED {
   2127 		add_attr_used();
   2128 	  }
   2129 	| T_AT_USED {
   2130 		add_attr_used();
   2131 	  }
   2132 	| T_AT_VISIBILITY T_LPAREN constant_expr T_RPAREN
   2133 	| T_AT_WARN_UNUSED_RESULT
   2134 	| T_AT_WEAK
   2135 	| T_QUAL {
   2136 		if ($1 != CONST)
   2137 			yyerror("Bad attribute");
   2138 	  }
   2139 	;
   2140 
   2141 gcc_attribute_bounded:
   2142 	  T_AT_MINBYTES
   2143 	| T_AT_STRING
   2144 	| T_AT_BUFFER
   2145 	;
   2146 
   2147 gcc_attribute_format:
   2148 	  T_AT_FORMAT_GNU_PRINTF
   2149 	| T_AT_FORMAT_PRINTF
   2150 	| T_AT_FORMAT_SCANF
   2151 	| T_AT_FORMAT_STRFMON
   2152 	| T_AT_FORMAT_STRFTIME
   2153 	| T_AT_FORMAT_SYSLOG
   2154 	;
   2155 
   2156 sys:
   2157 	  /* empty */ {
   2158 		$$ = in_system_header;
   2159 	  }
   2160 	;
   2161 
   2162 %%
   2163 
   2164 /* ARGSUSED */
   2165 int
   2166 yyerror(const char *msg)
   2167 {
   2168 	/* syntax error '%s' */
   2169 	error(249, yytext);
   2170 	if (++sytxerr >= 5)
   2171 		norecover();
   2172 	return 0;
   2173 }
   2174 
   2175 #if (defined(YYDEBUG) && YYDEBUG > 0 && defined(YYBYACC)) \
   2176     || (defined(YYDEBUG) && defined(YYBISON))
   2177 static const char *
   2178 cgram_to_string(int token, YYSTYPE val)
   2179 {
   2180 	static const char *tqual_name[] = {
   2181 		"const", "volatile", "restrict", "_Thread_local"
   2182 	};
   2183 
   2184 	switch (token) {
   2185 	case T_INCDEC:
   2186 	case T_MULTIPLICATIVE:
   2187 	case T_ADDITIVE:
   2188 	case T_SHIFT:
   2189 	case T_RELATIONAL:
   2190 	case T_EQUALITY:
   2191 	case T_OPASSIGN:
   2192 		return modtab[val.y_op].m_name;
   2193 	case T_SCLASS:
   2194 		return scl_name(val.y_scl);
   2195 	case T_TYPE:
   2196 	case T_STRUCT_OR_UNION:
   2197 		return tspec_name(val.y_tspec);
   2198 	case T_QUAL:
   2199 		return tqual_name[val.y_tqual];
   2200 	case T_NAME:
   2201 		return val.y_name->sb_name;
   2202 	default:
   2203 		return "<none>";
   2204 	}
   2205 }
   2206 #endif
   2207 
   2208 #if defined(YYDEBUG) && defined(YYBISON)
   2209 static inline void
   2210 cgram_print(FILE *output, int token, YYSTYPE val)
   2211 {
   2212 	(void)fprintf(output, "%s", cgram_to_string(token, val));
   2213 }
   2214 #endif
   2215 
   2216 static void
   2217 cgram_declare(sym_t *decl, bool initflg, sbuf_t *renaming)
   2218 {
   2219 	declare(decl, initflg, renaming);
   2220 	if (renaming != NULL)
   2221 		freeyyv(&renaming, T_NAME);
   2222 }
   2223 
   2224 /*
   2225  * Discard all input tokens up to and including the next
   2226  * unmatched right paren
   2227  */
   2228 static void
   2229 read_until_rparen(void)
   2230 {
   2231 	int	level;
   2232 
   2233 	if (yychar < 0)
   2234 		yychar = yylex();
   2235 	freeyyv(&yylval, yychar);
   2236 
   2237 	level = 1;
   2238 	while (yychar != T_RPAREN || --level > 0) {
   2239 		if (yychar == T_LPAREN) {
   2240 			level++;
   2241 		} else if (yychar <= 0) {
   2242 			break;
   2243 		}
   2244 		freeyyv(&yylval, yychar = yylex());
   2245 	}
   2246 
   2247 	yyclearin;
   2248 }
   2249 
   2250 static	sym_t *
   2251 symbolrename(sym_t *s, sbuf_t *sb)
   2252 {
   2253 	if (sb != NULL)
   2254 		s->s_rename = sb->sb_name;
   2255 	return s;
   2256 }
   2257