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: revert resolving grammar conflicts...



details:   https://anonhg.NetBSD.org/src/rev/c7118fb8b87a
branches:  trunk
changeset: 365851:c7118fb8b87a
user:      rillig <rillig%NetBSD.org@localhost>
date:      Thu Apr 28 21:38:38 2022 +0000

description:
lint: revert resolving grammar conflicts for labeled statements

Restore the grammar rule for labeled_statement as it was before cgram.y
1.400 from 2022-04-24.  This allows labels with attributes again.  Fix
the wrong interpretation in the tests; the attributes belong to the
label, not to the statement.

Today in the morning, when I thought that the change in cgram.y 1.400
were innocent, I accidentally ran lint only with the options '-Sw' but
forgot the option '-g' for GNU mode.  Without that option, the token
'__attribute__' is unknown, which unsurprisingly leads to lots of syntax
errors, and these didn't change with that commit.  The actual change was
only visible in GNU mode.

diffstat:

 distrib/sets/lists/tests/mi                       |   4 +-
 tests/usr.bin/xlint/lint1/Makefile                |   3 +-
 tests/usr.bin/xlint/lint1/gcc_attribute_label.c   |  26 ++++++++++++++++++++++-
 tests/usr.bin/xlint/lint1/gcc_attribute_label.exp |   1 +
 tests/usr.bin/xlint/lint1/gcc_attribute_stmt.c    |  23 +-------------------
 tests/usr.bin/xlint/lint1/gcc_attribute_stmt.exp  |   2 -
 usr.bin/xlint/lint1/cgram.y                       |   8 +++---
 7 files changed, 35 insertions(+), 32 deletions(-)

diffs (155 lines):

diff -r e39582a95985 -r c7118fb8b87a distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi       Thu Apr 28 17:28:15 2022 +0000
+++ b/distrib/sets/lists/tests/mi       Thu Apr 28 21:38:38 2022 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1199 2022/04/26 22:48:53 blymn Exp $
+# $NetBSD: mi,v 1.1200 2022/04/28 21:38:38 rillig Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -6505,7 +6505,7 @@
 ./usr/tests/usr.bin/xlint/lint1/gcc_attribute_func.c           tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/gcc_attribute_func.exp         tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/gcc_attribute_label.c          tests-usr.bin-tests     compattestfile,atf
-./usr/tests/usr.bin/xlint/lint1/gcc_attribute_label.exp                tests-obsolete          obsolete
+./usr/tests/usr.bin/xlint/lint1/gcc_attribute_label.exp                tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/gcc_attribute_stmt.c           tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/gcc_attribute_stmt.exp         tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/gcc_attribute_type.c           tests-usr.bin-tests     compattestfile,atf
diff -r e39582a95985 -r c7118fb8b87a tests/usr.bin/xlint/lint1/Makefile
--- a/tests/usr.bin/xlint/lint1/Makefile        Thu Apr 28 17:28:15 2022 +0000
+++ b/tests/usr.bin/xlint/lint1/Makefile        Thu Apr 28 21:38:38 2022 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.120 2022/04/16 20:18:52 rillig Exp $
+# $NetBSD: Makefile,v 1.121 2022/04/28 21:38:38 rillig Exp $
 
 NOMAN=         # defined
 MAX_MESSAGE=   348             # see lint1/err.c
@@ -165,6 +165,7 @@
 FILES+=                gcc_attribute_func.c
 FILES+=                gcc_attribute_func.exp
 FILES+=                gcc_attribute_label.c
+FILES+=                gcc_attribute_label.exp
 FILES+=                gcc_attribute_stmt.c
 FILES+=                gcc_attribute_stmt.exp
 FILES+=                gcc_attribute_type.c
