Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/xlint/lint1 lint: fix parsing of __attribute__ befor...



details:   https://anonhg.NetBSD.org/src/rev/1166ab8ed8a3
branches:  trunk
changeset: 984850:1166ab8ed8a3
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Jul 25 18:44:21 2021 +0000

description:
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.

diffstat:

 tests/usr.bin/xlint/lint1/gcc_attribute_enum.c   |  19 +++++++++----------
 tests/usr.bin/xlint/lint1/gcc_attribute_enum.exp |   9 ++-------
 usr.bin/xlint/lint1/cgram.y                      |  22 +++++++++++-----------
 3 files changed, 22 insertions(+), 28 deletions(-)

diffs (113 lines):

diff -r eed5a59def34 -r 1166ab8ed8a3 tests/usr.bin/xlint/lint1/gcc_attribute_enum.c
--- a/tests/usr.bin/xlint/lint1/gcc_attribute_enum.c    Sun Jul 25 18:34:44 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/gcc_attribute_enum.c    Sun Jul 25 18:44:21 2021 +0000
@@ -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 @@
  * 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
+};
diff -r eed5a59def34 -r 1166ab8ed8a3 tests/usr.bin/xlint/lint1/gcc_attribute_enum.exp
--- a/tests/usr.bin/xlint/lint1/gcc_attribute_enum.exp  Sun Jul 25 18:34:44 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/gcc_attribute_enum.exp  Sun Jul 25 18:44:21 2021 +0000
@@ -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]
diff -r eed5a59def34 -r 1166ab8ed8a3 usr.bin/xlint/lint1/cgram.y
--- a/usr.bin/xlint/lint1/cgram.y       Sun Jul 25 18:34:44 2021 +0000
+++ b/usr.bin/xlint/lint1/cgram.y       Sun Jul 25 18:44:21 2021 +0000
@@ -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 @@
        ;
 
 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;



Home | Main Index | Thread Index | Old Index