From 9f21ba24ebea7e74869811b23eeb778ed7d91527 Mon Sep 17 00:00:00 2001 From: "yu.dongliang" <18588496441@163.com> Date: Sat, 25 Nov 2023 23:54:13 +0800 Subject: [PATCH] fix: core dump when test 'examples/declare_vars.c' --- core/scf_3ac.c | 4 ++-- core/scf_dag.h | 2 -- examples/declare_vars.c | 13 +++++++++++++ native/x64/scf_x64_peephole.c | 2 +- parse/scf_dfa_var.c | 8 +++++++- parse/scf_parse.h | 2 ++ 6 files changed, 25 insertions(+), 6 deletions(-) create mode 100644 examples/declare_vars.c diff --git a/core/scf_3ac.c b/core/scf_3ac.c index e62d8e0..3d1ff12 100644 --- a/core/scf_3ac.c +++ b/core/scf_3ac.c @@ -881,7 +881,7 @@ static void _3ac_filter_jmp(scf_list_t* h, scf_3ac_code_t* c) c2->jmp_dst_flag = 1; break; } - +#if 0 if (SCF_OP_GOTO == c->op->type) { c->op = c2->op; @@ -893,7 +893,7 @@ static void _3ac_filter_jmp(scf_list_t* h, scf_3ac_code_t* c) l2 = &dst1->code->list; continue; } - +#endif scf_logw("c: %s, c2: %s\n", c->op->name, c2->op->name); dst0 = c->dsts->data[0]; dst0->code = c2; diff --git a/core/scf_dag.h b/core/scf_dag.h index 2afa80c..f90e9d1 100644 --- a/core/scf_dag.h +++ b/core/scf_dag.h @@ -72,8 +72,6 @@ struct scf_dn_status_s { intptr_t color; - int ret_index; - uint32_t active :1; uint32_t inited :1; uint32_t updated:1; diff --git a/examples/declare_vars.c b/examples/declare_vars.c new file mode 100644 index 0000000..cf7c5a2 --- /dev/null +++ b/examples/declare_vars.c @@ -0,0 +1,13 @@ +//第5章/setcc.c + +int printf(const char* fmt, ...); + +int main() +{ + int a = 1, b = 2, c = 3, d = 4; + + int ret = a > b && b < c || c < d; + + printf("ret: %d\n", ret); + return 0; +} diff --git a/native/x64/scf_x64_peephole.c b/native/x64/scf_x64_peephole.c index 63ec4cc..8172558 100644 --- a/native/x64/scf_x64_peephole.c +++ b/native/x64/scf_x64_peephole.c @@ -478,7 +478,7 @@ int x64_optimize_peephole(scf_native_t* ctx, scf_function_t* f) goto next; } - scf_instruction_print(inst); +// scf_instruction_print(inst); if (SCF_X64_CMP == inst->OpCode->type || SCF_X64_TEST == inst->OpCode->type) { diff --git a/parse/scf_dfa_var.c b/parse/scf_dfa_var.c index c7d634c..99e839b 100644 --- a/parse/scf_dfa_var.c +++ b/parse/scf_dfa_var.c @@ -238,6 +238,8 @@ static int _var_action_semicolon(scf_dfa_t* dfa, scf_vector_t* words, void* data dfa_parse_data_t* d = data; dfa_identity_t* id = NULL; + d->var_semicolon_flag = 0; + if (_var_add_var(dfa, d) < 0) { scf_loge("add var error\n"); return SCF_DFA_ERROR; @@ -318,7 +320,11 @@ static int _var_action_assign(scf_dfa_t* dfa, scf_vector_t* words, void* data) d->expr = e; d->expr_local_flag++; - SCF_DFA_PUSH_HOOK(scf_dfa_find_node(dfa, "var_semicolon"), SCF_DFA_HOOK_POST); + if (!d->var_semicolon_flag) { + SCF_DFA_PUSH_HOOK(scf_dfa_find_node(dfa, "var_semicolon"), SCF_DFA_HOOK_POST); + d->var_semicolon_flag = 1; + } + SCF_DFA_PUSH_HOOK(scf_dfa_find_node(dfa, "var_comma"), SCF_DFA_HOOK_POST); scf_logd("d->expr: %p\n", d->expr); diff --git a/parse/scf_parse.h b/parse/scf_parse.h index d8dc890..8ef3d05 100644 --- a/parse/scf_parse.h +++ b/parse/scf_parse.h @@ -100,6 +100,8 @@ struct dfa_parse_data_s { uint32_t static_flag:1; uint32_t inline_flag:1; + uint32_t var_semicolon_flag:1; + int nb_lbs; int nb_rbs; -- 2.25.1