All of lore.kernel.org
 help / color / mirror / Atom feed
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: sanitize the de-anonymization of SYM_ENUMs
Date: Sun, 4 Jan 2026 16:22:08 +0100	[thread overview]
Message-ID: <aVqFoD7JKxylHanE@redhat.com> (raw)
In-Reply-To: <aVqFaL88QonZYs63@redhat.com>

examine_sym_node() tries to de-anonymize enums just like structs,
and sometimes it makes sense:

	$ ~/tmp/sparse/test-dissect - <<<'enum { X } x;'

	   1:6                    def   E :x                               unsigned int
	   1:8                    def   e :x.X                             unsigned int enum :x
	   1:12                   def   v x                                unsigned int enum :x

But it doesn't make sense to de-anonymize enum types using the name
of its enum_member.

Test-case:

	$ cat -n ENUM_3.c
	     1	enum { A, B };
	     2	typeof(B) x = A;

	$ ./test-dissect ENUM_3.c

	   1:6                    def   E :B                               unsigned int
	   1:8                    def   e :B.A                             unsigned int enum :B
	   1:11                   def   e :B.B                             unsigned int enum :B
	   2:8                    ---   e :B.B                             unsigned int enum :B
	   2:11                   def   v x                                int
	   2:11                   -w-   v x                                int
	   2:15  x                -r-   e :B.A                             unsigned int enum :B

With this patch:

	$ ./test-dissect ENUM_3.c

	   1:8                    def   e A                                unsigned int enum <noident>
	   1:11                   def   e B                                unsigned int enum <noident>
	   2:8                    ---   e B                                unsigned int enum <noident>
	   2:11                   def   v x                                int
	   2:11                   -w-   v x                                int
	   2:15  x                -r-   e A                                unsigned int enum <noident>

Signed-off-by: Oleg Nesterov <oleg@redhat.com>
---
 dissect.c      |  5 +++--
 test-dissect.c | 13 +++++++------
 2 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/dissect.c b/dissect.c
index d36986dd..a0fda09c 100644
--- a/dissect.c
+++ b/dissect.c
@@ -245,10 +245,11 @@ static void examine_sym_node(struct symbol *node, struct symbol *parent)
 			if (toplevel(base->scope))
 				dissect_ctx = NULL;
 
-			if (base->ident || deanon(base, name, parent))
+			if (base->ident || (!node->enum_member &&
+					    deanon(base, name, parent)))
 				reporter->r_symdef(base);
 
-			if (base->ident)
+			if (base->ident || base->type == SYM_ENUM)
 				parent = base;
 			DO_LIST(base->symbol_list, mem,
 				examine_sym_node(mem, parent);
diff --git a/test-dissect.c b/test-dissect.c
index e2b8ec9d..0a7ee98c 100644
--- a/test-dissect.c
+++ b/test-dissect.c
@@ -88,19 +88,20 @@ err:
 static void r_member(unsigned mode, struct position *pos, struct symbol *sym, struct symbol *mem)
 {
 	struct ident *ni, *si, *mi;
-	int mk;
+	int mk, ms = 32;
 
 	ni = built_in_ident("?");
-	si = sym->ident ?: ni;
 	/* mem == NULL means entire struct accessed */
-	mi = mem ? (mem->ident ?: ni) : built_in_ident("*");
 	mk = mem ? mem->kind : 'm';
+	mi = mem ? (mem->ident ?: ni) : built_in_ident("*");
+	si = sym->ident ?: (mk == 'e' ? NULL : ni);
 
 	print_usage(pos, sym, mode, mk);
 
-	printf("%.*s.%-*.*s %s\n",
-		si->len, si->name,
-		32-1 - si->len, mi->len, mi->name,
+	if (si)
+		ms -= printf("%.*s.", si->len, si->name);
+
+	printf("%-*.*s %s\n", ms, mi->len, mi->name,
 		show_typename(mem ? mem->ctype.base_type : sym));
 
 	if (sym->ident && sym->kind != 's' && sym->kind != 'E')
-- 
2.52.0


      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 ` [PATCH 1/4] sparse/dissect: examine SYM_ENUM nodes Oleg Nesterov
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 ` 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=aVqFoD7JKxylHanE@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.