Module Name: src Committed By: rillig Date: Wed Jul 14 20:39:13 UTC 2021
Modified Files: src/distrib/sets/lists/tests: mi src/tests/usr.bin/xlint/lint1: Makefile decl.c decl.exp decl_struct_member.c decl_struct_member.exp gcc_attribute_func.c gcc_attribute_func.exp init_c90.c init_c90.exp msg_002.c msg_002.exp msg_072.c msg_072.exp Added Files: src/tests/usr.bin/xlint/lint1: gcc_stmt_asm.c gcc_stmt_asm.exp stmt_goto.c stmt_goto.exp Log Message: tests/lint: add several tests for edge cases in the grammar To generate a diff of this commit: cvs rdiff -u -r1.1087 -r1.1088 src/distrib/sets/lists/tests/mi cvs rdiff -u -r1.88 -r1.89 src/tests/usr.bin/xlint/lint1/Makefile cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/xlint/lint1/decl.c \ src/tests/usr.bin/xlint/lint1/decl.exp \ src/tests/usr.bin/xlint/lint1/decl_struct_member.exp \ src/tests/usr.bin/xlint/lint1/msg_002.c \ src/tests/usr.bin/xlint/lint1/msg_072.c cvs rdiff -u -r1.5 -r1.6 src/tests/usr.bin/xlint/lint1/decl_struct_member.c cvs rdiff -u -r1.1 -r1.2 src/tests/usr.bin/xlint/lint1/gcc_attribute_func.c \ src/tests/usr.bin/xlint/lint1/gcc_attribute_func.exp \ src/tests/usr.bin/xlint/lint1/init_c90.c \ src/tests/usr.bin/xlint/lint1/init_c90.exp cvs rdiff -u -r0 -r1.1 src/tests/usr.bin/xlint/lint1/gcc_stmt_asm.c \ src/tests/usr.bin/xlint/lint1/gcc_stmt_asm.exp \ src/tests/usr.bin/xlint/lint1/stmt_goto.c \ src/tests/usr.bin/xlint/lint1/stmt_goto.exp cvs rdiff -u -r1.3 -r1.4 src/tests/usr.bin/xlint/lint1/msg_002.exp \ src/tests/usr.bin/xlint/lint1/msg_072.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.1087 src/distrib/sets/lists/tests/mi:1.1088 --- src/distrib/sets/lists/tests/mi:1.1087 Wed Jul 14 03:22:33 2021 +++ src/distrib/sets/lists/tests/mi Wed Jul 14 20:39:13 2021 @@ -1,4 +1,4 @@ -# $NetBSD: mi,v 1.1087 2021/07/14 03:22:33 ozaki-r Exp $ +# $NetBSD: mi,v 1.1088 2021/07/14 20:39:13 rillig Exp $ # # Note: don't delete entries from here - mark them as "obsolete" instead. # @@ -6248,6 +6248,8 @@ ./usr/tests/usr.bin/xlint/lint1/gcc_bit_field_types.exp tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/xlint/lint1/gcc_init_compound_literal.c tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/xlint/lint1/gcc_init_compound_literal.exp tests-usr.bin-tests compattestfile,atf +./usr/tests/usr.bin/xlint/lint1/gcc_stmt_asm.c tests-usr.bin-tests compattestfile,atf +./usr/tests/usr.bin/xlint/lint1/gcc_stmt_asm.exp tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/xlint/lint1/gcc_typeof_after_statement.c tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/xlint/lint1/gcc_typeof_after_statement.exp tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/xlint/lint1/init.c tests-usr.bin-tests compattestfile,atf @@ -6982,6 +6984,8 @@ ./usr/tests/usr.bin/xlint/lint1/op_shl_lp64.exp tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/xlint/lint1/stmt_for.c tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/xlint/lint1/stmt_for.exp tests-usr.bin-tests compattestfile,atf +./usr/tests/usr.bin/xlint/lint1/stmt_goto.c tests-usr.bin-tests compattestfile,atf +./usr/tests/usr.bin/xlint/lint1/stmt_goto.exp tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/xlint/lint1/stmt_if.c tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/xlint/lint1/stmt_if.exp tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/xlint/lint1/t_integration tests-usr.bin-tests compattestfile,atf Index: src/tests/usr.bin/xlint/lint1/Makefile diff -u src/tests/usr.bin/xlint/lint1/Makefile:1.88 src/tests/usr.bin/xlint/lint1/Makefile:1.89 --- src/tests/usr.bin/xlint/lint1/Makefile:1.88 Tue Jul 13 19:38:10 2021 +++ src/tests/usr.bin/xlint/lint1/Makefile Wed Jul 14 20:39:13 2021 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.88 2021/07/13 19:38:10 rillig Exp $ +# $NetBSD: Makefile,v 1.89 2021/07/14 20:39:13 rillig Exp $ NOMAN= # defined MAX_MESSAGE= 345 # see lint1/err.c @@ -146,6 +146,8 @@ FILES+= gcc_bit_field_types.c FILES+= gcc_bit_field_types.exp FILES+= gcc_init_compound_literal.c FILES+= gcc_init_compound_literal.exp +FILES+= gcc_stmt_asm.c +FILES+= gcc_stmt_asm.exp FILES+= gcc_typeof_after_statement.c FILES+= gcc_typeof_after_statement.exp FILES+= init.c @@ -188,6 +190,8 @@ FILES+= op_shl_lp64.c FILES+= op_shl_lp64.exp FILES+= stmt_for.c FILES+= stmt_for.exp +FILES+= stmt_goto.c +FILES+= stmt_goto.exp FILES+= stmt_if.c FILES+= stmt_if.exp Index: src/tests/usr.bin/xlint/lint1/decl.c diff -u src/tests/usr.bin/xlint/lint1/decl.c:1.4 src/tests/usr.bin/xlint/lint1/decl.c:1.5 --- src/tests/usr.bin/xlint/lint1/decl.c:1.4 Sun Jul 11 15:07:39 2021 +++ src/tests/usr.bin/xlint/lint1/decl.c Wed Jul 14 20:39:13 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: decl.c,v 1.4 2021/07/11 15:07:39 rillig Exp $ */ +/* $NetBSD: decl.c,v 1.5 2021/07/14 20:39:13 rillig Exp $ */ # 3 "decl.c" /* @@ -99,3 +99,28 @@ unused_local_variable(void) __attribute__((unused)) __attribute__((unused)) _Bool unused_twice; } + +int +declaration_without_type_specifier(void) +{ + const i = 3; + + return i; +} + +/* TODO: add quotes around %s */ +/* expect+2: warning: static function unused unused [236] */ +static void +unused(void) +{ +} + +/* + * The attribute 'used' does not influence static functions, it only + * applies to function parameters. + */ +/* LINTED */ +static void +unused_linted(void) +{ +} Index: src/tests/usr.bin/xlint/lint1/decl.exp diff -u src/tests/usr.bin/xlint/lint1/decl.exp:1.4 src/tests/usr.bin/xlint/lint1/decl.exp:1.5 --- src/tests/usr.bin/xlint/lint1/decl.exp:1.4 Sun Jul 11 15:07:39 2021 +++ src/tests/usr.bin/xlint/lint1/decl.exp Wed Jul 14 20:39:13 2021 @@ -9,3 +9,4 @@ decl.c(68): warning: converting 'pointer decl.c(70): warning: illegal combination of pointer (pointer to double) and integer (char), arg #1 [154] decl.c(72): warning: converting 'pointer to pointer to char' to incompatible 'pointer to double' for argument 1 [153] decl.c(80): error: syntax error '"' [249] +decl.c(114): warning: static function unused unused [236] Index: src/tests/usr.bin/xlint/lint1/decl_struct_member.exp diff -u src/tests/usr.bin/xlint/lint1/decl_struct_member.exp:1.4 src/tests/usr.bin/xlint/lint1/decl_struct_member.exp:1.5 --- src/tests/usr.bin/xlint/lint1/decl_struct_member.exp:1.4 Sat Jul 10 22:46:02 2021 +++ src/tests/usr.bin/xlint/lint1/decl_struct_member.exp Wed Jul 14 20:39:13 2021 @@ -1,4 +1,4 @@ -decl_struct_member.c(17): error: syntax error 'unnamed member' [249] -decl_struct_member.c(24): error: syntax error '0' [249] -decl_struct_member.c(25): warning: syntax requires ';' after last struct/union member [66] -decl_struct_member.c(32): error: cannot recover from previous errors [224] +decl_struct_member.c(38): error: syntax error 'unnamed member' [249] +decl_struct_member.c(45): error: syntax error '0' [249] +decl_struct_member.c(46): warning: syntax requires ';' after last struct/union member [66] +decl_struct_member.c(53): error: cannot recover from previous errors [224] Index: src/tests/usr.bin/xlint/lint1/msg_002.c diff -u src/tests/usr.bin/xlint/lint1/msg_002.c:1.4 src/tests/usr.bin/xlint/lint1/msg_002.c:1.5 --- src/tests/usr.bin/xlint/lint1/msg_002.c:1.4 Thu Jul 8 05:18:49 2021 +++ src/tests/usr.bin/xlint/lint1/msg_002.c Wed Jul 14 20:39:13 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: msg_002.c,v 1.4 2021/07/08 05:18:49 rillig Exp $ */ +/* $NetBSD: msg_002.c,v 1.5 2021/07/14 20:39:13 rillig Exp $ */ # 3 "msg_002.c" // Test for message: empty declaration [2] @@ -10,3 +10,20 @@ int local_variable; /* expect+1: warning: empty declaration [2] */ const; + +void +cover_cgram_declaration(void) +{ + + /* expect+1: warning: typedef declares no type name [72] */ + typedef const; + + /* expect+1: warning: empty declaration [2] */ + const; + + /* expect+1: warning: typedef declares no type name [72] */ + typedef int; + + /* expect+1: warning: empty declaration [2] */ + int; +} Index: src/tests/usr.bin/xlint/lint1/msg_072.c diff -u src/tests/usr.bin/xlint/lint1/msg_072.c:1.4 src/tests/usr.bin/xlint/lint1/msg_072.c:1.5 --- src/tests/usr.bin/xlint/lint1/msg_072.c:1.4 Thu Jul 8 05:18:49 2021 +++ src/tests/usr.bin/xlint/lint1/msg_072.c Wed Jul 14 20:39:13 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: msg_072.c,v 1.4 2021/07/08 05:18:49 rillig Exp $ */ +/* $NetBSD: msg_072.c,v 1.5 2021/07/14 20:39:13 rillig Exp $ */ # 3 "msg_072.c" // Test for message: typedef declares no type name [72] @@ -10,3 +10,20 @@ typedef int number; /* expect+1: warning: typedef declares no type name [72] */ const typedef; + +void +cover_cgram_declaration(void) +{ + + /* expect+1: warning: typedef declares no type name [72] */ + typedef const; + + /* expect+1: warning: empty declaration [2] */ + const; + + /* expect+1: warning: typedef declares no type name [72] */ + typedef int; + + /* expect+1: warning: empty declaration [2] */ + int; +} Index: src/tests/usr.bin/xlint/lint1/decl_struct_member.c diff -u src/tests/usr.bin/xlint/lint1/decl_struct_member.c:1.5 src/tests/usr.bin/xlint/lint1/decl_struct_member.c:1.6 --- src/tests/usr.bin/xlint/lint1/decl_struct_member.c:1.5 Sat Jul 10 22:46:02 2021 +++ src/tests/usr.bin/xlint/lint1/decl_struct_member.c Wed Jul 14 20:39:13 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: decl_struct_member.c,v 1.5 2021/07/10 22:46:02 rillig Exp $ */ +/* $NetBSD: decl_struct_member.c,v 1.6 2021/07/14 20:39:13 rillig Exp $ */ # 3 "decl_struct_member.c" struct multi_attributes { @@ -8,6 +8,27 @@ struct multi_attributes { int deprecated; }; +struct cover_begin_type_noclass_declspecs { + int m1; + __attribute__((deprecated)) int m2; + const int m3; + int const m4; + int const long m5; + int __attribute__((deprecated)) m6; +}; + +typedef int number; + +struct cover_begin_type_typespec { + int m1; + number m2; +}; + +struct cover_begin_type_noclass_declmods { + const m1; + const volatile m2; +}; + /* * Before cgram.y 1.228 from 2021-06-19, lint ran into an assertion failure: * Index: src/tests/usr.bin/xlint/lint1/gcc_attribute_func.c diff -u src/tests/usr.bin/xlint/lint1/gcc_attribute_func.c:1.1 src/tests/usr.bin/xlint/lint1/gcc_attribute_func.c:1.2 --- src/tests/usr.bin/xlint/lint1/gcc_attribute_func.c:1.1 Tue Jul 6 17:33:07 2021 +++ src/tests/usr.bin/xlint/lint1/gcc_attribute_func.c Wed Jul 14 20:39:13 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: gcc_attribute_func.c,v 1.1 2021/07/06 17:33:07 rillig Exp $ */ +/* $NetBSD: gcc_attribute_func.c,v 1.2 2021/07/14 20:39:13 rillig Exp $ */ # 3 "gcc_attribute_func.c" /* @@ -21,6 +21,18 @@ void *__attribute__((__cold__)) attribut void *attribute_after_name __attribute__((__cold__))(void); void *attribute_after_parameters(void) __attribute__((__cold__)); -/* just to trigger _some_ error, to keep the .exp file */ -/* expect+1: error: syntax error 'syntax_error' [249] */ -__attribute__((syntax_error)); +/* + * The attribute 'used' does not influence static functions, it only + * applies to function parameters. + */ +/* expect+2: warning: static function used_function unused [236] */ +static void __attribute__((used)) +used_function(void) +{ +} + +/* expect+2: warning: static function unused_function unused [236] */ +static void +unused_function(void) +{ +} Index: src/tests/usr.bin/xlint/lint1/gcc_attribute_func.exp diff -u src/tests/usr.bin/xlint/lint1/gcc_attribute_func.exp:1.1 src/tests/usr.bin/xlint/lint1/gcc_attribute_func.exp:1.2 --- src/tests/usr.bin/xlint/lint1/gcc_attribute_func.exp:1.1 Tue Jul 6 17:33:07 2021 +++ src/tests/usr.bin/xlint/lint1/gcc_attribute_func.exp Wed Jul 14 20:39:13 2021 @@ -1 +1,2 @@ -gcc_attribute_func.c(26): error: syntax error 'syntax_error' [249] +gcc_attribute_func.c(30): warning: static function used_function unused [236] +gcc_attribute_func.c(36): warning: static function unused_function unused [236] Index: src/tests/usr.bin/xlint/lint1/init_c90.c diff -u src/tests/usr.bin/xlint/lint1/init_c90.c:1.1 src/tests/usr.bin/xlint/lint1/init_c90.c:1.2 --- src/tests/usr.bin/xlint/lint1/init_c90.c:1.1 Sat Jul 10 09:24:27 2021 +++ src/tests/usr.bin/xlint/lint1/init_c90.c Wed Jul 14 20:39:13 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: init_c90.c,v 1.1 2021/07/10 09:24:27 rillig Exp $ */ +/* $NetBSD: init_c90.c,v 1.2 2021/07/14 20:39:13 rillig Exp $ */ # 3 "init_c90.c" /* @@ -21,3 +21,10 @@ struct point point_c99 = { .x = 0, .y = struct point points_c90[] = {{ 0, 0 }}; /* expect+1: warning: array initializer with designators is a C9X feature [321] */ struct point points_c99[] = {[3] = { 0, 0 }}; + + +struct point +compound_literal(void) { + /* expect+1: compound literals are a C9X/GCC extension [319] */ + return (struct point){ 0, 0 }; +} Index: src/tests/usr.bin/xlint/lint1/init_c90.exp diff -u src/tests/usr.bin/xlint/lint1/init_c90.exp:1.1 src/tests/usr.bin/xlint/lint1/init_c90.exp:1.2 --- src/tests/usr.bin/xlint/lint1/init_c90.exp:1.1 Sat Jul 10 09:24:27 2021 +++ src/tests/usr.bin/xlint/lint1/init_c90.exp Wed Jul 14 20:39:13 2021 @@ -1,3 +1,4 @@ init_c90.c(19): warning: struct or union member name in initializer is a C9X feature [313] init_c90.c(19): warning: struct or union member name in initializer is a C9X feature [313] init_c90.c(23): warning: array initializer with designators is a C9X feature [321] +init_c90.c(29): error: compound literals are a C9X/GCC extension [319] Index: src/tests/usr.bin/xlint/lint1/msg_002.exp diff -u src/tests/usr.bin/xlint/lint1/msg_002.exp:1.3 src/tests/usr.bin/xlint/lint1/msg_002.exp:1.4 --- src/tests/usr.bin/xlint/lint1/msg_002.exp:1.3 Thu Jul 8 05:18:49 2021 +++ src/tests/usr.bin/xlint/lint1/msg_002.exp Wed Jul 14 20:39:13 2021 @@ -1,2 +1,6 @@ msg_002.c(7): warning: empty declaration [2] msg_002.c(12): warning: empty declaration [2] +msg_002.c(19): warning: typedef declares no type name [72] +msg_002.c(22): warning: empty declaration [2] +msg_002.c(25): warning: typedef declares no type name [72] +msg_002.c(28): warning: empty declaration [2] Index: src/tests/usr.bin/xlint/lint1/msg_072.exp diff -u src/tests/usr.bin/xlint/lint1/msg_072.exp:1.3 src/tests/usr.bin/xlint/lint1/msg_072.exp:1.4 --- src/tests/usr.bin/xlint/lint1/msg_072.exp:1.3 Thu Jul 8 05:18:49 2021 +++ src/tests/usr.bin/xlint/lint1/msg_072.exp Wed Jul 14 20:39:13 2021 @@ -1,2 +1,6 @@ msg_072.c(7): warning: typedef declares no type name [72] msg_072.c(12): warning: typedef declares no type name [72] +msg_072.c(19): warning: typedef declares no type name [72] +msg_072.c(22): warning: empty declaration [2] +msg_072.c(25): warning: typedef declares no type name [72] +msg_072.c(28): warning: empty declaration [2] Added files: Index: src/tests/usr.bin/xlint/lint1/gcc_stmt_asm.c diff -u /dev/null src/tests/usr.bin/xlint/lint1/gcc_stmt_asm.c:1.1 --- /dev/null Wed Jul 14 20:39:14 2021 +++ src/tests/usr.bin/xlint/lint1/gcc_stmt_asm.c Wed Jul 14 20:39:13 2021 @@ -0,0 +1,38 @@ +/* $NetBSD: gcc_stmt_asm.c,v 1.1 2021/07/14 20:39:13 rillig Exp $ */ +# 3 "gcc_stmt_asm.c" + +/* + * Tests for the GCC 'asm' statement. + */ + +void +function(void) +{ + /* + * lint is not really interested in assembly language, therefore it + * just skips everything until and including the closing parenthesis. + */ + asm(any "string" or 12345 || whatever); + + /* + * Parentheses are allowed in 'asm' statements, they have to be + * properly nested. Brackets and braces don't have to be nested + * since they usually not occur in 'asm' statements. + */ + __asm(^(int = typedef[[[{{{)); + + __asm__(); +} + +/* + * Even on the top level, 'asm' is allowed. It is interpreted as a + * declaration. + */ +__asm__(); + +void +syntax_error(void) +{ + /* expect+1: syntax error '__asm__' [249] */ + int i = __asm__(); +} Index: src/tests/usr.bin/xlint/lint1/gcc_stmt_asm.exp diff -u /dev/null src/tests/usr.bin/xlint/lint1/gcc_stmt_asm.exp:1.1 --- /dev/null Wed Jul 14 20:39:14 2021 +++ src/tests/usr.bin/xlint/lint1/gcc_stmt_asm.exp Wed Jul 14 20:39:13 2021 @@ -0,0 +1 @@ +gcc_stmt_asm.c(37): error: syntax error '__asm__' [249] Index: src/tests/usr.bin/xlint/lint1/stmt_goto.c diff -u /dev/null src/tests/usr.bin/xlint/lint1/stmt_goto.c:1.1 --- /dev/null Wed Jul 14 20:39:14 2021 +++ src/tests/usr.bin/xlint/lint1/stmt_goto.c Wed Jul 14 20:39:13 2021 @@ -0,0 +1,26 @@ +/* $NetBSD: stmt_goto.c,v 1.1 2021/07/14 20:39:13 rillig Exp $ */ +# 3 "stmt_goto.c" + +/* + * Tests for the 'goto' statement. + */ + +/* expect+1: syntax error 'goto' [249] */ +goto invalid_at_top_level; + +void +function(void) +{ + goto label; +label: + /* expect+1: syntax error '"' [249] */ + goto "string"; + + /* Reset the error handling of the parser. */ + goto ok; +ok: + + /* Numeric labels work in Pascal, but not in C. */ + /* expect+1: syntax error '12345' [249] */ + goto 12345; +} Index: src/tests/usr.bin/xlint/lint1/stmt_goto.exp diff -u /dev/null src/tests/usr.bin/xlint/lint1/stmt_goto.exp:1.1 --- /dev/null Wed Jul 14 20:39:14 2021 +++ src/tests/usr.bin/xlint/lint1/stmt_goto.exp Wed Jul 14 20:39:13 2021 @@ -0,0 +1,3 @@ +stmt_goto.c(9): error: syntax error 'goto' [249] +stmt_goto.c(17): error: syntax error '"' [249] +stmt_goto.c(25): error: syntax error '12345' [249]