* [PATCH] sparse: add the new m_pos member into struct expression{EXPR_DEREF}
@ 2025-12-16 13:40 Oleg Nesterov
2026-01-16 22:55 ` Chris Li
0 siblings, 1 reply; 2+ messages in thread
From: Oleg Nesterov @ 2025-12-16 13:40 UTC (permalink / raw)
To: Chris Li, Luc Van Oostenryck; +Cc: Alexey Gladkov, linux-sparse
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
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] sparse: add the new m_pos member into struct expression{EXPR_DEREF}
2025-12-16 13:40 [PATCH] sparse: add the new m_pos member into struct expression{EXPR_DEREF} Oleg Nesterov
@ 2026-01-16 22:55 ` Chris Li
0 siblings, 0 replies; 2+ messages in thread
From: Chris Li @ 2026-01-16 22:55 UTC (permalink / raw)
To: Oleg Nesterov; +Cc: Luc Van Oostenryck, Alexey Gladkov, linux-sparse
Hi Oleg,
Applied to sparse-dev.
Chris
Chris
On Tue, Dec 16, 2025 at 5:40 AM Oleg Nesterov <oleg@redhat.com> wrote:
>
> 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
>
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-01-16 22:55 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-16 13:40 [PATCH] sparse: add the new m_pos member into struct expression{EXPR_DEREF} Oleg Nesterov
2026-01-16 22:55 ` Chris Li
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox