Source-Changes-HG archive

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

[src/trunk]: src tests/lint: add test for unrealistic edge cases in declarations



details:   https://anonhg.NetBSD.org/src/rev/840e67581882
branches:  trunk
changeset: 1022212:840e67581882
user:      rillig <rillig%NetBSD.org@localhost>
date:      Fri Jul 09 20:20:03 2021 +0000

description:
tests/lint: add test for unrealistic edge cases in declarations

The example code for triggering these grammar rules looks completely
contrived.  Even if lint had not implemented these cases, hopefully
nobody would have ever noticed.

diffstat:

 distrib/sets/lists/tests/mi            |   4 +-
 tests/usr.bin/xlint/lint1/Makefile     |   4 +-
 tests/usr.bin/xlint/lint1/decl_arg.c   |  93 ++++++++++++++++++++++++++++++++++
 tests/usr.bin/xlint/lint1/decl_arg.exp |  27 +++++++++
 4 files changed, 126 insertions(+), 2 deletions(-)

diffs (164 lines):

diff -r ff9498967225 -r 840e67581882 distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi       Fri Jul 09 20:00:26 2021 +0000
+++ b/distrib/sets/lists/tests/mi       Fri Jul 09 20:20:03 2021 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1080 2021/07/09 05:54:11 yamaguchi Exp $
+# $NetBSD: mi,v 1.1081 2021/07/09 20:20:03 rillig Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -6210,6 +6210,8 @@
 ./usr/tests/usr.bin/xlint/lint1/d_typefun.c                    tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/d_typename_as_var.c            tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/d_zero_sized_arrays.c          tests-usr.bin-tests     compattestfile,atf
+./usr/tests/usr.bin/xlint/lint1/decl_arg.c                     tests-usr.bin-tests     compattestfile,atf
+./usr/tests/usr.bin/xlint/lint1/decl_arg.exp                   tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/decl_struct_member.c           tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/decl_struct_member.exp         tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/emit.c                         tests-usr.bin-tests     compattestfile,atf
diff -r ff9498967225 -r 840e67581882 tests/usr.bin/xlint/lint1/Makefile
--- a/tests/usr.bin/xlint/lint1/Makefile        Fri Jul 09 20:00:26 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/Makefile        Fri Jul 09 20:20:03 2021 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.81 2021/07/08 05:18:49 rillig Exp $
+# $NetBSD: Makefile,v 1.82 2021/07/09 20:20:03 rillig Exp $
 
 NOMAN=         # defined
 MAX_MESSAGE=   345             # see lint1/err.c
@@ -108,6 +108,8 @@
 FILES+=                d_typefun.c
 FILES+=                d_typename_as_var.c
 FILES+=                d_zero_sized_arrays.c
+FILES+=                decl_arg.c
+FILES+=                decl_arg.exp
 FILES+=                decl_struct_member.c
 FILES+=                decl_struct_member.exp
 FILES+=                emit.c
