All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] sparse/dissect: fix missing definitions for unnamed members of named types
@ 2026-06-04 13:52 Oleg Nesterov
  0 siblings, 0 replies; only message in thread
From: Oleg Nesterov @ 2026-06-04 13:52 UTC (permalink / raw)
  To: Chris Li, Luc Van Oostenryck; +Cc: Alexey Gladkov, linux-sparse

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



^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-06-04 13:52 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-04 13:52 [PATCH] sparse/dissect: fix missing definitions for unnamed members of named types Oleg Nesterov

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.