Module Name: src
Committed By: rillig
Date: Thu Apr 28 21:38:38 UTC 2022
Modified Files:
src/distrib/sets/lists/tests: mi
src/tests/usr.bin/xlint/lint1: Makefile gcc_attribute_label.c
gcc_attribute_stmt.c gcc_attribute_stmt.exp
src/usr.bin/xlint/lint1: cgram.y
Added Files:
src/tests/usr.bin/xlint/lint1: gcc_attribute_label.exp
Log Message:
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.
To generate a diff of this commit:
cvs rdiff -u -r1.1199 -r1.1200 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.120 -r1.121 src/tests/usr.bin/xlint/lint1/Makefile
cvs rdiff -u -r1.2 -r1.3 src/tests/usr.bin/xlint/lint1/gcc_attribute_label.c \
src/tests/usr.bin/xlint/lint1/gcc_attribute_stmt.c \
src/tests/usr.bin/xlint/lint1/gcc_attribute_stmt.exp
cvs rdiff -u -r0 -r1.3 src/tests/usr.bin/xlint/lint1/gcc_attribute_label.exp
cvs rdiff -u -r1.402 -r1.403 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/distrib/sets/lists/tests/mi
diff -u src/distrib/sets/lists/tests/mi:1.1199 src/distrib/sets/lists/tests/mi:1.1200
--- src/distrib/sets/lists/tests/mi:1.1199 Tue Apr 26 22:48:53 2022
+++ src/distrib/sets/lists/tests/mi Thu Apr 28 21:38:38 2022
@@ -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
Index: src/tests/usr.bin/xlint/lint1/Makefile
diff -u src/tests/usr.bin/xlint/lint1/Makefile:1.120 src/tests/usr.bin/xlint/lint1/Makefile:1.121
--- src/tests/usr.bin/xlint/lint1/Makefile:1.120 Sat Apr 16 20:18:52 2022
+++ src/tests/usr.bin/xlint/lint1/Makefile Thu Apr 28 21:38:38 2022
@@ -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_enum.exp
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
Index: src/tests/usr.bin/xlint/lint1/gcc_attribute_label.c
diff -u src/tests/usr.bin/xlint/lint1/gcc_attribute_label.c:1.2 src/tests/usr.bin/xlint/lint1/gcc_attribute_label.c:1.3
--- src/tests/usr.bin/xlint/lint1/gcc_attribute_label.c:1.2 Sun Jul 11 19:24:42 2021
+++ src/tests/usr.bin/xlint/lint1/gcc_attribute_label.c Thu Apr 28 21:38:38 2022
@@ -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 @@ hot:
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;
+}
Index: src/tests/usr.bin/xlint/lint1/gcc_attribute_stmt.c
diff -u src/tests/usr.bin/xlint/lint1/gcc_attribute_stmt.c:1.2 src/tests/usr.bin/xlint/lint1/gcc_attribute_stmt.c:1.3
--- src/tests/usr.bin/xlint/lint1/gcc_attribute_stmt.c:1.2 Thu Apr 28 07:10:39 2022
+++ src/tests/usr.bin/xlint/lint1/gcc_attribute_stmt.c Thu Apr 28 21:38:38 2022
@@ -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(int i)
__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;
- }
-}
Index: src/tests/usr.bin/xlint/lint1/gcc_attribute_stmt.exp
diff -u src/tests/usr.bin/xlint/lint1/gcc_attribute_stmt.exp:1.2 src/tests/usr.bin/xlint/lint1/gcc_attribute_stmt.exp:1.3
--- src/tests/usr.bin/xlint/lint1/gcc_attribute_stmt.exp:1.2 Thu Apr 28 07:10:39 2022
+++ src/tests/usr.bin/xlint/lint1/gcc_attribute_stmt.exp Thu Apr 28 21:38:38 2022
@@ -1,3 +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]
Index: src/usr.bin/xlint/lint1/cgram.y
diff -u src/usr.bin/xlint/lint1/cgram.y:1.402 src/usr.bin/xlint/lint1/cgram.y:1.403
--- src/usr.bin/xlint/lint1/cgram.y:1.402 Sun Apr 24 20:08:22 2022
+++ src/usr.bin/xlint/lint1/cgram.y Thu Apr 28 21:38:38 2022
@@ -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 @@ anonymize(sym_t *s)
%}
-%expect 128
+%expect 132
%union {
val_t *y_val;
@@ -1655,7 +1655,7 @@ non_expr_statement: /* helper for C99 6
;
labeled_statement: /* C99 6.8.1 */
- label statement
+ label type_attribute_opt statement
;
label:
Added files:
Index: src/tests/usr.bin/xlint/lint1/gcc_attribute_label.exp
diff -u /dev/null src/tests/usr.bin/xlint/lint1/gcc_attribute_label.exp:1.3
--- /dev/null Thu Apr 28 21:38:38 2022
+++ src/tests/usr.bin/xlint/lint1/gcc_attribute_label.exp Thu Apr 28 21:38:38 2022
@@ -0,0 +1 @@
+gcc_attribute_label.c(48): error: syntax error 'return' [249]