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 2/4] sparse/dissect: report the usage of enumerators
Date: Sun, 4 Jan 2026 16:22:00 +0100	[thread overview]
Message-ID: <aVqFmM1ILcca3e6l@redhat.com> (raw)
In-Reply-To: <aVqFaL88QonZYs63@redhat.com>

Test-case:

	$ cat ENUM_2.c
	enum X { A, B };
	typeof(A) x = B;

	$ ./test-dissect ENUM_2.c

	   2:11                   def   v x                                int
	   2:11                   -w-   v x                                int

With this patch:

	$ ./test-dissect ENUM_2.c

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

Signed-off-by: Oleg Nesterov <oleg@redhat.com>
---
 dissect.c    | 6 +++++-
 expression.c | 3 +++
 expression.h | 1 +
 3 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/dissect.c b/dissect.c
index abca1805..d36986dd 100644
--- a/dissect.c
+++ b/dissect.c
@@ -345,9 +345,13 @@ again:
 		warning(expr->pos, "bad expr->type: %d", expr->type);
 
 	case EXPR_TYPE:		// [struct T]; Why ???
-	case EXPR_VALUE:
 	case EXPR_FVALUE:
 
+	break; case EXPR_VALUE:
+		if (expr->flags & CEF_ENUM)
+			report_member(mode, &expr->pos,
+				base_type(expr->enum_node), expr->enum_node);
+
 	break; case EXPR_LABEL:
 		ret = &label_ctype;
 
diff --git a/expression.c b/expression.c
index b23107da..573358e3 100644
--- a/expression.c
+++ b/expression.c
@@ -479,6 +479,9 @@ struct token *primary_expression(struct token *token, struct expression **tree)
 			/* we want the right position reported, thus the copy */
 			expr->pos = token->pos;
 			expr->flags = CEF_SET_ENUM;
+			// enum { X = bad } results in EXPR_SYMBOL
+			if (expr->type == EXPR_VALUE)
+				expr->enum_node = sym;
 			token = next;
 			break;
 		}
diff --git a/expression.h b/expression.h
index ce8a29ce..b7abff15 100644
--- a/expression.h
+++ b/expression.h
@@ -167,6 +167,7 @@ struct expression {
 		// EXPR_VALUE
 		struct {
 			unsigned long long value;
+			struct symbol *enum_node;
 			unsigned taint;
 		};
 
-- 
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 ` Oleg Nesterov [this message]
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=aVqFmM1ILcca3e6l@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.