[PATCH 4/4] sparse/dissect: fix missing usage reports for unnamed members of named types
Oleg Nesterov <[email protected]> Fri, 5 Jun 2026 16:56:53 +0200
| Newsgroups | org.kernel.vger.linux-sparse |
|---|---|
| Message-ID | <[email protected]> |
With the recent change, dissect.c correctly reports the definitions of the
promoted members, but it still doesn't report the usages of the underlying
members.
This means, for example, that
$ semind search -m r ns_tree.ns_id
finds nothing without this change.
Minimal (same) test-case:
union U { int i; };
struct S { union U; } v = { .i = 0 };
Before the patch:
$ test-dissect TEST.c
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
The usage of U.i is not reported.
After the patch:
$ test-dissect TEST.c
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 U.i int
3:30 v -w- m S.i int
Signed-off-by: Oleg Nesterov <[email protected]>
---
dissect.c | 24 ++++++++++++++++++++++--
1 file changed, 22 insertions(+), 2 deletions(-)
diff --git a/dissect.c b/dissect.c
index 3da9e3a2..2358297b 100644
--- a/dissect.c
+++ b/dissect.c
@@ -286,8 +286,19 @@ static struct symbol *base_type(struct symbol *sym)
struct lookup_args {
struct ident *name;
int *p_addr;
+ struct position pos;
+ struct symbol *stack[8];
+ unsigned int depth;
};
+static inline void lookup_push(struct lookup_args *la, struct symbol *type)
+{
+ if (la->depth == ARRAY_SIZE(la->stack))
+ warning(la->pos, "lookup stack overflow");
+ else
+ la->stack[la->depth++] = type;
+}
+
static struct symbol *lookup_member(struct symbol *type, struct lookup_args *la)
{
struct symbol *node;
@@ -299,9 +310,13 @@ static struct symbol *lookup_member(struct symbol *type, struct lookup_args *la)
return node;
}
else if (node->ident == NULL) {
- node = lookup_member(node->ctype.base_type, la);
- if (node)
+ struct symbol *base = node->ctype.base_type;
+ node = lookup_member(base, la);
+ if (node) {
+ if (type->ident != base->ident)
+ lookup_push(la, base);
goto found;
+ }
}
else if (node->ident == la->name) {
found: if (la->p_addr)
@@ -321,6 +336,8 @@ static struct symbol *find_report_member(usage_t mode, struct position *pos,
struct lookup_args la = {
.name = name,
.p_addr = p_addr,
+ .pos = *pos,
+ .depth = 0,
};
struct symbol *mem = lookup_member(type, &la);
@@ -338,6 +355,9 @@ static struct symbol *find_report_member(usage_t mode, struct position *pos,
mem->ident = name;
}
+ while (la.depth)
+ report_member(mode, pos, la.stack[--la.depth], mem);
+
return report_member(mode, pos, type, mem);
}
--
2.52.0