From 6ea9757096d63320ed02cb489569b533cf2d5727 Mon Sep 17 00:00:00 2001 From: "yu.dongliang" <18588496441@163.com> Date: Tue, 13 Jun 2023 18:43:13 +0800 Subject: [PATCH] fix: core dump of 'while (i < 10); ' and 'for(i = 0; i < 1000; i++);' --- core/scf_core_types.h | 5 +++-- lex/scf_lex.c | 1 + native/x64/scf_x64_bb_color.c | 2 +- native/x64/scf_x64_reg.c | 5 ++++- parse/scf_dfa_for.c | 3 +++ parse/scf_parse.c | 14 ++++++++------ 6 files changed, 20 insertions(+), 10 deletions(-) diff --git a/core/scf_core_types.h b/core/scf_core_types.h index 6c48bfc..f698305 100644 --- a/core/scf_core_types.h +++ b/core/scf_core_types.h @@ -175,7 +175,7 @@ enum scf_core_types { SCF_OP_3AC_JB, SCF_OP_3AC_JBE, - SCF_OP_3AC_PUSH, // push a var to stack, only for 3ac & native + SCF_OP_3AC_PUSH, // push a var to stack, only for 3ac & native SCF_OP_3AC_POP, // pop a var from stack, only for 3ac & native SCF_OP_3AC_PUSH_RAX, // push rax, only for 3ac & native @@ -205,6 +205,7 @@ enum scf_core_types { // 122 SCF_VAR_U8, SCF_VAR_VOID, + SCF_VAR_BIT, SCF_VAR_U16, SCF_VAR_U32, SCF_VAR_U64, @@ -216,7 +217,7 @@ enum scf_core_types { SCF_VAR_DOUBLE, // double variable - SCF_LABEL, // label + SCF_LABEL, // label SCF_FUNCTION, // function diff --git a/lex/scf_lex.c b/lex/scf_lex.c index 3fbd2f7..005b9f9 100644 --- a/lex/scf_lex.c +++ b/lex/scf_lex.c @@ -33,6 +33,7 @@ static scf_lex_key_word_t key_words[] = { {"int", SCF_LEX_WORD_KEY_INT}, {"float", SCF_LEX_WORD_KEY_FLOAT}, {"double", SCF_LEX_WORD_KEY_DOUBLE}, + {"bit", SCF_LEX_WORD_KEY_BIT}, {"int8_t", SCF_LEX_WORD_KEY_INT8}, {"int16_t", SCF_LEX_WORD_KEY_INT16}, diff --git a/native/x64/scf_x64_bb_color.c b/native/x64/scf_x64_bb_color.c index 011d170..16ce76d 100644 --- a/native/x64/scf_x64_bb_color.c +++ b/native/x64/scf_x64_bb_color.c @@ -239,7 +239,7 @@ int x64_load_bb_colors(scf_basic_block_t* bb, scf_bb_group_t* bbg, scf_function_ for (j = 0; j < bb->prevs->size; j++) { prev = bb->prevs->data[j]; - if (prev->index > bb->index) + if (prev->index >= bb->index) continue; for (k = 0; k < prev->dn_colors_exit->size; k++) { diff --git a/native/x64/scf_x64_reg.c b/native/x64/scf_x64_reg.c index ce11deb..5f893f7 100644 --- a/native/x64/scf_x64_reg.c +++ b/native/x64/scf_x64_reg.c @@ -465,7 +465,10 @@ int x64_save_var2(scf_dag_node_t* dn, scf_register_t* r, scf_3ac_code_t* c, scf_ assert(var_size == r->bytes); if (scf_variable_const(v)) { - scf_logw("const literal var: v_%s_%d_%d not save\n", v->w->text->data, v->w->line, v->w->pos); + if (v->w) + scf_logw("const literal var: v_%s_%d_%d not save\n", v->w->text->data, v->w->line, v->w->pos); + else + scf_logw("const literal var: v_%#lx not save\n", 0xffff & (uintptr_t)v); goto end; } diff --git a/parse/scf_dfa_for.c b/parse/scf_dfa_for.c index c5f203a..7ec70b4 100644 --- a/parse/scf_dfa_for.c +++ b/parse/scf_dfa_for.c @@ -284,6 +284,9 @@ static int _for_action_end(scf_dfa_t* dfa, scf_vector_t* words, void* data) scf_loge("current_block: %p, parent_block: %p\n", parse->ast->current_block, fd->parent_block); + if (3 == fd->_for->nb_nodes) + scf_node_add_child(fd->_for, NULL); + assert(parse->ast->current_block == fd->parent_block); d->current_node = fd->parent_node; diff --git a/parse/scf_parse.c b/parse/scf_parse.c index 15346ea..73432b2 100644 --- a/parse/scf_parse.c +++ b/parse/scf_parse.c @@ -17,14 +17,16 @@ } \ } while (0) -scf_base_type_t base_types[] = { - {SCF_VAR_CHAR, "char", 1}, +scf_base_type_t base_types[] = +{ + {SCF_VAR_CHAR, "char", 1}, - {SCF_VAR_VOID, "void", 1}, + {SCF_VAR_VOID, "void", 1}, + {SCF_VAR_BIT, "bit", 1}, - {SCF_VAR_INT, "int", 4}, - {SCF_VAR_FLOAT, "float", 4}, - {SCF_VAR_DOUBLE, "double", 8}, + {SCF_VAR_INT, "int", 4}, + {SCF_VAR_FLOAT, "float", 4}, + {SCF_VAR_DOUBLE, "double", 8}, {SCF_VAR_I8, "int8_t", 1}, {SCF_VAR_I16, "int16_t", 2}, -- 2.25.1