diff -r ff9498967225 -r 840e67581882 tests/usr.bin/xlint/lint1/decl_arg.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/usr.bin/xlint/lint1/decl_arg.c      Fri Jul 09 20:20:03 2021 +0000
@@ -0,0 +1,93 @@
+/*     $NetBSD: decl_arg.c,v 1.1 2021/07/09 20:20:03 rillig Exp $      */
+# 3 "decl_arg.c"
+
+/*
+ * Tests for declarations of function arguments.
+ *
+ * See arg_declaration in cgram.y.
+ */
+
+typedef double number;
+
+void no_args(void);
+void type_unnamed(double );
+void type_named(double arg);
+void typedef_unnamed_prototype(number);
+void typedef_named(number arg);
+
+void type_qualifier(const number);
+void type_qualifier_pointer(const number *const);
+
+/*
+ * Just some unrealistic coverage for the grammar rule 'arg_declaration'.
+ */
+/* expect+6: warning: argument 'an_int' unused in function 'old_style' [231] */
+/* expect+5: warning: argument 'a_const_int' unused in function 'old_style' [231] */
+/* expect+4: warning: argument 'a_number' unused in function 'old_style' [231] */
+/* expect+3: warning: argument 'a_function' unused in function 'old_style' [231] */
+/* expect+2: warning: argument 'a_struct' unused in function 'old_style' [231] */
+extern void
+old_style(an_int, a_const_int, a_number, a_function, a_struct)
+/* expect+2: warning: empty declaration [2] */
+/* expect+1: error: only register valid as formal parameter storage class [9] */
+static;
+/* expect+1: error: syntax error '"' [249] */
+static "error";
+/* expect+1: warning: empty declaration [2] */
+const;
+/* expect+1: error: declared argument undeclared is missing [53] */
+const undeclared;
+/* expect+2: error: declared argument undeclared_initialized is missing [53] */
+/* expect+1: error: cannot initialize parameter: undeclared_initialized [52] */
+const undeclared_initialized = 12345;
+/* expect+1: warning: empty declaration [2] */
+int;
+/* expect+1: warning: 'struct arg_struct' declared in argument declaration list [3] */
+struct arg_struct { int member; };
+/* expect+1: error: cannot initialize parameter: an_int [52] */
+int an_int = 12345;
+const int a_const_int;
+number a_number;
+void (a_function) (number);
+/* expect+1: warning: 'struct a_struct' declared in argument declaration list [3] */
+struct a_struct { int member; } a_struct;
+{
+}
+
+/*
+ * Just some unrealistic coverage for the grammar rule 'notype_direct_decl'.
+ */
+extern int
+cover_notype_direct_decl(arg)
+int arg;
+/* expect+1: error: declared argument name is missing [53] */
+const name;
+/* expect+1: error: declared argument parenthesized_name is missing [53] */
+const (parenthesized_name);
+/* expect+1: error: declared argument array is missing [53] */
+const array[];
+/* expect+1: error: declared argument array_size is missing [53] */
+const array_size[1+1+1];
+/* expect+2: error: declared argument multi_array is missing [53] */
+/* expect+1: error: null dimension [17] */
+const multi_array[][][][][][];
+/* expect+1: error: declared argument function is missing [53] */
+const function(void);
+/* expect+1: error: declared argument prefix_attribute is missing [53] */
+const __attribute__((deprecated)) prefix_attribute;
+/* expect+1: error: declared argument postfix_attribute is missing [53] */
+const postfix_attribute __attribute__((deprecated));
+/* expect+1: error: declared argument infix_attribute is missing [53] */
+const __attribute__((deprecated)) infix_attribute __attribute__((deprecated));
+/* The __attribute__ before the '*' is consumed by some other grammar rule. */
+/* expect+7: error: declared argument pointer_prefix_attribute is missing [53] */
+const
+    __attribute__((deprecated))
+    *
+    __attribute__((deprecated))
+    __attribute__((deprecated))
+    __attribute__((deprecated))
+    pointer_prefix_attribute;
+{
+       return arg;
+}
diff -r ff9498967225 -r 840e67581882 tests/usr.bin/xlint/lint1/decl_arg.exp
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/usr.bin/xlint/lint1/decl_arg.exp    Fri Jul 09 20:20:03 2021 +0000
@@ -0,0 +1,27 @@
+decl_arg.c(33): error: only register valid as formal parameter storage class [9]
+decl_arg.c(33): warning: empty declaration [2]
+decl_arg.c(35): error: syntax error '"' [249]
+decl_arg.c(37): warning: empty declaration [2]
+decl_arg.c(39): error: declared argument undeclared is missing [53]
+decl_arg.c(42): error: declared argument undeclared_initialized is missing [53]
+decl_arg.c(42): error: cannot initialize parameter: undeclared_initialized [52]
+decl_arg.c(44): warning: empty declaration [2]
+decl_arg.c(46): warning: 'struct arg_struct' declared in argument declaration list [3]
+decl_arg.c(48): error: cannot initialize parameter: an_int [52]
+decl_arg.c(53): warning: 'struct a_struct' declared in argument declaration list [3]
+decl_arg.c(30): warning: argument 'an_int' unused in function 'old_style' [231]
+decl_arg.c(30): warning: argument 'a_const_int' unused in function 'old_style' [231]
+decl_arg.c(30): warning: argument 'a_number' unused in function 'old_style' [231]
+decl_arg.c(30): warning: argument 'a_function' unused in function 'old_style' [231]
+decl_arg.c(30): warning: argument 'a_struct' unused in function 'old_style' [231]
+decl_arg.c(64): error: declared argument name is missing [53]
+decl_arg.c(66): error: declared argument parenthesized_name is missing [53]
+decl_arg.c(68): error: declared argument array is missing [53]
+decl_arg.c(70): error: declared argument array_size is missing [53]
+decl_arg.c(73): error: null dimension [17]
+decl_arg.c(73): error: declared argument multi_array is missing [53]
+decl_arg.c(75): error: declared argument function is missing [53]
+decl_arg.c(77): error: declared argument prefix_attribute is missing [53]
+decl_arg.c(79): error: declared argument postfix_attribute is missing [53]
+decl_arg.c(81): error: declared argument infix_attribute is missing [53]
+decl_arg.c(90): error: declared argument pointer_prefix_attribute is missing [53]



Home | Main Index | Thread Index | Old Index