[PATCH] sparse/dissect: change do_symbol(sym) to use sym->definition

Oleg Nesterov <[email protected]> Sun, 11 Jan 2026 18:28:26 +0100
Newsgroups org.kernel.vger.linux-sparse
Message-ID <[email protected]>
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(-)

diff --git a/dissect.c b/dissect.c
index a0fda09c..f20522f0 100644
--- a/dissect.c
+++ b/dissect.c
@@ -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) {
-- 
2.52.0