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