linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Oleg Nesterov <oleg@redhat.com>
To: Chris Li <sparse@chrisli.org>, Luc Van Oostenryck <lucvoo@kernel.org>
Cc: Alexey Gladkov <legion@kernel.org>, linux-sparse@vger.kernel.org
Subject: [PATCH] sparse/pre-process: introduce "dissect_mode" option to fix dissect/semind
Date: Wed, 17 Dec 2025 16:17:44 +0100	[thread overview]
Message-ID: <aULJmGi8yib_XH0P@redhat.com> (raw)

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

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)

Signed-off-by: Oleg Nesterov <oleg@redhat.com>
---
 dissect.c     | 1 +
 options.c     | 1 +
 options.h     | 1 +
 pre-process.c | 8 +++++---
 4 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/dissect.c b/dissect.c
index a6003afa..5fed8e22 100644
--- a/dissect.c
+++ b/dissect.c
@@ -714,6 +714,7 @@ end:
 
 void dissect(struct reporter *rep, struct string_list *filelist)
 {
+	dissect_mode = 1;
 	reporter = rep;
 
 	DO_LIST(filelist, file, do_file(file));
diff --git a/options.c b/options.c
index 6ee4d878..0f207e80 100644
--- a/options.c
+++ b/options.c
@@ -71,6 +71,7 @@ int dump_macro_defs = 0;
 int dump_macros_only = 0;
 
 int dissect_show_all_symbols = 0;
+int dissect_mode = 0;
 
 unsigned long fdump_ir;
 int fhosted = 1;
diff --git a/options.h b/options.h
index c2a9551a..b559254d 100644
--- a/options.h
+++ b/options.h
@@ -71,6 +71,7 @@ extern int dump_macro_defs;
 extern int dump_macros_only;
 
 extern int dissect_show_all_symbols;
+extern int dissect_mode;
 
 extern unsigned long fdump_ir;
 extern int fhosted;
diff --git a/pre-process.c b/pre-process.c
index 3fb25082..64445881 100644
--- a/pre-process.c
+++ b/pre-process.c
@@ -294,9 +294,11 @@ 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;
+		if (!dissect_mode) {
+			next->pos.stream = pos->stream;
+			next->pos.line = pos->line;
+			next->pos.pos = pos->pos;
+		}
 		next->pos.newline = 0;
 		p = &next->next;
 	}
-- 
2.52.0



                 reply	other threads:[~2025-12-17 15:26 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aULJmGi8yib_XH0P@redhat.com \
    --to=oleg@redhat.com \
    --cc=legion@kernel.org \
    --cc=linux-sparse@vger.kernel.org \
    --cc=lucvoo@kernel.org \
    --cc=sparse@chrisli.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).