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