Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/tests/usr.bin/xlint/lint1 tests/lint: add tests for a few mo...
details: https://anonhg.NetBSD.org/src/rev/6c95b6b799c6
branches: trunk
changeset: 960374:6c95b6b799c6
user: rillig <rillig%NetBSD.org@localhost>
date: Tue Mar 16 23:39:41 2021 +0000
description:
tests/lint: add tests for a few more messages
diffstat:
tests/usr.bin/xlint/lint1/msg_031.c | 5 +++-
tests/usr.bin/xlint/lint1/msg_031.exp | 1 +
tests/usr.bin/xlint/lint1/msg_151.c | 12 +++++++--
tests/usr.bin/xlint/lint1/msg_151.exp | 2 +-
tests/usr.bin/xlint/lint1/msg_152.c | 14 +++++++++--
tests/usr.bin/xlint/lint1/msg_152.exp | 5 +++-
tests/usr.bin/xlint/lint1/msg_154.c | 11 ++++++--
tests/usr.bin/xlint/lint1/msg_154.exp | 2 +-
tests/usr.bin/xlint/lint1/msg_157.c | 9 +++++--
tests/usr.bin/xlint/lint1/msg_157.exp | 2 +-
tests/usr.bin/xlint/lint1/msg_158.c | 42 ++++++++++++++++++++++++++++++++--
tests/usr.bin/xlint/lint1/msg_158.exp | 2 +-
12 files changed, 86 insertions(+), 21 deletions(-)
diffs (184 lines):
diff -r f539fb0a5681 -r 6c95b6b799c6 tests/usr.bin/xlint/lint1/msg_031.c
--- a/tests/usr.bin/xlint/lint1/msg_031.c Tue Mar 16 23:18:49 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_031.c Tue Mar 16 23:39:41 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: msg_031.c,v 1.3 2021/01/31 11:12:07 rillig Exp $ */
+/* $NetBSD: msg_031.c,v 1.4 2021/03/16 23:39:41 rillig Exp $ */
# 3 "msg_031.c"
// Test for message: incomplete structure or union %s: %s [31]
@@ -13,3 +13,6 @@
struct complete complete_var;
struct incomplete incomplete_var; /* expect: 31 */
+
+/* XXX: the 'incomplete: <unnamed>' in the diagnostic looks strange */
+void function(struct incomplete); /* expect: incomplete: <unnamed> [31] */
diff -r f539fb0a5681 -r 6c95b6b799c6 tests/usr.bin/xlint/lint1/msg_031.exp
--- a/tests/usr.bin/xlint/lint1/msg_031.exp Tue Mar 16 23:18:49 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_031.exp Tue Mar 16 23:39:41 2021 +0000
@@ -1,2 +1,3 @@
+msg_031.c(18): incomplete structure or union incomplete: <unnamed> [31]
msg_031.c(10): warning: struct incomplete never defined [233]
msg_031.c(15): incomplete structure or union incomplete: incomplete_var [31]
diff -r f539fb0a5681 -r 6c95b6b799c6 tests/usr.bin/xlint/lint1/msg_151.c
--- a/tests/usr.bin/xlint/lint1/msg_151.c Tue Mar 16 23:18:49 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_151.c Tue Mar 16 23:39:41 2021 +0000
@@ -1,7 +1,13 @@
-/* $NetBSD: msg_151.c,v 1.2 2021/02/21 09:07:58 rillig Exp $ */
+/* $NetBSD: msg_151.c,v 1.3 2021/03/16 23:39:41 rillig Exp $ */
# 3 "msg_151.c"
// Test for message: void expressions may not be arguments, arg #%d [151]
-TODO: "Add example code that triggers the above message." /* expect: 249 */
-TODO: "Add example code that almost triggers the above message."
+void sink_int(int);
+
+void
+example(int i)
+{
+ sink_int((void)i); /* expect: 151 */
+ sink_int(i);
+}
diff -r f539fb0a5681 -r 6c95b6b799c6 tests/usr.bin/xlint/lint1/msg_151.exp
--- a/tests/usr.bin/xlint/lint1/msg_151.exp Tue Mar 16 23:18:49 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_151.exp Tue Mar 16 23:39:41 2021 +0000
@@ -1,1 +1,1 @@
-msg_151.c(6): syntax error ':' [249]
+msg_151.c(11): void expressions may not be arguments, arg #1 [151]
diff -r f539fb0a5681 -r 6c95b6b799c6 tests/usr.bin/xlint/lint1/msg_152.c
--- a/tests/usr.bin/xlint/lint1/msg_152.c Tue Mar 16 23:18:49 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_152.c Tue Mar 16 23:39:41 2021 +0000
@@ -1,7 +1,15 @@
-/* $NetBSD: msg_152.c,v 1.2 2021/02/21 09:07:58 rillig Exp $ */
+/* $NetBSD: msg_152.c,v 1.3 2021/03/16 23:39:41 rillig Exp $ */
# 3 "msg_152.c"
// Test for message: argument cannot have unknown size, arg #%d [152]
-TODO: "Add example code that triggers the above message." /* expect: 249 */
-TODO: "Add example code that almost triggers the above message."
+struct incomplete; /* expect: 233 */
+
+void callee(struct incomplete); /* expect: 31 */
+
+void
+caller(void)
+{
+ struct incomplete local_var; /* expect: 31 */
+ callee(local_var); /* expect: 152 */
+}
diff -r f539fb0a5681 -r 6c95b6b799c6 tests/usr.bin/xlint/lint1/msg_152.exp
--- a/tests/usr.bin/xlint/lint1/msg_152.exp Tue Mar 16 23:18:49 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_152.exp Tue Mar 16 23:39:41 2021 +0000
@@ -1,1 +1,4 @@
-msg_152.c(6): syntax error ':' [249]
+msg_152.c(8): incomplete structure or union incomplete: <unnamed> [31]
+msg_152.c(13): incomplete structure or union incomplete: local_var [31]
+msg_152.c(14): argument cannot have unknown size, arg #1 [152]
+msg_152.c(6): warning: struct incomplete never defined [233]
diff -r f539fb0a5681 -r 6c95b6b799c6 tests/usr.bin/xlint/lint1/msg_154.c
--- a/tests/usr.bin/xlint/lint1/msg_154.c Tue Mar 16 23:18:49 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_154.c Tue Mar 16 23:39:41 2021 +0000
@@ -1,7 +1,12 @@
-/* $NetBSD: msg_154.c,v 1.2 2021/02/21 09:07:58 rillig Exp $ */
+/* $NetBSD: msg_154.c,v 1.3 2021/03/16 23:39:41 rillig Exp $ */
# 3 "msg_154.c"
// Test for message: illegal combination of %s (%s) and %s (%s), arg #%d [154]
-TODO: "Add example code that triggers the above message." /* expect: 249 */
-TODO: "Add example code that almost triggers the above message."
+void sink_int(int);
+
+void
+example(int *ptr)
+{
+ sink_int(ptr); /* expect: 154 */
+}
diff -r f539fb0a5681 -r 6c95b6b799c6 tests/usr.bin/xlint/lint1/msg_154.exp
--- a/tests/usr.bin/xlint/lint1/msg_154.exp Tue Mar 16 23:18:49 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_154.exp Tue Mar 16 23:39:41 2021 +0000
@@ -1,1 +1,1 @@
-msg_154.c(6): syntax error ':' [249]
+msg_154.c(11): warning: illegal combination of integer (int) and pointer (pointer to int), arg #1 [154]
diff -r f539fb0a5681 -r 6c95b6b799c6 tests/usr.bin/xlint/lint1/msg_157.c
--- a/tests/usr.bin/xlint/lint1/msg_157.c Tue Mar 16 23:18:49 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_157.c Tue Mar 16 23:39:41 2021 +0000
@@ -1,7 +1,10 @@
-/* $NetBSD: msg_157.c,v 1.2 2021/02/21 09:07:58 rillig Exp $ */
+/* $NetBSD: msg_157.c,v 1.3 2021/03/16 23:39:41 rillig Exp $ */
# 3 "msg_157.c"
// Test for message: ANSI C treats constant as unsigned [157]
-TODO: "Add example code that triggers the above message." /* expect: 249 */
-TODO: "Add example code that almost triggers the above message."
+/*
+ * A rather strange definition for an ARGB color.
+ * Luckily, 'double' has more than 32 significant binary digits.
+ */
+double white = 0xFFFFFFFF; /* expect: 157 */
diff -r f539fb0a5681 -r 6c95b6b799c6 tests/usr.bin/xlint/lint1/msg_157.exp
--- a/tests/usr.bin/xlint/lint1/msg_157.exp Tue Mar 16 23:18:49 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_157.exp Tue Mar 16 23:39:41 2021 +0000
@@ -1,1 +1,1 @@
-msg_157.c(6): syntax error ':' [249]
+msg_157.c(10): warning: ANSI C treats constant as unsigned [157]
diff -r f539fb0a5681 -r 6c95b6b799c6 tests/usr.bin/xlint/lint1/msg_158.c
--- a/tests/usr.bin/xlint/lint1/msg_158.c Tue Mar 16 23:18:49 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_158.c Tue Mar 16 23:39:41 2021 +0000
@@ -1,7 +1,43 @@
-/* $NetBSD: msg_158.c,v 1.2 2021/02/21 09:07:58 rillig Exp $ */
+/* $NetBSD: msg_158.c,v 1.3 2021/03/16 23:39:41 rillig Exp $ */
# 3 "msg_158.c"
// Test for message: %s may be used before set [158]
-TODO: "Add example code that triggers the above message." /* expect: 249 */
-TODO: "Add example code that almost triggers the above message."
+void sink_int(int);
+
+void
+example(int arg)
+{
+ int twice_arg;
+
+ sink_int(twice_arg); /* expect: 158 */
+ twice_arg = 2 * arg;
+ sink_int(twice_arg);
+}
+
+void
+conditionally_used(int arg)
+{
+ int twice_arg;
+
+ if (arg > 0)
+ twice_arg = 2 * arg;
+ if (arg > 0)
+ sink_int(twice_arg);
+}
+
+void
+conditionally_unused(int arg)
+{
+ int twice_arg;
+
+ if (arg > 0)
+ twice_arg = 2 * arg;
+
+ /*
+ * This situation is not detected by lint as it does not track the
+ * possible code paths for all conditions.
+ */
+ if (arg < 0)
+ sink_int(twice_arg);
+}
diff -r f539fb0a5681 -r 6c95b6b799c6 tests/usr.bin/xlint/lint1/msg_158.exp
--- a/tests/usr.bin/xlint/lint1/msg_158.exp Tue Mar 16 23:18:49 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_158.exp Tue Mar 16 23:39:41 2021 +0000
@@ -1,1 +1,1 @@
-msg_158.c(6): syntax error ':' [249]
+msg_158.c(13): warning: twice_arg may be used before set [158]
Home |
Main Index |
Thread Index |
Old Index