From 253e01ff2eba44cae1ca23bde2438082209fbd0d Mon Sep 17 00:00:00 2001 From: "yu.dongliang" <18588496441@163.com> Date: Fri, 1 Aug 2025 21:23:21 +0800 Subject: [PATCH] fix: struct array run core dump --- examples/struct_array.c | 20 ++++++++++++++++++++ native/x64/scf_x64_inst.c | 2 +- parse/scf_operator_handler_expr.c | 2 +- 3 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 examples/struct_array.c diff --git a/examples/struct_array.c b/examples/struct_array.c new file mode 100644 index 0000000..06b6143 --- /dev/null +++ b/examples/struct_array.c @@ -0,0 +1,20 @@ +int printf(const char* fmt, ...); + +struct A { + int x; +}; + +struct B +{ + A a[2]; +}; + +B b = { + {{1}, {2}} +}; + +int main() +{ + printf("%d\n", b.a[0].x); + return 0; +} diff --git a/native/x64/scf_x64_inst.c b/native/x64/scf_x64_inst.c index be69b2e..9854380 100644 --- a/native/x64/scf_x64_inst.c +++ b/native/x64/scf_x64_inst.c @@ -1049,7 +1049,7 @@ static int _x64_inst_array_index(scf_native_t* ctx, scf_3ac_code_t* c, int lea_f return ret; } - if (vb->nb_dimentions > 1 || lea_flag) { + if (vb->nb_dimentions > 1 || (vb->type >= SCF_STRUCT && 0 == vb->nb_pointers) || lea_flag) { OpCode = x64_find_OpCode(SCF_X64_LEA, rd->bytes, rd->bytes, SCF_X64_E2G); } else { diff --git a/parse/scf_operator_handler_expr.c b/parse/scf_operator_handler_expr.c index d5f6437..62faa07 100644 --- a/parse/scf_operator_handler_expr.c +++ b/parse/scf_operator_handler_expr.c @@ -105,7 +105,7 @@ static int _scf_op_expr_array_index(scf_ast_t* ast, scf_node_t** nodes, int nb_n return -EINVAL; } - if (!v0->const_literal_flag) { + if (!v0->const_literal_flag && !v0->member_flag) { scf_loge("\n"); return -EINVAL; } -- 2.25.1