Module Name: src
Committed By: rillig
Date: Sun Jul 25 18:44:21 UTC 2021
Modified Files:
src/tests/usr.bin/xlint/lint1: gcc_attribute_enum.c
gcc_attribute_enum.exp
src/usr.bin/xlint/lint1: cgram.y
Log Message:
lint: fix parsing of __attribute__ before enum tag
The __attribute__ after the enumerators will be fixed in a follow-up
commit since lint exits after the 5th syntax error in a translation
unit, which up to now shadowed the error messages about the enumerators.
To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/usr.bin/xlint/lint1/gcc_attribute_enum.c \
src/tests/usr.bin/xlint/lint1/gcc_attribute_enum.exp
cvs rdiff -u -r1.340 -r1.341 src/usr.bin/xlint/lint1/cgram.y
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/tests/usr.bin/xlint/lint1/gcc_attribute_enum.c
diff -u src/tests/usr.bin/xlint/lint1/gcc_attribute_enum.c:1.2 src/tests/usr.bin/xlint/lint1/gcc_attribute_enum.c:1.3
--- src/tests/usr.bin/xlint/lint1/gcc_attribute_enum.c:1.2 Sun Jul 25 18:34:44 2021
+++ src/tests/usr.bin/xlint/lint1/gcc_attribute_enum.c Sun Jul 25 18:44:21 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: gcc_attribute_enum.c,v 1.2 2021/07/25 18:34:44 rillig Exp $ */
+/* $NetBSD: gcc_attribute_enum.c,v 1.3 2021/07/25 18:44:21 rillig Exp $ */
# 3 "gcc_attribute_enum.c"
/*
@@ -13,22 +13,15 @@
* See GCC, c-parser.c, function c_parser_enum_specifier.
*/
-/* expect+1: syntax error '__attribute__' [249] */
enum __attribute__(()) tag;
-/* expect+2: syntax error '__attribute__' [249] */
-/* expect+1: syntax error '{' [249] */
enum __attribute__(()) tag_with_declaration {
TAG_WITH_DECL
} __attribute__(());
-/* expect-1: syntax error ';' [249] */
-/* expect+1: syntax error '{' [249] */
enum __attribute__(()) {
ONLY_DECL
} __attribute__(());
-/* expect-1: syntax error ';' [249] */
-/* expect-2: error: cannot recover from previous errors [224] */
/*
* Attributes in enumerator.
@@ -36,12 +29,18 @@ enum __attribute__(()) {
* See GCC, c-parser.c, function c_parser_enum_specifier.
*/
-enum {
+enum without_initializer {
+ /* expect+1: error: syntax error '__attribute__' [249] */
NO_INIT_FIRST __attribute__(()),
NO_INIT__LAST __attribute__(())
};
-enum {
+enum with_initializer {
+ /* expect+1: error: syntax error '__attribute__' [249] */
INIT_FIRST __attribute__(()) = 1,
INIT__LAST __attribute__(()) = 2
};
+
+enum tag {
+ TAG
+};
Index: src/tests/usr.bin/xlint/lint1/gcc_attribute_enum.exp
diff -u src/tests/usr.bin/xlint/lint1/gcc_attribute_enum.exp:1.2 src/tests/usr.bin/xlint/lint1/gcc_attribute_enum.exp:1.3
--- src/tests/usr.bin/xlint/lint1/gcc_attribute_enum.exp:1.2 Sun Jul 25 18:34:44 2021
+++ src/tests/usr.bin/xlint/lint1/gcc_attribute_enum.exp Sun Jul 25 18:44:21 2021
@@ -1,7 +1,2 @@
-gcc_attribute_enum.c(17): error: syntax error '__attribute__' [249]
-gcc_attribute_enum.c(21): error: syntax error '__attribute__' [249]
-gcc_attribute_enum.c(21): error: syntax error '{' [249]
-gcc_attribute_enum.c(23): error: syntax error ';' [249]
-gcc_attribute_enum.c(27): error: syntax error '{' [249]
-gcc_attribute_enum.c(29): error: syntax error ';' [249]
-gcc_attribute_enum.c(29): error: cannot recover from previous errors [224]
+gcc_attribute_enum.c(34): error: syntax error '__attribute__' [249]
+gcc_attribute_enum.c(40): error: syntax error '__attribute__' [249]
Index: src/usr.bin/xlint/lint1/cgram.y
diff -u src/usr.bin/xlint/lint1/cgram.y:1.340 src/usr.bin/xlint/lint1/cgram.y:1.341
--- src/usr.bin/xlint/lint1/cgram.y:1.340 Sun Jul 25 18:01:03 2021
+++ src/usr.bin/xlint/lint1/cgram.y Sun Jul 25 18:44:21 2021
@@ -1,5 +1,5 @@
%{
-/* $NetBSD: cgram.y,v 1.340 2021/07/25 18:01:03 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.341 2021/07/25 18:44:21 rillig Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
@@ -35,7 +35,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: cgram.y,v 1.340 2021/07/25 18:01:03 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.341 2021/07/25 18:44:21 rillig Exp $");
#endif
#include <limits.h>
@@ -1037,18 +1037,18 @@ type_struct_declarator:
;
enum_specifier: /* C99 6.7.2.2 */
- enum identifier_sym {
- $$ = mktag($2, ENUM, false, false);
+ enum gcc_attribute_list_opt identifier_sym {
+ $$ = mktag($3, ENUM, false, false);
}
- | enum identifier_sym {
- dcs->d_tagtyp = mktag($2, ENUM, true, false);
- } enum_declaration {
- $$ = complete_tag_enum(dcs->d_tagtyp, $4);
+ | enum gcc_attribute_list_opt identifier_sym {
+ dcs->d_tagtyp = mktag($3, ENUM, true, false);
+ } enum_declaration /*gcc_attribute_list_opt*/ {
+ $$ = complete_tag_enum(dcs->d_tagtyp, $5);
}
- | enum {
+ | enum gcc_attribute_list_opt {
dcs->d_tagtyp = mktag(NULL, ENUM, true, false);
- } enum_declaration {
- $$ = complete_tag_enum(dcs->d_tagtyp, $3);
+ } enum_declaration /*gcc_attribute_list_opt*/ {
+ $$ = complete_tag_enum(dcs->d_tagtyp, $4);
}
| enum error {
symtyp = FVFT;