From ae95f90ee95815e88927b963b34b0d958da84a98 Mon Sep 17 00:00:00 2001 From: rillig Date: Thu, 15 Jul 2021 21:00:05 +0000 Subject: [PATCH] tests/lint: cover more edge cases in the parser --- distrib/sets/lists/tests/mi | 6 +++++- tests/usr.bin/xlint/lint1/Makefile | 6 +++++- tests/usr.bin/xlint/lint1/decl.c | 5 ++++- tests/usr.bin/xlint/lint1/decl_enum.c | 19 +++++++++++++++++++ tests/usr.bin/xlint/lint1/decl_enum.exp | 3 +++ tests/usr.bin/xlint/lint1/decl_enum_c90.c | 13 +++++++++++++ tests/usr.bin/xlint/lint1/decl_enum_c90.exp | 1 + tests/usr.bin/xlint/lint1/decl_struct_c90.c | 12 +++++++++++- tests/usr.bin/xlint/lint1/decl_struct_c90.exp | 5 +++-- .../usr.bin/xlint/lint1/decl_struct_member.c | 11 ++++++++++- .../xlint/lint1/decl_struct_member.exp | 4 ++-- tests/usr.bin/xlint/lint1/gcc_attribute.c | 12 +++++++++++- tests/usr.bin/xlint/lint1/gcc_attribute.exp | 1 + tests/usr.bin/xlint/lint1/gcc_stmt_asm.c | 6 +++++- tests/usr.bin/xlint/lint1/gcc_stmt_asm.exp | 1 + tests/usr.bin/xlint/lint1/msg_343.c | 10 +++++++++- tests/usr.bin/xlint/lint1/msg_343.exp | 2 ++ 17 files changed, 105 insertions(+), 12 deletions(-) create mode 100644 tests/usr.bin/xlint/lint1/decl_enum.c create mode 100644 tests/usr.bin/xlint/lint1/decl_enum.exp create mode 100644 tests/usr.bin/xlint/lint1/decl_enum_c90.c create mode 100644 tests/usr.bin/xlint/lint1/decl_enum_c90.exp diff --git a/distrib/sets/lists/tests/mi b/distrib/sets/lists/tests/mi index 4017b5a877b8..532db050b211 100644 --- a/distrib/sets/lists/tests/mi +++ b/distrib/sets/lists/tests/mi @@ -1,4 +1,4 @@ -# $NetBSD: mi,v 1.1090 2021/07/15 19:51:29 rillig Exp $ +# $NetBSD: mi,v 1.1091 2021/07/15 21:00:05 rillig Exp $ # # Note: don't delete entries from here - mark them as "obsolete" instead. # @@ -6218,6 +6218,10 @@ ./usr/tests/usr.bin/xlint/lint1/decl.exp 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_enum.c tests-usr.bin-tests compattestfile,atf +./usr/tests/usr.bin/xlint/lint1/decl_enum.exp tests-usr.bin-tests compattestfile,atf +./usr/tests/usr.bin/xlint/lint1/decl_enum_c90.c tests-usr.bin-tests compattestfile,atf +./usr/tests/usr.bin/xlint/lint1/decl_enum_c90.exp tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/xlint/lint1/decl_struct_c90.c tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/xlint/lint1/decl_struct_c90.exp tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/xlint/lint1/decl_struct_member.c tests-usr.bin-tests compattestfile,atf diff --git a/tests/usr.bin/xlint/lint1/Makefile b/tests/usr.bin/xlint/lint1/Makefile index f60fddd583be..af669da87450 100644 --- a/tests/usr.bin/xlint/lint1/Makefile +++ b/tests/usr.bin/xlint/lint1/Makefile @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.91 2021/07/15 19:51:29 rillig Exp $ +# $NetBSD: Makefile,v 1.92 2021/07/15 21:00:05 rillig Exp $ NOMAN= # defined MAX_MESSAGE= 345 # see lint1/err.c @@ -118,6 +118,10 @@ FILES+= decl.c FILES+= decl.exp FILES+= decl_arg.c FILES+= decl_arg.exp +FILES+= decl_enum.c +FILES+= decl_enum.exp +FILES+= decl_enum_c90.c +FILES+= decl_enum_c90.exp FILES+= decl_struct_c90.c FILES+= decl_struct_c90.exp FILES+= decl_struct_member.c diff --git a/tests/usr.bin/xlint/lint1/decl.c b/tests/usr.bin/xlint/lint1/decl.c index cec8af12f4bf..1c395f2027be 100644 --- a/tests/usr.bin/xlint/lint1/decl.c +++ b/tests/usr.bin/xlint/lint1/decl.c @@ -1,4 +1,4 @@ -/* $NetBSD: decl.c,v 1.5 2021/07/14 20:39:13 rillig Exp $ */ +/* $NetBSD: decl.c,v 1.6 2021/07/15 21:00:05 rillig Exp $ */ # 3 "decl.c" /* @@ -124,3 +124,6 @@ static void unused_linted(void) { } + +/* covers 'type_qualifier_list: type_qualifier_list type_qualifier' */ +int *const volatile cover_type_qualifier_list; diff --git a/tests/usr.bin/xlint/lint1/decl_enum.c b/tests/usr.bin/xlint/lint1/decl_enum.c new file mode 100644 index 000000000000..7a7937022a96 --- /dev/null +++ b/tests/usr.bin/xlint/lint1/decl_enum.c @@ -0,0 +1,19 @@ +/* $NetBSD: decl_enum.c,v 1.1 2021/07/15 21:00:05 rillig Exp $ */ +# 3 "decl_enum.c" + +/* + * Tests for enum declarations. + */ + +/* cover 'enumerator_list: error' */ +enum { + /* expect+1: error: syntax error 'goto' [249] */ + goto +}; + +/* cover 'enum_specifier: enum error' */ +/* expect+1: error: syntax error 'goto' [249] */ +enum goto { + A +}; +/* expect-1: warning: empty declaration [0] */ diff --git a/tests/usr.bin/xlint/lint1/decl_enum.exp b/tests/usr.bin/xlint/lint1/decl_enum.exp new file mode 100644 index 000000000000..5b0b3bea2699 --- /dev/null +++ b/tests/usr.bin/xlint/lint1/decl_enum.exp @@ -0,0 +1,3 @@ +decl_enum.c(11): error: syntax error 'goto' [249] +decl_enum.c(16): error: syntax error 'goto' [249] +decl_enum.c(18): warning: empty declaration [0] diff --git a/tests/usr.bin/xlint/lint1/decl_enum_c90.c b/tests/usr.bin/xlint/lint1/decl_enum_c90.c new file mode 100644 index 000000000000..04838edfbf9d --- /dev/null +++ b/tests/usr.bin/xlint/lint1/decl_enum_c90.c @@ -0,0 +1,13 @@ +/* $NetBSD: decl_enum_c90.c,v 1.1 2021/07/15 21:00:05 rillig Exp $ */ +# 3 "decl_enum_c90.c" + +/* + * Tests for enum declarations in C90 mode. + */ + +/* lint1-flags: -sw */ + +enum { + A, +}; +/* expect-1: trailing ',' prohibited in enum declaration [54] */ diff --git a/tests/usr.bin/xlint/lint1/decl_enum_c90.exp b/tests/usr.bin/xlint/lint1/decl_enum_c90.exp new file mode 100644 index 000000000000..08afe01580a6 --- /dev/null +++ b/tests/usr.bin/xlint/lint1/decl_enum_c90.exp @@ -0,0 +1 @@ +decl_enum_c90.c(12): error: trailing ',' prohibited in enum declaration [54] diff --git a/tests/usr.bin/xlint/lint1/decl_struct_c90.c b/tests/usr.bin/xlint/lint1/decl_struct_c90.c index 35782337ffae..f1f74cd68afa 100644 --- a/tests/usr.bin/xlint/lint1/decl_struct_c90.c +++ b/tests/usr.bin/xlint/lint1/decl_struct_c90.c @@ -1,4 +1,4 @@ -/* $NetBSD: decl_struct_c90.c,v 1.2 2021/07/15 20:05:49 rillig Exp $ */ +/* $NetBSD: decl_struct_c90.c,v 1.3 2021/07/15 21:00:05 rillig Exp $ */ # 3 "decl_struct_c90.c" /* @@ -7,6 +7,16 @@ /* lint1-flags: -sw */ +struct unnamed_member { + enum { A, B, C } tag; + union { + int a_value; + void *b_value; + void (*c_value)(void); + }; + /* expect-1: warning: anonymous struct/union members is a C9X feature [49] */ +}; + /* * All of K&R, C90, C99 require that a struct member declaration is * terminated with a semicolon. diff --git a/tests/usr.bin/xlint/lint1/decl_struct_c90.exp b/tests/usr.bin/xlint/lint1/decl_struct_c90.exp index 53c3a4544c1e..34711e09e40e 100644 --- a/tests/usr.bin/xlint/lint1/decl_struct_c90.exp +++ b/tests/usr.bin/xlint/lint1/decl_struct_c90.exp @@ -1,2 +1,3 @@ -decl_struct_c90.c(19): error: syntax error '}' [249] -decl_struct_c90.c(22): error: cannot recover from previous errors [224] +decl_struct_c90.c(16): warning: anonymous struct/union members is a C9X feature [49] +decl_struct_c90.c(29): error: syntax error '}' [249] +decl_struct_c90.c(32): error: cannot recover from previous errors [224] diff --git a/tests/usr.bin/xlint/lint1/decl_struct_member.c b/tests/usr.bin/xlint/lint1/decl_struct_member.c index 560ec6b9a0c8..a61e419abe3d 100644 --- a/tests/usr.bin/xlint/lint1/decl_struct_member.c +++ b/tests/usr.bin/xlint/lint1/decl_struct_member.c @@ -1,4 +1,4 @@ -/* $NetBSD: decl_struct_member.c,v 1.8 2021/07/15 20:05:49 rillig Exp $ */ +/* $NetBSD: decl_struct_member.c,v 1.9 2021/07/15 21:00:05 rillig Exp $ */ # 3 "decl_struct_member.c" struct multi_attributes { @@ -47,6 +47,15 @@ struct { char; /* expect: syntax error 'unnamed member' */ }; +struct cover_notype_struct_declarators { + const a, b; +}; + +struct cover_notype_struct_declarator_bit_field { + const a: 3, : 0, b: 4; + const : 0; +}; + /* * Before decl.c 1.188 from 2021-06-20, lint ran into a segmentation fault. */ diff --git a/tests/usr.bin/xlint/lint1/decl_struct_member.exp b/tests/usr.bin/xlint/lint1/decl_struct_member.exp index a9f7c0296de7..81a5d22364af 100644 --- a/tests/usr.bin/xlint/lint1/decl_struct_member.exp +++ b/tests/usr.bin/xlint/lint1/decl_struct_member.exp @@ -3,5 +3,5 @@ decl_struct_member.c(36): error: illegal type combination [4] decl_struct_member.c(38): error: syntax error '}' [249] decl_struct_member.c(38): warning: empty declaration [0] decl_struct_member.c(47): error: syntax error 'unnamed member' [249] -decl_struct_member.c(54): error: syntax error '0' [249] -decl_struct_member.c(62): error: cannot recover from previous errors [224] +decl_struct_member.c(63): error: syntax error '0' [249] +decl_struct_member.c(71): error: cannot recover from previous errors [224] diff --git a/tests/usr.bin/xlint/lint1/gcc_attribute.c b/tests/usr.bin/xlint/lint1/gcc_attribute.c index ae3ffba1fa0b..37a449e1c94a 100644 --- a/tests/usr.bin/xlint/lint1/gcc_attribute.c +++ b/tests/usr.bin/xlint/lint1/gcc_attribute.c @@ -1,4 +1,4 @@ -/* $NetBSD: gcc_attribute.c,v 1.9 2021/07/09 18:55:28 rillig Exp $ */ +/* $NetBSD: gcc_attribute.c,v 1.10 2021/07/15 21:00:05 rillig Exp $ */ # 3 "gcc_attribute.c" /* @@ -117,3 +117,13 @@ __attribute__((deprecated("d5"))) ) __attribute__((deprecated("d8"))) ; + +/* + * The attribute 'const' provides stronger guarantees than 'pure', and + * 'volatile' is not defined. To keep the grammar simple, any T_QUAL is + * allowed at this point, but only syntactically. + */ +int const_function(int) __attribute__((const)); +/* cover 'gcc_attribute_spec: T_QUAL' */ +/* expect+1: syntax error 'volatile' [249] */ +int volatile_function(int) __attribute__((volatile)); diff --git a/tests/usr.bin/xlint/lint1/gcc_attribute.exp b/tests/usr.bin/xlint/lint1/gcc_attribute.exp index fbc58a086967..8340bcb790b2 100644 --- a/tests/usr.bin/xlint/lint1/gcc_attribute.exp +++ b/tests/usr.bin/xlint/lint1/gcc_attribute.exp @@ -1 +1,2 @@ gcc_attribute.c(33): error: syntax error 'unknown_attribute' [249] +gcc_attribute.c(129): error: syntax error 'volatile' [249] diff --git a/tests/usr.bin/xlint/lint1/gcc_stmt_asm.c b/tests/usr.bin/xlint/lint1/gcc_stmt_asm.c index 4b12a7dbefee..6934aa466520 100644 --- a/tests/usr.bin/xlint/lint1/gcc_stmt_asm.c +++ b/tests/usr.bin/xlint/lint1/gcc_stmt_asm.c @@ -1,4 +1,4 @@ -/* $NetBSD: gcc_stmt_asm.c,v 1.1 2021/07/14 20:39:13 rillig Exp $ */ +/* $NetBSD: gcc_stmt_asm.c,v 1.2 2021/07/15 21:00:05 rillig Exp $ */ # 3 "gcc_stmt_asm.c" /* @@ -36,3 +36,7 @@ syntax_error(void) /* expect+1: syntax error '__asm__' [249] */ int i = __asm__(); } + +__asm__( +/* cover ignore_up_to_rparen at EOF */ +/* expect+1: error: syntax error '' [249] */ diff --git a/tests/usr.bin/xlint/lint1/gcc_stmt_asm.exp b/tests/usr.bin/xlint/lint1/gcc_stmt_asm.exp index 0ff6e91130f7..368197226a2f 100644 --- a/tests/usr.bin/xlint/lint1/gcc_stmt_asm.exp +++ b/tests/usr.bin/xlint/lint1/gcc_stmt_asm.exp @@ -1 +1,2 @@ gcc_stmt_asm.c(37): error: syntax error '__asm__' [249] +gcc_stmt_asm.c(43): error: syntax error '' [249] diff --git a/tests/usr.bin/xlint/lint1/msg_343.c b/tests/usr.bin/xlint/lint1/msg_343.c index a7bea436d6fd..e4e4ce4b4058 100644 --- a/tests/usr.bin/xlint/lint1/msg_343.c +++ b/tests/usr.bin/xlint/lint1/msg_343.c @@ -1,4 +1,4 @@ -/* $NetBSD: msg_343.c,v 1.4 2021/04/14 22:06:38 rillig Exp $ */ +/* $NetBSD: msg_343.c,v 1.5 2021/07/15 21:00:05 rillig Exp $ */ # 3 "msg_343.c" /* Test for message: static array size is a C11 extension [343] */ @@ -37,3 +37,11 @@ returns_volatile_int_array(int a[volatile 3]) /* expect+1: expects to return value */ return a[0]; } + +/* + * This triggers the "Bad attribute", but for some reason, that custom error + * message does not make it into the actual diagnostic. + */ +/* expect+2: error: syntax error ']' [249] */ +/* expect+1: error: static array size is a C11 extension [343] */ +void invalid_storage_class(int a[const typedef 3]); diff --git a/tests/usr.bin/xlint/lint1/msg_343.exp b/tests/usr.bin/xlint/lint1/msg_343.exp index f8b59fcab82e..f69c7c26d678 100644 --- a/tests/usr.bin/xlint/lint1/msg_343.exp +++ b/tests/usr.bin/xlint/lint1/msg_343.exp @@ -4,3 +4,5 @@ msg_343.c(27): error: static array size is a C11 extension [343] msg_343.c(34): error: syntax error '3' [249] msg_343.c(38): error: cannot dereference non-pointer type [96] msg_343.c(38): warning: function returns_volatile_int_array expects to return value [214] +msg_343.c(47): error: syntax error ']' [249] +msg_343.c(47): error: static array size is a C11 extension [343]