tests/lint: cover more edge cases in the parser

This commit is contained in:
rillig 2021-07-15 21:00:05 +00:00
parent a8f0cd4b03
commit ae95f90ee9
17 changed files with 105 additions and 12 deletions

View File

@ -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

View File

@ -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

View File

@ -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;

View File

@ -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] */

View File

@ -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]

View File

@ -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] */

View File

@ -0,0 +1 @@
decl_enum_c90.c(12): error: trailing ',' prohibited in enum declaration [54]

View File

@ -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.

View File

@ -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]

View File

@ -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.
*/

View File

@ -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]

View File

@ -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));

View File

@ -1 +1,2 @@
gcc_attribute.c(33): error: syntax error 'unknown_attribute' [249]
gcc_attribute.c(129): error: syntax error 'volatile' [249]

View File

@ -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] */

View File

@ -1 +1,2 @@
gcc_stmt_asm.c(37): error: syntax error '__asm__' [249]
gcc_stmt_asm.c(43): error: syntax error '' [249]

View File

@ -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]);

View File

@ -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]