[PATCH] sparse/dissect: fix missing definitions for unnamed members of named types
Oleg Nesterov <[email protected]> Thu, 4 Jun 2026 15:52:51 +0200
| Newsgroups | org.kernel.vger.linux-sparse |
|---|---|
| Message-ID | <[email protected]> |
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 <[email protected]>
---
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