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: add the new m_pos member into struct expression{EXPR_DEREF}
Date: Tue, 16 Dec 2025 14:40:15 +0100 [thread overview]
Message-ID: <aUFhP-rIwC-iNJ5s@redhat.com> (raw)
Test-case:
$ cat -n MEMPOS.c
1 struct T {
2 int mem;
3 } X;
4
5 void func(struct T *x)
6 {
7 x -> mem = 1;
8 X . mem = 2;
9 }
$ ./test-dissect MEMPOS.c | grep -F T.mem
2:6 def m T.mem int
7:4 func -w- m T.mem int
8:4 func -w- m T.mem int
Note that the reported position of .mem usage is wrong. This is because
do_expression(EXPR_DEREF) uses &expr->pos which is position of TOKEN_SPECIAL,
not the position of the next token (mem).
This also breaks "semind search -l" (search by location)
$ ./semind add MEMPOS.c
$ ./semind search -l MEMPOS.c:7:7
reports nothing.
With this patch:
$ ./test-dissect MEMPOS.c | grep -F T.mem
2:6 def m T.mem int
7:7 func -w- m T.mem int
8:7 func -w- m T.mem int
$ ./semind add MEMPOS.c
$ ./semind search -l MEMPOS.c:7:7
(def) MEMPOS.c 2 6 int mem;
(-w-) MEMPOS.c 7 7 func x -> mem = 1;
(-w-) MEMPOS.c 8 7 func X . mem = 2;
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
---
dissect.c | 2 +-
expression.c | 1 +
expression.h | 1 +
3 files changed, 3 insertions(+), 1 deletion(-)
diff --git a/dissect.c b/dissect.c
index 9419c593..a6003afa 100644
--- a/dissect.c
+++ b/dissect.c
@@ -454,7 +454,7 @@ again:
p_mode = U_R_VAL;
p_type = do_expression(p_mode, expr->deref);
- ret = report_member(mode, &expr->pos, p_type,
+ ret = report_member(mode, &expr->m_pos, p_type,
lookup_member(p_type, expr->member, NULL));
}
diff --git a/expression.c b/expression.c
index 727e7056..b23107da 100644
--- a/expression.c
+++ b/expression.c
@@ -605,6 +605,7 @@ static struct token *postfix_expression(struct token *token, struct expression *
break;
}
deref->member = token->ident;
+ deref->m_pos = token->pos;
token = token->next;
expr = deref;
continue;
diff --git a/expression.h b/expression.h
index 8bf40d32..ce8a29ce 100644
--- a/expression.h
+++ b/expression.h
@@ -202,6 +202,7 @@ struct expression {
struct /* deref_arg */ {
struct expression *deref;
struct ident *member;
+ struct position m_pos;
};
// EXPR_SLICE
struct /* slice */ {
--
2.52.0
next reply other threads:[~2025-12-16 13:40 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-16 13:40 Oleg Nesterov [this message]
2026-01-16 22:55 ` [PATCH] sparse: add the new m_pos member into struct expression{EXPR_DEREF} Chris Li
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=aUFhP-rIwC-iNJ5s@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