[PATCH] sparse/dissect: fix parsing of array designated initializers
Oleg Nesterov <[email protected]> Sun, 10 May 2026 17:06:38 +0200
| Newsgroups | org.kernel.vger.linux-sparse |
|---|---|
| Message-ID | <[email protected]> |
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 <[email protected]>
---
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