Module Name:    src
Committed By:   rillig
Date:           Sun Sep  5 19:16:38 UTC 2021

Modified Files:
        src/tests/usr.bin/xlint: check-expect.lua
        src/tests/usr.bin/xlint/lint1: msg_280.c msg_280.exp

Log Message:
tests/lint: document placement of lint comments


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/tests/usr.bin/xlint/check-expect.lua
cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/xlint/lint1/msg_280.c \
    src/tests/usr.bin/xlint/lint1/msg_280.exp

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/check-expect.lua
diff -u src/tests/usr.bin/xlint/check-expect.lua:1.12 src/tests/usr.bin/xlint/check-expect.lua:1.13
--- src/tests/usr.bin/xlint/check-expect.lua:1.12	Sat Aug 21 07:49:48 2021
+++ src/tests/usr.bin/xlint/check-expect.lua	Sun Sep  5 19:16:37 2021
@@ -1,5 +1,5 @@
 #!  /usr/bin/lua
--- $NetBSD: check-expect.lua,v 1.12 2021/08/21 07:49:48 rillig Exp $
+-- $NetBSD: check-expect.lua,v 1.13 2021/09/05 19:16:37 rillig Exp $
 
 --[[
 
@@ -105,10 +105,11 @@ local function check_test(c_fname, error
 
   for _, act in ipairs(messages) do
     local exp = comments_by_location[act.location] or {}
+    local exp_comment = act.message:gsub("/%*", "**"):gsub("%*/", "**")
 
     local found = false
     for i, message in ipairs(exp) do
-      if message ~= "" and act.message:find(message, 1, true) then
+      if message ~= "" and exp_comment:find(message, 1, true) then
         exp[i] = ""
         found = true
         break
@@ -116,7 +117,7 @@ local function check_test(c_fname, error
     end
 
     if not found then
-      errors:add("error: %s: missing /* expect+1: %s */", act.location, act.message)
+      errors:add("error: %s: missing /* expect+1: %s */", act.location, exp_comment)
     end
   end
 

Index: src/tests/usr.bin/xlint/lint1/msg_280.c
diff -u src/tests/usr.bin/xlint/lint1/msg_280.c:1.4 src/tests/usr.bin/xlint/lint1/msg_280.c:1.5
--- src/tests/usr.bin/xlint/lint1/msg_280.c:1.4	Sun Sep  5 18:39:58 2021
+++ src/tests/usr.bin/xlint/lint1/msg_280.c	Sun Sep  5 19:16:37 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: msg_280.c,v 1.4 2021/09/05 18:39:58 rillig Exp $	*/
+/*	$NetBSD: msg_280.c,v 1.5 2021/09/05 19:16:37 rillig Exp $	*/
 # 3 "msg_280.c"
 
 // Test for message: must be outside function: /* %s */ [280]
@@ -10,25 +10,42 @@ varargs_ok(const char *str, ...)
 	(void)str;
 }
 
+/*
+ * In the following example, the comment looks misplaced, but lint does not
+ * warn about it.
+ *
+ * This is due to the implementation of the parser and the C grammar.  When
+ * the parser sees the token T_LPAREN, it has to decide whether the following
+ * tokens will form a parameter type list or an identifier list.  For that,
+ * it needs to look at the next token to see whether it is a T_NAME (in which
+ * case the T_LPAREN belongs to an id_list_lparen) or something else (in
+ * which case the T_LPAREN belongs to an abstract_decl_lparen).  This token
+ * lookahead happens just before either of these grammar rules is reduced.
+ * During that reduction, the current declaration context switches from
+ * 'extern' to 'prototype argument', which makes this exact position the very
+ * last possible.  Everything later would already be in the wrong context.
+ *
+ * As of cgram.y 1.360 from 2021-09-04, the implementation of these grammar
+ * rules is exactly the same, which makes it tempting to join them into a
+ * single rule.
+ */
 void
-/* XXX: Why is this comment considered 'outside' enough? */
 varargs_bad_param(/* VARARGS */ const char *str, ...)
 {
 	(void)str;
 }
 
 void
-/* expect+1: warning: must be outside function: */
+/* expect+1: warning: must be outside function: ** VARARGS ** [280] */
 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 */
+	/* expect+1: warning: must be outside function: ** VARARGS ** [280] */
 	/* VARARGS */
 	(void)str;
 }
@@ -37,14 +54,14 @@ 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 */
+	/* expect+1: warning: must be outside function: ** ARGSUSED ** [280] */
 	/* ARGSUSED */
 }
 
 void
 printflike_bad_body(const char *fmt, ...)
 {
-	/* expect+1: warning: must be outside function */
+	/* expect+1: warning: must be outside function: ** PRINTFLIKE ** [280] */
 	/* PRINTFLIKE */
 	(void)fmt;
 }
@@ -52,7 +69,7 @@ printflike_bad_body(const char *fmt, ...
 void
 scanflike_bad_body(const char *fmt, ...)
 {
-	/* expect+1: warning: must be outside function */
+	/* expect+1: warning: must be outside function: ** SCANFLIKE ** [280] */
 	/* 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.4 src/tests/usr.bin/xlint/lint1/msg_280.exp:1.5
--- src/tests/usr.bin/xlint/lint1/msg_280.exp:1.4	Sun Sep  5 18:39:58 2021
+++ src/tests/usr.bin/xlint/lint1/msg_280.exp	Sun Sep  5 19:16:37 2021
@@ -1,6 +1,6 @@
-msg_280.c(22): warning: must be outside function: /* VARARGS */ [280]
-msg_280.c(32): warning: must be outside function: /* VARARGS */ [280]
-msg_280.c(41): warning: must be outside function: /* ARGSUSED */ [280]
-msg_280.c(38): warning: argument 'str' unused in function 'argsused_bad_body' [231]
-msg_280.c(48): warning: must be outside function: /* PRINTFLIKE */ [280]
-msg_280.c(56): warning: must be outside function: /* SCANFLIKE */ [280]
+msg_280.c(40): warning: must be outside function: /* VARARGS */ [280]
+msg_280.c(49): warning: must be outside function: /* VARARGS */ [280]
+msg_280.c(58): warning: must be outside function: /* ARGSUSED */ [280]
+msg_280.c(55): warning: argument 'str' unused in function 'argsused_bad_body' [231]
+msg_280.c(65): warning: must be outside function: /* PRINTFLIKE */ [280]
+msg_280.c(73): warning: must be outside function: /* SCANFLIKE */ [280]

Reply via email to