Linux SPARSE checker discussions
 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: fix missing definitions for unnamed members of named types
Date: Thu, 4 Jun 2026 15:52:51 +0200	[thread overview]
Message-ID: <aiGDM56DNkolOPPX@redhat.com> (raw)

Now that the Linux kernel is built with -fms-extensions, people use
this feature more and more often. However, dissect.c doesn't report
the definitions of members promoted from unnamed fields of named types.

This means, for example, that

	$ semind search -m def ns_common.ns_id

fails without this change.

Minimal test-case:

	union U { int i; };

	struct S { union U; } v = { .i = 0 };

Before the patch:

   3:8                    def   s S
   1:7                    def   s U
   1:15                   def   m U.i                              int
   3:23                   def   v v                                struct S
   3:23                   -w-   v v                                struct S
   3:30  v                -w-   m S.i                              int

After the patch:

   3:8                    def   s S
   1:7                    def   s U
   1:15                   def   m U.i                              int
   3:19                   def   m S.i                              int
   3:23                   def   v v                                struct S
   3:23                   -w-   v v                                struct S
   3:30  v                -w-   m S.i                              int

Signed-off-by: Oleg Nesterov <oleg@redhat.com>
---
 dissect.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/dissect.c b/dissect.c
index 796b6e4d..04ec89ca 100644
--- a/dissect.c
+++ b/dissect.c
@@ -193,8 +193,19 @@ static bool deanon(struct symbol *base, struct ident *node, struct symbol *paren
 static void report_memdef(struct symbol *sym, struct symbol *mem)
 {
 	mem->kind = sym && sym->type == SYM_ENUM ? 'e' : 'm';
-	if (sym && mem->ident)
+	if (!sym)
+		return;
+	else if (mem->ident)
 		reporter->r_memdef(sym, mem);
+	else {
+		struct symbol *base = mem->ctype.base_type;
+		if (base->ident == sym->ident) // deanon()'ed
+			return;
+		// base->inspected is T, we can override ->pos
+		DO_LIST(base->symbol_list, __mem,
+			__mem->pos = mem->pos;
+			report_memdef(sym, __mem));
+	}
 }
 
 static void examine_sym_node(struct symbol *node, struct symbol *parent)
-- 
2.52.0



                 reply	other threads:[~2026-06-04 13:52 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=aiGDM56DNkolOPPX@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