sparse/dissect: change do_symbol(sym) to use sym->definition
PATCH 1/1 sparse/dissect: change do_symbol(sym) to use sym->definition
Test-case:
$ cat TEST.c
static inline void i_func(void) { FUNC(); }
static inline void i_func(void);
void func(void) { i_func(); }$ ./test-dissect TEST.c
3:6 def f func void ( ... ) 2:20 def f i_func void ( ... ) 3:19 func --r f i_func void ( ... )
dissect reports the wrong position for the definition of i_func() and doesn't inspect its body.
This is because the 2nd external_declaration() binds another SYM_NODE to the same ident and lookup_symbol() called during parsing returns the most recent one, which is then used by do_symbol().
With this patch:
$ ./test-dissect TEST.c
3:6 def f func void ( ... ) 1:20 def f i_func void ( ... ) 1:35 i_func --r f FUNC bad type 3:19 func --r f i_func void ( ... )
Signed-off-by Oleg Nesterov <[email protected]>
--- dissect.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
dissect.c +6 -1
@@ -630,12 +630,17 @@ static inline bool is_typedef(struct symbol *sym)return (sym->namespace ==NS_TYPEDEF ); } -static struct symbol *do_symbol (struct symbol *sym) +static struct symbol *do_symbol (struct symbol *__sym) { +struct symbol *sym = __sym->definition ?: __sym;struct symbol *type =base_type (sym);struct symbol *dctx = dissect_ctx;struct statement *stmt; +if (sym->inspected) +return type; + sym->inspected =1 ; + reporter->r_symdef (sym);switch (type->type) {
Signature · 1 line
2.52.0