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