sparse/dissect: fix parsing of array designated initializers
PATCH 1/1 sparse/dissect: fix parsing of array designated initializers
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: 25the 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 intSigned-off-by Oleg Nesterov <[email protected]>
--- dissect.c | 5 +++++ 1 file changed, 5 insertions(+)
dissect.c +5 -0
@@ -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) {
Signature · 1 line
2.52.0