Sat Jul 10 22:46:02 2021 UTC ()
lint: fix parsing of __attribute__ for member (since 2021-07-10)

Since cgram.y 1.280 from 2021-07-10, lint could not parse struct members
that have multiple __attribute__ in front of their type.


(rillig)
diff -r1.4 -r1.5 src/tests/usr.bin/xlint/lint1/decl_struct_member.c
diff -r1.3 -r1.4 src/tests/usr.bin/xlint/lint1/decl_struct_member.exp
diff -r1.304 -r1.305 src/usr.bin/xlint/lint1/cgram.y

cvs diff -r1.4 -r1.5 src/tests/usr.bin/xlint/lint1/decl_struct_member.c (expand / switch to unified diff)

--- src/tests/usr.bin/xlint/lint1/decl_struct_member.c 2021/07/10 22:34:02 1.4
+++ src/tests/usr.bin/xlint/lint1/decl_struct_member.c 2021/07/10 22:46:02 1.5
@@ -1,19 +1,18 @@ @@ -1,19 +1,18 @@
1/* $NetBSD: decl_struct_member.c,v 1.4 2021/07/10 22:34:02 rillig Exp $ */ 1/* $NetBSD: decl_struct_member.c,v 1.5 2021/07/10 22:46:02 rillig Exp $ */
2# 3 "decl_struct_member.c" 2# 3 "decl_struct_member.c"
3 3
4struct multi_attributes { 4struct multi_attributes {
5 __attribute__((deprecated)) 5 __attribute__((deprecated))
6 /* expect+1: error: syntax error '__attribute__' [249] */ 
7 __attribute__((deprecated)) 6 __attribute__((deprecated))
8 __attribute__((deprecated)) 7 __attribute__((deprecated))
9 int deprecated; 8 int deprecated;
10}; 9};
11 10
12/* 11/*
13 * Before cgram.y 1.228 from 2021-06-19, lint ran into an assertion failure: 12 * Before cgram.y 1.228 from 2021-06-19, lint ran into an assertion failure:
14 * 13 *
15 * "is_struct_or_union(dcs->d_type->t_tspec)" at cgram.y:846 14 * "is_struct_or_union(dcs->d_type->t_tspec)" at cgram.y:846
16 */ 15 */
17struct { 16struct {
18 char; /* expect: syntax error 'unnamed member' */ 17 char; /* expect: syntax error 'unnamed member' */
19}; 18};

cvs diff -r1.3 -r1.4 src/tests/usr.bin/xlint/lint1/Attic/decl_struct_member.exp (expand / switch to unified diff)

--- src/tests/usr.bin/xlint/lint1/Attic/decl_struct_member.exp 2021/07/10 22:34:02 1.3
+++ src/tests/usr.bin/xlint/lint1/Attic/decl_struct_member.exp 2021/07/10 22:46:02 1.4
@@ -1,5 +1,4 @@ @@ -1,5 +1,4 @@
1decl_struct_member.c(7): error: syntax error '__attribute__' [249] 1decl_struct_member.c(17): error: syntax error 'unnamed member' [249]
2decl_struct_member.c(18): error: syntax error 'unnamed member' [249] 2decl_struct_member.c(24): error: syntax error '0' [249]
3decl_struct_member.c(25): error: syntax error '0' [249] 3decl_struct_member.c(25): warning: syntax requires ';' after last struct/union member [66]
4decl_struct_member.c(26): warning: syntax requires ';' after last struct/union member [66] 4decl_struct_member.c(32): error: cannot recover from previous errors [224]
5decl_struct_member.c(33): error: cannot recover from previous errors [224] 

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

--- src/usr.bin/xlint/lint1/cgram.y 2021/07/10 21:44:51 1.304
+++ src/usr.bin/xlint/lint1/cgram.y 2021/07/10 22:46:02 1.305
@@ -1,15 +1,15 @@ @@ -1,15 +1,15 @@
1%{ 1%{
2/* $NetBSD: cgram.y,v 1.304 2021/07/10 21:44:51 rillig Exp $ */ 2/* $NetBSD: cgram.y,v 1.305 2021/07/10 22:46: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.304 2021/07/10 21:44:51 rillig Exp $"); 38__RCSID("$NetBSD: cgram.y,v 1.305 2021/07/10 22:46: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 136 127%expect 131
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;
@@ -705,27 +705,27 @@ struct_declaration: @@ -705,27 +705,27 @@ struct_declaration:
705 /* syntax error '%s' */ 705 /* syntax error '%s' */
706 error(249, "unnamed member"); 706 error(249, "unnamed member");
707 $$ = NULL; 707 $$ = NULL;
708 } 708 }
709 } 709 }
710 | error { 710 | error {
711 symtyp = FVFT; 711 symtyp = FVFT;
712 $$ = NULL; 712 $$ = NULL;
713 } 713 }
714 ; 714 ;
715 715
716noclass_declspecs: 716noclass_declspecs:
717 noclass_declspecs_postfix 717 noclass_declspecs_postfix
718 | type_attribute noclass_declspecs_postfix 718 | type_attribute noclass_declspecs
719 ; 719 ;
720 720
721noclass_declspecs_postfix: 721noclass_declspecs_postfix:
722 add_type_specifier 722 add_type_specifier
723 | add_type_qualifier_list add_type_specifier 723 | add_type_qualifier_list add_type_specifier
724 | noclass_declspecs_postfix add_type_qualifier 724 | noclass_declspecs_postfix add_type_qualifier
725 | noclass_declspecs_postfix add_notype_type_specifier 725 | noclass_declspecs_postfix add_notype_type_specifier
726 | noclass_declspecs_postfix type_attribute 726 | noclass_declspecs_postfix type_attribute
727 ; 727 ;
728 728
729add_type_qualifier_list: 729add_type_qualifier_list:
730 add_type_qualifier 730 add_type_qualifier
731 | add_type_qualifier_list add_type_qualifier 731 | add_type_qualifier_list add_type_qualifier