Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/tests/usr.bin/xlint/lint1 tests/lint: analyze yesterday's bu...
details: https://anonhg.NetBSD.org/src/rev/2da3150b8662
branches: trunk
changeset: 984542:2da3150b8662
user: rillig <rillig%NetBSD.org@localhost>
date: Sun Jul 11 13:32:06 2021 +0000
description:
tests/lint: analyze yesterday's bug for parsing declarations
diffstat:
tests/usr.bin/xlint/lint1/gcc_attribute_var.c | 43 ++++++++++++++++++++++++-
tests/usr.bin/xlint/lint1/gcc_attribute_var.exp | 4 +-
2 files changed, 45 insertions(+), 2 deletions(-)
diffs (65 lines):
diff -r 00959f8ae2a8 -r 2da3150b8662 tests/usr.bin/xlint/lint1/gcc_attribute_var.c
--- a/tests/usr.bin/xlint/lint1/gcc_attribute_var.c Sun Jul 11 13:00:52 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/gcc_attribute_var.c Sun Jul 11 13:32:06 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: gcc_attribute_var.c,v 1.1 2021/07/06 17:33:07 rillig Exp $ */
+/* $NetBSD: gcc_attribute_var.c,v 1.2 2021/07/11 13:32:06 rillig Exp $ */
# 3 "gcc_attribute_var.c"
/*
@@ -23,6 +23,47 @@
int after __attribute__((__deprecated__))
);
+void println(void);
+
+/*
+ * Since cgram.y 1.294 from 2021-07-10, lint did not accept declarations that
+ * started with __attribute__, due to a newly and accidentally introduced
+ * shift/reduce conflict in the grammar.
+ *
+ * A GCC extension allows statement of the form __attribute__((fallthrough)),
+ * thus starting with __attribute__. This is the 'shift' in the conflict.
+ * The 'reduce' in the conflict was begin_type.
+ *
+ * Before cgram 1.294, the gcc_attribute was placed outside the pair of
+ * begin_type/end_type, exactly to resolve this conflict.
+ *
+ * Conceptually, it made sense to put the __attribute__((unused)) between
+ * begin_type and end_type, to make it part of the declaration-specifiers.
+ * This change introduced the hidden conflict though.
+ *
+ * Interestingly, the number of shift/reduce conflicts did not change in
+ * cgram 1.294, the conflicts were just resolved differently than before.
+ *
+ * To prevent this from happening again, make sure that declarations as well
+ * as statements can start with gcc_attribute.
+ */
+void
+ambiguity_for_attribute(void)
+{
+ /*FIXME*//* expect+1: error: syntax error '_Bool' [249] */
+ __attribute__((unused)) _Bool var1;
+
+ switch (1) {
+ case 1:
+ println();
+ /*FIXME*//* expect+1: error: syntax error '_Bool' [249] */
+ __attribute__((unused)) _Bool var2;
+ __attribute__((fallthrough));
+ case 2:
+ println();
+ }
+}
+
/* just to trigger _some_ error, to keep the .exp file */
/* expect+1: error: syntax error 'syntax_error' [249] */
__attribute__((syntax_error));
diff -r 00959f8ae2a8 -r 2da3150b8662 tests/usr.bin/xlint/lint1/gcc_attribute_var.exp
--- a/tests/usr.bin/xlint/lint1/gcc_attribute_var.exp Sun Jul 11 13:00:52 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/gcc_attribute_var.exp Sun Jul 11 13:32:06 2021 +0000
@@ -1,1 +1,3 @@
-gcc_attribute_var.c(28): error: syntax error 'syntax_error' [249]
+gcc_attribute_var.c(54): error: syntax error '_Bool' [249]
+gcc_attribute_var.c(60): error: syntax error '_Bool' [249]
+gcc_attribute_var.c(69): error: syntax error 'syntax_error' [249]
Home |
Main Index |
Thread Index |
Old Index