Module Name:    src
Committed By:   rillig
Date:           Fri Jul  9 20:20:03 UTC 2021

Modified Files:
        src/distrib/sets/lists/tests: mi
        src/tests/usr.bin/xlint/lint1: Makefile
Added Files:
        src/tests/usr.bin/xlint/lint1: decl_arg.c decl_arg.exp

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.1080 -r1.1081 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.81 -r1.82 src/tests/usr.bin/xlint/lint1/Makefile
cvs rdiff -u -r0 -r1.1 src/tests/usr.bin/xlint/lint1/decl_arg.c \
    src/tests/usr.bin/xlint/lint1/decl_arg.exp

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.1080 src/distrib/sets/lists/tests/mi:1.1081
--- src/distrib/sets/lists/tests/mi:1.1080	Fri Jul  9 05:54:11 2021
+++ src/distrib/sets/lists/tests/mi	Fri Jul  9 20:20:03 2021
@@ -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

Index: src/tests/usr.bin/xlint/lint1/Makefile
diff -u src/tests/usr.bin/xlint/lint1/Makefile:1.81 src/tests/usr.bin/xlint/lint1/Makefile:1.82
--- src/tests/usr.bin/xlint/lint1/Makefile:1.81	Thu Jul  8 05:18:49 2021
+++ src/tests/usr.bin/xlint/lint1/Makefile	Fri Jul  9 20:20:03 2021
@@ -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_type_question_colon.c
 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

Added files:

Index: src/tests/usr.bin/xlint/lint1/decl_arg.c
diff -u /dev/null src/tests/usr.bin/xlint/lint1/decl_arg.c:1.1
--- /dev/null	Fri Jul  9 20:20:03 2021
+++ src/tests/usr.bin/xlint/lint1/decl_arg.c	Fri Jul  9 20:20:03 2021
@@ -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;
+}
Index: src/tests/usr.bin/xlint/lint1/decl_arg.exp
diff -u /dev/null src/tests/usr.bin/xlint/lint1/decl_arg.exp:1.1
--- /dev/null	Fri Jul  9 20:20:03 2021
+++ src/tests/usr.bin/xlint/lint1/decl_arg.exp	Fri Jul  9 20:20:03 2021
@@ -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]

Reply via email to