public inbox for linux-sparse@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] sparse/pre-process: don't update next->pos in collect_arg()
@ 2026-01-18 14:55 Oleg Nesterov
  0 siblings, 0 replies; only message in thread
From: Oleg Nesterov @ 2026-01-18 14:55 UTC (permalink / raw)
  To: Chris Li, Luc Van Oostenryck; +Cc: Alexey Gladkov, linux-sparse

I don't quite understand why the expand() -> collect_arg() path
updates ->pos for each token in the input *list, but this breaks
dissect and thus semind.

Change collect_arg() to update next->pos only if "preprocess_only"
is true, the "if (preprocess_only)" block in sparse_tokenstream()
relies on the current behaviour.

Test-case:

	$ cat -n PP_POS.c
	     1	#define READ_ONCE(x) x
	     2	#define WRITE_ONCE(x, y) x = y
	     3
	     4	int R, W;
	     5
	     6	void func(void)
	     7	{
	     8	  WRITE_ONCE(
	     9	     W,
	    10	     READ_ONCE(R)
	    11	  );
	    12	}

	$ ./test-dissect PP_POS.c
	   4:5                    def   v R                                int
	   4:8                    def   v W                                int
	   6:6                    def   f func                             void ( ... )
	   8:3   func             -w-   v W                                int
	   8:3   func             -r-   v R                                int

The reported positions of the usage of R and W are wrong, and thus
./semind doesn't work:

	$ ./semind add PP_POS.c
	$ ./semind search -l PP_POS.c:10:16

With this patch:

	$ ./test-dissect PP_POS.c
	   4:5                    def   v R                                int
	   4:8                    def   v W                                int
	   6:6                    def   f func                             void ( ... )
	   9:6   func             -w-   v W                                int
	  10:16  func             -r-   v R                                int

	$ ./semind add PP_POS.c
	$ ./semind search -l PP_POS.c:10:16
	(def) PP_POS.c	4	5		int R, W;
	(-r-) PP_POS.c	10	16	func	READ_ONCE(R)

See also the changes in validation/parsing/attr-cleanup.c and
validation/sizeof-void.c, the updated positions look more correct.

Suggested-by: Chris Li <sparse@chrisli.org>
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
---
 pre-process.c                     | 9 ++++++---
 validation/parsing/attr-cleanup.c | 2 +-
 validation/sizeof-void.c          | 2 +-
 3 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/pre-process.c b/pre-process.c
index 3fb25082..5ab4810d 100644
--- a/pre-process.c
+++ b/pre-process.c
@@ -294,9 +294,12 @@ static struct token *collect_arg(struct token *prev, int vararg, struct position
 		} else if (match_op(next, ',') && !nesting && !vararg) {
 			break;
 		}
-		next->pos.stream = pos->stream;
-		next->pos.line = pos->line;
-		next->pos.pos = pos->pos;
+		/* See "if (preprocess_only)" in sparse_tokenstream() */
+		if (preprocess_only) {
+			next->pos.stream = pos->stream;
+			next->pos.line = pos->line;
+			next->pos.pos = pos->pos;
+		}
 		next->pos.newline = 0;
 		p = &next->next;
 	}
diff --git a/validation/parsing/attr-cleanup.c b/validation/parsing/attr-cleanup.c
index ac64649c..fa3cb1ca 100644
--- a/validation/parsing/attr-cleanup.c
+++ b/validation/parsing/attr-cleanup.c
@@ -24,7 +24,7 @@ int test(int n)
  * check-command: sparse -Wunknown-attribute $file
  *
  * check-error-start
-parsing/attr-cleanup.c:10:17: error: argument is not an identifier
+parsing/attr-cleanup.c:10:27: error: argument is not an identifier
 parsing/attr-cleanup.c:11:39: error: an argument is expected for attribute 'cleanup'
 parsing/attr-cleanup.c:12:40: error: an argument is expected for attribute 'cleanup'
 parsing/attr-cleanup.c:13:43: error: Expected ) after attribute's argument'
diff --git a/validation/sizeof-void.c b/validation/sizeof-void.c
index 0fd917a2..6792ff02 100644
--- a/validation/sizeof-void.c
+++ b/validation/sizeof-void.c
@@ -36,7 +36,7 @@ sizeof-void.c:16:14: warning: expression using sizeof(void)
 sizeof-void.c:17:14: warning: expression using sizeof(void)
 sizeof-void.c:18:14: warning: expression using sizeof(void)
 sizeof-void.c:19:14: warning: expression using sizeof(void)
-sizeof-void.c:20:14: warning: expression using sizeof(void)
+sizeof-void.c:20:27: warning: expression using sizeof(void)
 sizeof-void.c:21:14: warning: expression using sizeof(void)
 sizeof-void.c:22:14: warning: expression using sizeof(void)
 sizeof-void.c:23:14: warning: expression using sizeof(void)
-- 
2.52.0



^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-01-18 14:55 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-18 14:55 [PATCH] sparse/pre-process: don't update next->pos in collect_arg() Oleg Nesterov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox