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 4/4] sparse/dissect: fix missing usage reports for unnamed members of named types
Date: Fri, 5 Jun 2026 16:56:53 +0200 [thread overview]
Message-ID: <aiLjtfbosMDLSux5@redhat.com> (raw)
In-Reply-To: <aiLjjDwKRB1UjNcs@redhat.com>
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 <oleg@redhat.com>
---
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
prev parent reply other threads:[~2026-06-05 14:57 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-05 14:56 [PATCH 0/4] sparse/dissect: fix missing usage reports for unnamed members of named types Oleg Nesterov
2026-06-05 14:56 ` [PATCH 1/4] sparse/dissect: introduce find_report_member() Oleg Nesterov
2026-06-05 14:56 ` [PATCH 2/4] sparse/dissect: fold lookup_member() into find_report_member() Oleg Nesterov
2026-06-05 14:56 ` [PATCH 3/4] sparse/dissect: introduce struct lookup_args for lookup_member() Oleg Nesterov
2026-06-05 14:56 ` Oleg Nesterov [this message]
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=aiLjtfbosMDLSux5@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