Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/xlint/lint1 tests/lint: test varargs, printflike, sc...
details: https://anonhg.NetBSD.org/src/rev/063cc7fc689b
branches: trunk
changeset: 1023245:063cc7fc689b
user: rillig <rillig%NetBSD.org@localhost>
date: Mon Aug 30 19:48:21 2021 +0000
description:
tests/lint: test varargs, printflike, scanflike
diffstat:
tests/usr.bin/xlint/lint1/emit.c | 76 +++++++++++++++++++++++++++++++++-
tests/usr.bin/xlint/lint1/emit.exp-ln | 10 ++++
tests/usr.bin/xlint/lint1/msg_280.c | 59 +++++++++++++++++++++++++-
tests/usr.bin/xlint/lint1/msg_280.exp | 8 +++-
tests/usr.bin/xlint/lint1/msg_283.c | 31 ++++++++++++-
tests/usr.bin/xlint/lint1/msg_283.exp | 2 +-
usr.bin/xlint/lint1/emit1.c | 6 +-
7 files changed, 178 insertions(+), 14 deletions(-)
diffs (262 lines):
diff -r 2ded6128b468 -r 063cc7fc689b tests/usr.bin/xlint/lint1/emit.c
--- a/tests/usr.bin/xlint/lint1/emit.c Mon Aug 30 19:07:57 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/emit.c Mon Aug 30 19:48:21 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: emit.c,v 1.3 2021/08/28 16:21:24 rillig Exp $ */
+/* $NetBSD: emit.c,v 1.4 2021/08/30 19:48:21 rillig Exp $ */
# 3 "emit.c"
/*
@@ -7,8 +7,8 @@
* consistently across different translation units.
*/
-
-
+/* Do not warn about unused parameters. */
+/* lint1-extra-flags: -X 231 */
/*
* Define some derived types.
@@ -179,3 +179,73 @@
__atomic_load(ptr, &value, 0);
}
+
+/*
+ * XXX: It's strange that a function can be annotated with VARARGS even
+ * though it does not take varargs at all.
+ *
+ * This feature is not useful for modern code anyway, it focused on pre-C90
+ * code that did not have function prototypes.
+ */
+
+/* VARARGS */
+void
+varargs_comment(const char *fmt)
+{
+}
+
+/* VARARGS 0 */
+void
+varargs_0_comment(const char *fmt)
+{
+}
+
+/* VARARGS 3 */
+void
+varargs_3_comment(int a, int b, int c, const char *fmt)
+{
+}
+
+/* PRINTFLIKE */
+void
+printflike_comment(const char *fmt)
+{
+}
+
+/* PRINTFLIKE 0 */
+void
+printflike_0_comment(const char *fmt)
+{
+}
+
+/* PRINTFLIKE 3 */
+void
+printflike_3_comment(int a, int b, const char *fmt)
+{
+}
+
+/* PRINTFLIKE 10 */
+void
+printflike_10_comment(int a1, int a2, int a3, int a4, int a5,
+ int a6, int a7, int a8, int a9,
+ const char *fmt)
+{
+}
+
+/* SCANFLIKE */
+void
+scanflike_comment(const char *fmt)
+{
+}
+
+/* SCANFLIKE 0 */
+void
+scanflike_0_comment(const char *fmt)
+{
+}
+
+/* SCANFLIKE 3 */
+void
+scanflike_3_comment(int a, int b, const char *fmt)
+{
+}
diff -r 2ded6128b468 -r 063cc7fc689b tests/usr.bin/xlint/lint1/emit.exp-ln
--- a/tests/usr.bin/xlint/lint1/emit.exp-ln Mon Aug 30 19:07:57 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/emit.exp-ln Mon Aug 30 19:48:21 2021 +0000
@@ -57,3 +57,13 @@
164c0.164s2"%\a%\b%\f%\n%\r%\t%\v%\177"i9my_printff2PcCPCV
159d0.159d14cover_outqcharF0V
173d0.173d17call_gcc_builtinsF2IPLV
+193d0.193v0d15varargs_commentF1PcCV
+199d0.199v0d17varargs_0_commentF1PcCV
+205d0.205v3d17varargs_3_commentF4IIIPcCV
+211d0.211d18printflike_commentF1PcCV
+217d0.217d20printflike_0_commentF1PcCV
+223d0.223v3P3d20printflike_3_commentF3IIPcCV
+229d0.229v10P10d21printflike_10_commentF10IIIIIIIIIPcCV
+237d0.237d17scanflike_commentF1PcCV
+243d0.243d19scanflike_0_commentF1PcCV
+249d0.249v3S3d19scanflike_3_commentF3IIPcCV
diff -r 2ded6128b468 -r 063cc7fc689b tests/usr.bin/xlint/lint1/msg_280.c
--- a/tests/usr.bin/xlint/lint1/msg_280.c Mon Aug 30 19:07:57 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_280.c Mon Aug 30 19:48:21 2021 +0000
@@ -1,7 +1,60 @@
-/* $NetBSD: msg_280.c,v 1.2 2021/02/21 09:07:58 rillig Exp $ */
+/* $NetBSD: msg_280.c,v 1.3 2021/08/30 19:48:21 rillig Exp $ */
# 3 "msg_280.c"
// Test for message: must be outside function: /* %s */ [280]
-TODO: "Add example code that triggers the above message." /* expect: 249 */
-TODO: "Add example code that almost triggers the above message."
+/* VARARGS */
+void
+varargs_ok(const char *str, ...)
+{
+ (void)str;
+}
+
+void
+/* XXX: Why is this comment considered 'outside' enough? */
+varargs_bad_param(/* VARARGS */ const char *str, ...)
+{
+ /* expect+1: warning: must be outside function: */
+ /* VARARGS */
+ (void)str;
+}
+
+void
+/* expect+1: warning: must be outside function: */
+varargs_bad_ellipsis(const char *str, /* VARARGS */ ...)
+{
+ (void)str;
+}
+
+void
+/* XXX: Why is this comment considered 'outside' enough? */
+varargs_bad_body(const char *str, ...)
+{
+ /* expect+1: warning: must be outside function */
+ /* VARARGS */
+ (void)str;
+}
+
+void
+/* expect+1: warning: argument 'str' unused in function 'argsused_bad_body' [231] */
+argsused_bad_body(const char *str)
+{
+ /* expect+1: warning: must be outside function */
+ /* ARGSUSED */
+}
+
+void
+printflike_bad_body(const char *fmt, ...)
+{
+ /* expect+1: warning: must be outside function */
+ /* PRINTFLIKE */
+ (void)fmt;
+}
+
+void
+scanflike_bad_body(const char *fmt, ...)
+{
+ /* expect+1: warning: must be outside function */
+ /* SCANFLIKE */
+ (void)fmt;
+}
diff -r 2ded6128b468 -r 063cc7fc689b tests/usr.bin/xlint/lint1/msg_280.exp
--- a/tests/usr.bin/xlint/lint1/msg_280.exp Mon Aug 30 19:07:57 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_280.exp Mon Aug 30 19:48:21 2021 +0000
@@ -1,1 +1,7 @@
-msg_280.c(6): error: syntax error ':' [249]
+msg_280.c(18): warning: must be outside function: /* VARARGS */ [280]
+msg_280.c(24): warning: must be outside function: /* VARARGS */ [280]
+msg_280.c(34): warning: must be outside function: /* VARARGS */ [280]
+msg_280.c(43): warning: must be outside function: /* ARGSUSED */ [280]
+msg_280.c(40): warning: argument 'str' unused in function 'argsused_bad_body' [231]
+msg_280.c(50): warning: must be outside function: /* PRINTFLIKE */ [280]
+msg_280.c(58): warning: must be outside function: /* SCANFLIKE */ [280]
diff -r 2ded6128b468 -r 063cc7fc689b tests/usr.bin/xlint/lint1/msg_283.c
--- a/tests/usr.bin/xlint/lint1/msg_283.c Mon Aug 30 19:07:57 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_283.c Mon Aug 30 19:48:21 2021 +0000
@@ -1,7 +1,32 @@
-/* $NetBSD: msg_283.c,v 1.2 2021/02/21 09:07:58 rillig Exp $ */
+/* $NetBSD: msg_283.c,v 1.3 2021/08/30 19:48:21 rillig Exp $ */
# 3 "msg_283.c"
// Test for message: argument number mismatch with directive: /* %s */ [283]
-TODO: "Add example code that triggers the above message." /* expect: 249 */
-TODO: "Add example code that almost triggers the above message."
+/* Do not warn about unused parameters. */
+/* lint1-extra-flags: -X 231 */
+
+/* PRINTFLIKE */
+void
+printflike_comment(const char *fmt)
+{
+}
+
+/* PRINTFLIKE 0 */
+void
+printflike_0_comment(const char *fmt)
+{
+}
+
+/* PRINTFLIKE 2 */
+void
+printflike_2_comment(int a, const char *fmt)
+{
+}
+
+/* PRINTFLIKE 3 */
+void
+printflike_3_comment(int a, const char *fmt)
+/* expect+1: warning: argument number mismatch with directive */
+{
+}
diff -r 2ded6128b468 -r 063cc7fc689b tests/usr.bin/xlint/lint1/msg_283.exp
--- a/tests/usr.bin/xlint/lint1/msg_283.exp Mon Aug 30 19:07:57 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_283.exp Mon Aug 30 19:48:21 2021 +0000
@@ -1,1 +1,1 @@
-msg_283.c(6): error: syntax error ':' [249]
+msg_283.c(31): warning: argument number mismatch with directive: /* PRINTFLIKE */ [283]
diff -r 2ded6128b468 -r 063cc7fc689b usr.bin/xlint/lint1/emit1.c
--- a/usr.bin/xlint/lint1/emit1.c Mon Aug 30 19:07:57 2021 +0000
+++ b/usr.bin/xlint/lint1/emit1.c Mon Aug 30 19:48:21 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: emit1.c,v 1.51 2021/08/28 12:21:53 rillig Exp $ */
+/* $NetBSD: emit1.c,v 1.52 2021/08/30 19:48:21 rillig Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
@@ -38,7 +38,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: emit1.c,v 1.51 2021/08/28 12:21:53 rillig Exp $");
+__RCSID("$NetBSD: emit1.c,v 1.52 2021/08/30 19:48:21 rillig Exp $");
#endif
#include "lint1.h"
@@ -99,7 +99,7 @@
while (tp != NULL) {
if ((ts = tp->t_tspec) == INT && tp->t_is_enum)
ts = ENUM;
- /* Available letters: ----E-GH--K-MNO--R--U-W-YZ */
+ /* Available letters: ------GH--K-MNO--R--U-W-YZ */
switch (ts) {
case BOOL: t = 'B'; s = '\0'; break;
case CHAR: t = 'C'; s = '\0'; break;
Home |
Main Index |
Thread Index |
Old Index