diff -r e39582a95985 -r c7118fb8b87a tests/usr.bin/xlint/lint1/gcc_attribute_label.c
--- a/tests/usr.bin/xlint/lint1/gcc_attribute_label.c   Thu Apr 28 17:28:15 2022 +0000
+++ b/tests/usr.bin/xlint/lint1/gcc_attribute_label.c   Thu Apr 28 21:38:38 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: gcc_attribute_label.c,v 1.2 2021/07/11 19:24:42 rillig Exp $   */
+/*     $NetBSD: gcc_attribute_label.c,v 1.3 2022/04/28 21:38:38 rillig Exp $   */
 # 3 "gcc_attribute_label.c"
 
 /*
@@ -23,3 +23,27 @@
        if (i < 0)
                goto error;
 }
+
+/* GCC allows a label to be marked as (possibly) unused. */
+void
+unused_labels(int x)
+{
+       switch (x) {
+       case 3:
+               __attribute__((__unused__))
+               break;
+       case 4:
+               goto label;
+       label:
+               __attribute__((__unused__))
+               return;
+       }
+
+       /*
+        * The GCC attributes may only occur after a label; they cannot occur
+        * before an arbitrary statement.
+        */
+       __attribute__((__unused__))
+       /* expect+1: error: syntax error 'return' [249] */
+       return;
+}
diff -r e39582a95985 -r c7118fb8b87a tests/usr.bin/xlint/lint1/gcc_attribute_label.exp
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/usr.bin/xlint/lint1/gcc_attribute_label.exp Thu Apr 28 21:38:38 2022 +0000
@@ -0,0 +1,1 @@
+gcc_attribute_label.c(48): error: syntax error 'return' [249]
diff -r e39582a95985 -r c7118fb8b87a tests/usr.bin/xlint/lint1/gcc_attribute_stmt.c
--- a/tests/usr.bin/xlint/lint1/gcc_attribute_stmt.c    Thu Apr 28 17:28:15 2022 +0000
+++ b/tests/usr.bin/xlint/lint1/gcc_attribute_stmt.c    Thu Apr 28 21:38:38 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: gcc_attribute_stmt.c,v 1.2 2022/04/28 07:10:39 rillig Exp $    */
+/*     $NetBSD: gcc_attribute_stmt.c,v 1.3 2022/04/28 21:38:38 rillig Exp $    */
 # 3 "gcc_attribute_stmt.c"
 
 /*
@@ -34,24 +34,3 @@
                    __attribute__((__fallthrough__));
        }
 }
-
-/*
- * Despite being undocumented, GCC 10 accepts __attribute__((__unused__))
- * at the beginning of a statement.
- */
-void
-unused_statements(int x)
-{
-       switch (x) {
-       case 3:
-               __attribute__((__unused__))
-               /* expect+1: error: syntax error 'break' [249] */
-               break;
-       case 4:
-               goto label;
-       label:
-               __attribute__((__unused__))
-               /* expect+1: error: syntax error 'return' [249] */
-               return;
-       }
-}
diff -r e39582a95985 -r c7118fb8b87a tests/usr.bin/xlint/lint1/gcc_attribute_stmt.exp
--- a/tests/usr.bin/xlint/lint1/gcc_attribute_stmt.exp  Thu Apr 28 17:28:15 2022 +0000
+++ b/tests/usr.bin/xlint/lint1/gcc_attribute_stmt.exp  Thu Apr 28 21:38:38 2022 +0000
@@ -1,3 +1,1 @@
 gcc_attribute_stmt.c(34): error: syntax error '__attribute__' [249]
-gcc_attribute_stmt.c(49): error: syntax error 'break' [249]
-gcc_attribute_stmt.c(55): error: syntax error 'return' [249]
diff -r e39582a95985 -r c7118fb8b87a usr.bin/xlint/lint1/cgram.y
--- a/usr.bin/xlint/lint1/cgram.y       Thu Apr 28 17:28:15 2022 +0000
+++ b/usr.bin/xlint/lint1/cgram.y       Thu Apr 28 21:38:38 2022 +0000
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.402 2022/04/24 20:08:22 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.403 2022/04/28 21:38:38 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.402 2022/04/24 20:08:22 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.403 2022/04/28 21:38:38 rillig Exp $");
 #endif
 
 #include <limits.h>
@@ -126,7 +126,7 @@
 
 %}
 
-%expect 128
+%expect 132
 
 %union {
        val_t   *y_val;
@@ -1655,7 +1655,7 @@
        ;
 
 labeled_statement:             /* C99 6.8.1 */
-         label statement
+         label type_attribute_opt statement
        ;
 
 label:



Home | Main Index | Thread Index | Old Index