Module Name:    src
Committed By:   rillig
Date:           Mon Aug 30 19:48:21 UTC 2021

Modified Files:
        src/tests/usr.bin/xlint/lint1: emit.c emit.exp-ln msg_280.c msg_280.exp
            msg_283.c msg_283.exp
        src/usr.bin/xlint/lint1: emit1.c

Log Message:
tests/lint: test varargs, printflike, scanflike


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/usr.bin/xlint/lint1/emit.c
cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/xlint/lint1/emit.exp-ln
cvs rdiff -u -r1.2 -r1.3 src/tests/usr.bin/xlint/lint1/msg_280.c \
    src/tests/usr.bin/xlint/lint1/msg_280.exp \
    src/tests/usr.bin/xlint/lint1/msg_283.c \
    src/tests/usr.bin/xlint/lint1/msg_283.exp
cvs rdiff -u -r1.51 -r1.52 src/usr.bin/xlint/lint1/emit1.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/usr.bin/xlint/lint1/emit.c
diff -u src/tests/usr.bin/xlint/lint1/emit.c:1.3 src/tests/usr.bin/xlint/lint1/emit.c:1.4
--- src/tests/usr.bin/xlint/lint1/emit.c:1.3	Sat Aug 28 16:21:24 2021
+++ src/tests/usr.bin/xlint/lint1/emit.c	Mon Aug 30 19:48:21 2021
@@ -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 @@ call_gcc_builtins(int x, long *ptr)
 
 	__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)
+{
+}

Index: src/tests/usr.bin/xlint/lint1/emit.exp-ln
diff -u src/tests/usr.bin/xlint/lint1/emit.exp-ln:1.4 src/tests/usr.bin/xlint/lint1/emit.exp-ln:1.5
--- src/tests/usr.bin/xlint/lint1/emit.exp-ln:1.4	Sat Aug 28 16:36:54 2021
+++ src/tests/usr.bin/xlint/lint1/emit.exp-ln	Mon Aug 30 19:48:21 2021
@@ -57,3 +57,13 @@ Semit.c
 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

Index: src/tests/usr.bin/xlint/lint1/msg_280.c
diff -u src/tests/usr.bin/xlint/lint1/msg_280.c:1.2 src/tests/usr.bin/xlint/lint1/msg_280.c:1.3
--- src/tests/usr.bin/xlint/lint1/msg_280.c:1.2	Sun Feb 21 09:07:58 2021
+++ src/tests/usr.bin/xlint/lint1/msg_280.c	Mon Aug 30 19:48:21 2021
@@ -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;
+}
Index: src/tests/usr.bin/xlint/lint1/msg_280.exp
diff -u src/tests/usr.bin/xlint/lint1/msg_280.exp:1.2 src/tests/usr.bin/xlint/lint1/msg_280.exp:1.3
--- src/tests/usr.bin/xlint/lint1/msg_280.exp:1.2	Sun Mar 21 20:45:00 2021
+++ src/tests/usr.bin/xlint/lint1/msg_280.exp	Mon Aug 30 19:48:21 2021
@@ -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]
Index: src/tests/usr.bin/xlint/lint1/msg_283.c
diff -u src/tests/usr.bin/xlint/lint1/msg_283.c:1.2 src/tests/usr.bin/xlint/lint1/msg_283.c:1.3
--- src/tests/usr.bin/xlint/lint1/msg_283.c:1.2	Sun Feb 21 09:07:58 2021
+++ src/tests/usr.bin/xlint/lint1/msg_283.c	Mon Aug 30 19:48:21 2021
@@ -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 */
+{
+}
Index: src/tests/usr.bin/xlint/lint1/msg_283.exp
diff -u src/tests/usr.bin/xlint/lint1/msg_283.exp:1.2 src/tests/usr.bin/xlint/lint1/msg_283.exp:1.3
--- src/tests/usr.bin/xlint/lint1/msg_283.exp:1.2	Sun Mar 21 20:45:00 2021
+++ src/tests/usr.bin/xlint/lint1/msg_283.exp	Mon Aug 30 19:48:21 2021
@@ -1 +1 @@
-msg_283.c(6): error: syntax error ':' [249]
+msg_283.c(31): warning: argument number mismatch with directive: /* PRINTFLIKE */ [283]

Index: src/usr.bin/xlint/lint1/emit1.c
diff -u src/usr.bin/xlint/lint1/emit1.c:1.51 src/usr.bin/xlint/lint1/emit1.c:1.52
--- src/usr.bin/xlint/lint1/emit1.c:1.51	Sat Aug 28 12:21:53 2021
+++ src/usr.bin/xlint/lint1/emit1.c	Mon Aug 30 19:48:21 2021
@@ -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 @@ outtype(const type_t *tp)
 	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;

Reply via email to