Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src tests/lint: add several tests for edge cases in the grammar
details: https://anonhg.NetBSD.org/src/rev/17c0efc4e84b
branches: trunk
changeset: 1022372:17c0efc4e84b
user: rillig <rillig%NetBSD.org@localhost>
date: Wed Jul 14 20:39:13 2021 +0000
description:
tests/lint: add several tests for edge cases in the grammar
diffstat:
distrib/sets/lists/tests/mi | 6 +++-
tests/usr.bin/xlint/lint1/Makefile | 6 +++-
tests/usr.bin/xlint/lint1/decl.c | 27 ++++++++++++++++-
tests/usr.bin/xlint/lint1/decl.exp | 1 +
tests/usr.bin/xlint/lint1/decl_struct_member.c | 23 +++++++++++++-
tests/usr.bin/xlint/lint1/decl_struct_member.exp | 8 ++--
tests/usr.bin/xlint/lint1/gcc_attribute_func.c | 20 ++++++++++--
tests/usr.bin/xlint/lint1/gcc_attribute_func.exp | 3 +-
tests/usr.bin/xlint/lint1/gcc_stmt_asm.c | 38 ++++++++++++++++++++++++
tests/usr.bin/xlint/lint1/gcc_stmt_asm.exp | 1 +
tests/usr.bin/xlint/lint1/init_c90.c | 9 +++++-
tests/usr.bin/xlint/lint1/init_c90.exp | 1 +
tests/usr.bin/xlint/lint1/msg_002.c | 19 +++++++++++-
tests/usr.bin/xlint/lint1/msg_002.exp | 4 ++
tests/usr.bin/xlint/lint1/msg_072.c | 19 +++++++++++-
tests/usr.bin/xlint/lint1/msg_072.exp | 4 ++
tests/usr.bin/xlint/lint1/stmt_goto.c | 26 ++++++++++++++++
tests/usr.bin/xlint/lint1/stmt_goto.exp | 3 +
18 files changed, 202 insertions(+), 16 deletions(-)
diffs (truncated from 379 to 300 lines):
diff -r 41cb8f46103e -r 17c0efc4e84b distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi Wed Jul 14 18:56:05 2021 +0000
+++ b/distrib/sets/lists/tests/mi Wed Jul 14 20:39:13 2021 +0000
@@ -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
diff -r 41cb8f46103e -r 17c0efc4e84b tests/usr.bin/xlint/lint1/Makefile
--- a/tests/usr.bin/xlint/lint1/Makefile Wed Jul 14 18:56:05 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/Makefile Wed Jul 14 20:39:13 2021 +0000
@@ -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.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.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
diff -r 41cb8f46103e -r 17c0efc4e84b tests/usr.bin/xlint/lint1/decl.c
--- a/tests/usr.bin/xlint/lint1/decl.c Wed Jul 14 18:56:05 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/decl.c Wed Jul 14 20:39:13 2021 +0000
@@ -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 @@
__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)
+{
+}
diff -r 41cb8f46103e -r 17c0efc4e84b tests/usr.bin/xlint/lint1/decl.exp
--- a/tests/usr.bin/xlint/lint1/decl.exp Wed Jul 14 18:56:05 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/decl.exp Wed Jul 14 20:39:13 2021 +0000
@@ -9,3 +9,4 @@
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]
diff -r 41cb8f46103e -r 17c0efc4e84b tests/usr.bin/xlint/lint1/decl_struct_member.c
--- a/tests/usr.bin/xlint/lint1/decl_struct_member.c Wed Jul 14 18:56:05 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/decl_struct_member.c Wed Jul 14 20:39:13 2021 +0000
@@ -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 @@
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:
*
diff -r 41cb8f46103e -r 17c0efc4e84b tests/usr.bin/xlint/lint1/decl_struct_member.exp
--- a/tests/usr.bin/xlint/lint1/decl_struct_member.exp Wed Jul 14 18:56:05 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/decl_struct_member.exp Wed Jul 14 20:39:13 2021 +0000
@@ -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]
diff -r 41cb8f46103e -r 17c0efc4e84b tests/usr.bin/xlint/lint1/gcc_attribute_func.c
--- a/tests/usr.bin/xlint/lint1/gcc_attribute_func.c Wed Jul 14 18:56:05 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/gcc_attribute_func.c Wed Jul 14 20:39:13 2021 +0000
@@ -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_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)
+{
+}
diff -r 41cb8f46103e -r 17c0efc4e84b tests/usr.bin/xlint/lint1/gcc_attribute_func.exp
--- a/tests/usr.bin/xlint/lint1/gcc_attribute_func.exp Wed Jul 14 18:56:05 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/gcc_attribute_func.exp Wed Jul 14 20:39:13 2021 +0000
@@ -1,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]
diff -r 41cb8f46103e -r 17c0efc4e84b tests/usr.bin/xlint/lint1/gcc_stmt_asm.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/usr.bin/xlint/lint1/gcc_stmt_asm.c Wed Jul 14 20:39:13 2021 +0000
@@ -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__();
+}
diff -r 41cb8f46103e -r 17c0efc4e84b tests/usr.bin/xlint/lint1/gcc_stmt_asm.exp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/usr.bin/xlint/lint1/gcc_stmt_asm.exp Wed Jul 14 20:39:13 2021 +0000
@@ -0,0 +1,1 @@
+gcc_stmt_asm.c(37): error: syntax error '__asm__' [249]
diff -r 41cb8f46103e -r 17c0efc4e84b tests/usr.bin/xlint/lint1/init_c90.c
--- a/tests/usr.bin/xlint/lint1/init_c90.c Wed Jul 14 18:56:05 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/init_c90.c Wed Jul 14 20:39:13 2021 +0000
@@ -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 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 };
+}
diff -r 41cb8f46103e -r 17c0efc4e84b tests/usr.bin/xlint/lint1/init_c90.exp
--- a/tests/usr.bin/xlint/lint1/init_c90.exp Wed Jul 14 18:56:05 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/init_c90.exp Wed Jul 14 20:39:13 2021 +0000
@@ -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]
diff -r 41cb8f46103e -r 17c0efc4e84b tests/usr.bin/xlint/lint1/msg_002.c
--- a/tests/usr.bin/xlint/lint1/msg_002.c Wed Jul 14 18:56:05 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_002.c Wed Jul 14 20:39:13 2021 +0000
@@ -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 @@
/* 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;
+}
diff -r 41cb8f46103e -r 17c0efc4e84b tests/usr.bin/xlint/lint1/msg_002.exp
--- a/tests/usr.bin/xlint/lint1/msg_002.exp Wed Jul 14 18:56:05 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_002.exp Wed Jul 14 20:39:13 2021 +0000
@@ -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]
Home |
Main Index |
Thread Index |
Old Index