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