Sun Jul 11 18:22:03 2021 UTC ()
lint: resolve shift/reduce conflict in notype_direct_decl

When a notype_direct_decl was followed by a type_attribute_list, and the
next token was another type_attribute, the parser could either continue
the current type_attribute_list or start a new one.  Either way has the
same effect since type_attribute_list has no associated action.

This reduces the conflicts by 4, one for each of T_ALIGNAS, T_ATTRIBUTE,
T_NORETURN, T_PACKED.  There are several other conflicts involving these
4 tokens, but they are harder to fix.

No functional change.


(rillig)
diff -r1.310 -r1.311 src/usr.bin/xlint/lint1/cgram.y

cvs diff -r1.310 -r1.311 src/usr.bin/xlint/lint1/cgram.y (expand / switch to unified diff)

--- src/usr.bin/xlint/lint1/cgram.y 2021/07/11 18:03:47 1.310
+++ src/usr.bin/xlint/lint1/cgram.y 2021/07/11 18:22:02 1.311
@@ -1,15 +1,15 @@ @@ -1,15 +1,15 @@
1%{ 1%{
2/* $NetBSD: cgram.y,v 1.310 2021/07/11 18:03:47 rillig Exp $ */ 2/* $NetBSD: cgram.y,v 1.311 2021/07/11 18:22:02 rillig Exp $ */
3 3
4/* 4/*
5 * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. 5 * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
6 * Copyright (c) 1994, 1995 Jochen Pohl 6 * Copyright (c) 1994, 1995 Jochen Pohl
7 * All Rights Reserved. 7 * All Rights Reserved.
8 * 8 *
9 * Redistribution and use in source and binary forms, with or without 9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions 10 * modification, are permitted provided that the following conditions
11 * are met: 11 * are met:
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright 14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the 15 * notice, this list of conditions and the following disclaimer in the
@@ -25,27 +25,27 @@ @@ -25,27 +25,27 @@
25 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 25 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
26 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 26 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 27 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
28 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 28 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
29 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 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 30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 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 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. 33 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 */ 34 */
35 35
36#include <sys/cdefs.h> 36#include <sys/cdefs.h>
37#if defined(__RCSID) && !defined(lint) 37#if defined(__RCSID) && !defined(lint)
38__RCSID("$NetBSD: cgram.y,v 1.310 2021/07/11 18:03:47 rillig Exp $"); 38__RCSID("$NetBSD: cgram.y,v 1.311 2021/07/11 18:22:02 rillig Exp $");
39#endif 39#endif
40 40
41#include <limits.h> 41#include <limits.h>
42#include <stdlib.h> 42#include <stdlib.h>
43#include <string.h> 43#include <string.h>
44 44
45#include "lint1.h" 45#include "lint1.h"
46 46
47extern char *yytext; 47extern char *yytext;
48 48
49/* 49/*
50 * Contains the level of current declaration, used for symbol table entries. 50 * Contains the level of current declaration, used for symbol table entries.
51 * 0 is the top-level, > 0 is inside a function body. 51 * 0 is the top-level, > 0 is inside a function body.
@@ -114,27 +114,27 @@ RESTORE_WARN_FLAGS(const char *file, siz @@ -114,27 +114,27 @@ RESTORE_WARN_FLAGS(const char *file, siz
114#define save_warning_flags() SAVE_WARN_FLAGS(__FILE__, __LINE__) 114#define save_warning_flags() SAVE_WARN_FLAGS(__FILE__, __LINE__)
115#define restore_warning_flags() RESTORE_WARN_FLAGS(__FILE__, __LINE__) 115#define restore_warning_flags() RESTORE_WARN_FLAGS(__FILE__, __LINE__)
116 116
117/* unbind the anonymous struct members from the struct */ 117/* unbind the anonymous struct members from the struct */
118static void 118static void
119anonymize(sym_t *s) 119anonymize(sym_t *s)
120{ 120{
121 for ( ; s != NULL; s = s->s_next) 121 for ( ; s != NULL; s = s->s_next)
122 s->s_styp = NULL; 122 s->s_styp = NULL;
123} 123}
124 124
125%} 125%}
126 126
127%expect 172 127%expect 168
128 128
129%union { 129%union {
130 val_t *y_val; 130 val_t *y_val;
131 sbuf_t *y_name; 131 sbuf_t *y_name;
132 sym_t *y_sym; 132 sym_t *y_sym;
133 op_t y_op; 133 op_t y_op;
134 scl_t y_scl; 134 scl_t y_scl;
135 tspec_t y_tspec; 135 tspec_t y_tspec;
136 tqual_t y_tqual; 136 tqual_t y_tqual;
137 type_t *y_type; 137 type_t *y_type;
138 tnode_t *y_tnode; 138 tnode_t *y_tnode;
139 range_t y_range; 139 range_t y_range;
140 strg_t *y_string; 140 strg_t *y_string;
@@ -969,27 +969,27 @@ notype_direct_decl: @@ -969,27 +969,27 @@ notype_direct_decl:
969 $$ = $2; 969 $$ = $2;
970 } 970 }
971 | notype_direct_decl T_LBRACK T_RBRACK { 971 | notype_direct_decl T_LBRACK T_RBRACK {
972 $$ = add_array($1, false, 0); 972 $$ = add_array($1, false, 0);
973 } 973 }
974 | notype_direct_decl T_LBRACK array_size T_RBRACK { 974 | notype_direct_decl T_LBRACK array_size T_RBRACK {
975 $$ = add_array($1, true, to_int_constant($3, false)); 975 $$ = add_array($1, true, to_int_constant($3, false));
976 } 976 }
977 | notype_direct_decl param_list asm_or_symbolrename_opt { 977 | notype_direct_decl param_list asm_or_symbolrename_opt {
978 $$ = add_function(symbolrename($1, $3), $2); 978 $$ = add_function(symbolrename($1, $3), $2);
979 end_declaration_level(); 979 end_declaration_level();
980 block_level--; 980 block_level--;
981 } 981 }
982 | notype_direct_decl type_attribute_list 982 | notype_direct_decl type_attribute
983 ; 983 ;
984 984
985type_direct_decl: 985type_direct_decl:
986 identifier { 986 identifier {
987 $$ = declarator_name(getsym($1)); 987 $$ = declarator_name(getsym($1));
988 } 988 }
989 | T_LPAREN type_decl T_RPAREN { 989 | T_LPAREN type_decl T_RPAREN {
990 $$ = $2; 990 $$ = $2;
991 } 991 }
992 | type_attribute type_direct_decl { 992 | type_attribute type_direct_decl {
993 $$ = $2; 993 $$ = $2;
994 } 994 }
995 | type_direct_decl T_LBRACK T_RBRACK { 995 | type_direct_decl T_LBRACK T_RBRACK {