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 1/4] sparse/dissect: examine SYM_ENUM nodes
Date: Sun, 4 Jan 2026 16:21:56 +0100 [thread overview]
Message-ID: <aVqFlC4sni-vU9Pw@redhat.com> (raw)
In-Reply-To: <aVqFaL88QonZYs63@redhat.com>
Test-case:
$ cat ENUM_1.c
enum X { A,B } x;
$ ./test-dissect ENUM_1.c
1:16 def v x unsigned int enum X
With this patch:
$ ./test-dissect ENUM_1.c
1:6 def E X unsigned int
1:10 def e X.A unsigned int enum X
1:12 def e X.B unsigned int enum X
1:16 def v x unsigned int enum X
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
---
dissect.c | 9 +++------
test-dissect.c | 17 +++++++++++------
2 files changed, 14 insertions(+), 12 deletions(-)
diff --git a/dissect.c b/dissect.c
index b9d4adc4..abca1805 100644
--- a/dissect.c
+++ b/dissect.c
@@ -168,9 +168,6 @@ static struct symbol *report_symbol(usage_t mode, struct expression *expr)
struct symbol *sym = expr_symbol(expr);
struct symbol *ret = base_type(sym);
- if (0 && ret->type == SYM_ENUM)
- return report_member(mode, &expr->pos, ret, expr->symbol);
-
reporter->r_symbol(fix_mode(ret, mode), &expr->pos, sym);
return ret;
@@ -195,7 +192,7 @@ static bool deanon(struct symbol *base, struct ident *node, struct symbol *paren
static void report_memdef(struct symbol *sym, struct symbol *mem)
{
- mem->kind = 'm';
+ mem->kind = sym && sym->type == SYM_ENUM ? 'e' : 'm';
if (sym && mem->ident)
reporter->r_memdef(sym, mem);
}
@@ -235,12 +232,12 @@ static void examine_sym_node(struct symbol *node, struct symbol *parent)
node = base;
break;
- case SYM_STRUCT: case SYM_UNION: //case SYM_ENUM:
+ case SYM_STRUCT: case SYM_UNION: case SYM_ENUM:
if (base->inspected)
return;
base->inspected = 1;
- base->kind = 's';
+ base->kind = base->type == SYM_ENUM ? 'E' : 's';
if (!base->symbol_list)
return;
diff --git a/test-dissect.c b/test-dissect.c
index 65b205f8..3691218d 100644
--- a/test-dissect.c
+++ b/test-dissect.c
@@ -58,13 +58,16 @@ static void r_symbol(unsigned mode, struct position *pos, struct symbol *sym)
switch (sym->kind) {
case 'd':
+ case 't':
break;
+ case 'E':
+ if (sym->type == SYM_ENUM)
+ break;
+ goto err;
case 's':
if (sym->type == SYM_STRUCT || sym->type == SYM_UNION)
break;
goto err;
- case 't':
- break;
case 'f':
if (sym->type != SYM_BAD && sym->ctype.base_type->type != SYM_FN)
goto err;
@@ -84,6 +87,7 @@ err:
static void r_member(unsigned mode, struct position *pos, struct symbol *sym, struct symbol *mem)
{
struct ident *ni, *si, *mi;
+ int mk;
print_usage(pos, sym, mode);
@@ -91,15 +95,16 @@ static void r_member(unsigned mode, struct position *pos, struct symbol *sym, st
si = sym->ident ?: ni;
/* mem == NULL means entire struct accessed */
mi = mem ? (mem->ident ?: ni) : built_in_ident("*");
+ mk = mem ? mem->kind : 'm';
- printf("%c m %.*s.%-*.*s %s\n",
- symscope(sym), si->len, si->name,
+ printf("%c %c %.*s.%-*.*s %s\n",
+ symscope(sym), mk, si->len, si->name,
32-1 - si->len, mi->len, mi->name,
show_typename(mem ? mem->ctype.base_type : sym));
- if (sym->ident && sym->kind != 's')
+ if (sym->ident && sym->kind != 's' && sym->kind != 'E')
warning(*pos, "r_member bad sym type=%d kind=%d", sym->type, sym->kind);
- if (mem && mem->kind != 'm')
+ if (mem && mem->kind != 'm' && mem->kind != 'e')
warning(*pos, "r_member bad mem->kind = %d", mem->kind);
}
--
2.52.0
next prev parent reply other threads:[~2026-01-04 15:22 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-04 15:21 [PATCH 0/4] sparse/dissect: handle SYM_ENUM Oleg Nesterov
2026-01-04 15:21 ` Oleg Nesterov [this message]
2026-01-04 15:22 ` [PATCH 2/4] sparse/dissect: report the usage of enumerators Oleg Nesterov
2026-01-04 15:22 ` [PATCH 3/4] sparse/dissect: shift symscope() callsites into print_usage() Oleg Nesterov
2026-01-04 15:22 ` [PATCH 4/4] sparse/dissect: sanitize the de-anonymization of SYM_ENUMs Oleg Nesterov
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=aVqFlC4sni-vU9Pw@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 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.