sparse: add the new m_pos member into struct expression{EXPR_DEREF}
PATCH 1/1 sparse: add the new m_pos member into struct expression{EXPR_DEREF}
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 <[email protected]>
--- dissect.c | 2 +- expression.c | 1 + expression.h | 1 + 3 files changed, 3 insertions(+), 1 deletion(-)
dissect.c +1 -1
@@ -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 )); }
expression.c +1 -0
@@ -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 ;
expression.h +1 -0
@@ -202,6 +202,7 @@ struct expression {struct /* deref_arg */ {struct expression *deref;struct ident *member; +struct position m_pos; };// EXPR_SLICE struct /* slice */ {
Signature · 1 line
2.52.0
Hi Oleg,
Applied to sparse-dev.
Chris
Chris
Quoted 91 lines · Oleg Nesterov
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 intNote that the reported position of .mem usage is wrong. This is because
do_expression(EXPR_DEREF)uses&expr->poswhich is position ofTOKEN_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:7reports 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 <[email protected]>--- dissect.c | 2 +- expression.c | 1 + expression.h | 1 + 3 files changed, 3 insertions(+), 1 deletion(-)dissect.c +1
-1@@ -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 )); }expression.c +1
-0@@ -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 ;expression.h +1
-1@@ -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