public inbox for linux-sparse@vger.kernel.org
 help / color / mirror / Atom feed
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/dissect: change do_symbol(sym) to use sym->definition
Date: Sun, 11 Jan 2026 18:28:26 +0100	[thread overview]
Message-ID: <aWPduv1ewBCFVn5w@redhat.com> (raw)

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 <oleg@redhat.com>
---
 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



                 reply	other threads:[~2026-01-11 17:28 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=aWPduv1ewBCFVn5w@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