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] sparse/dissect: fix parsing of array designated initializers
Date: Sun, 10 May 2026 17:06:38 +0200 [thread overview]
Message-ID: <agCe_rrtrOC-DNx2@redhat.com> (raw)
dissect.c fails to parse nested designated initializers that contain array
indices. In this case do_initializer() is called recursively with type ==
EXPR_INDEX, this later calls do_expression(EXPR_IDENTIFIER).
Change the "while (m_expr->type == EXPR_IDENTIFIER)" loop to unwrap the
EXPR_INDEX expressions as well.
Minimal test-case:
struct O {
struct I { int mem; } ary[1];
} v = {
.ary[0].mem = 0,
};
Before the patch:
$ ./test-dissect TEST.c
1:8 def s O
2:16 def s I
2:24 def m I.mem int
2:31 def m O.ary struct I [1]
3:3 def v v struct O
3:3 -w- v v struct O
4:10 v -w- m O.ary struct I [1]
TEST.c:4:17: warning: bad expr->type: 25
the warning comes from do_expression(), 25 is EXPR_IDENTIFIER.
The usage of I.mem is not reported.
After the patch:
$ ./test-dissect TEST.c
1:8 def s O
2:16 def s I
2:24 def m I.mem int
2:31 def m O.ary struct I [1]
3:3 def v v struct O
3:3 -w- v v struct O
4:10 v -w- m O.ary struct I [1]
4:17 v -w- m I.mem int
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
---
dissect.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/dissect.c b/dissect.c
index da1b63c8..796b6e4d 100644
--- a/dissect.c
+++ b/dissect.c
@@ -602,6 +602,11 @@ static struct symbol *do_initializer(struct symbol *type, struct expression *exp
lookup_member(m_type, m_expr->expr_ident, m_atop));
m_expr = m_expr->ident_expression;
m_atop = NULL;
+
+ while (m_expr->type == EXPR_INDEX) {
+ m_type = base_type(m_type);
+ m_expr = m_expr->idx_expression;
+ }
}
if (m_atop) {
--
2.52.0
reply other threads:[~2026-05-10 15:06 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=agCe_rrtrOC-DNx2@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