fix: core dump of 'while (i < 10); ' and 'for(i = 0; i < 1000; i++);'
authoryu.dongliang <18588496441@163.com>
Tue, 13 Jun 2023 10:43:13 +0000 (18:43 +0800)
committeryu.dongliang <18588496441@163.com>
Tue, 13 Jun 2023 10:43:13 +0000 (18:43 +0800)
core/scf_core_types.h
lex/scf_lex.c
native/x64/scf_x64_bb_color.c
native/x64/scf_x64_reg.c
parse/scf_dfa_for.c
parse/scf_parse.c

index 6c48bfc2c708be993c1c591aa13c6d61e6e2fd9c..f698305e058cad155b0c0b2ed4b9c5a395cbd78e 100644 (file)
@@ -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
 
index 3fbd2f79d78b523b3d0c5278f7cba3ee0acc9b04..005b9f997794609a55694788ed5df276ab41e68c 100644 (file)
@@ -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},
index 011d1701d2441554eba034846513efbc2cb41922..16ce76d4de56a79b5b4763d54bddf82c175ee356 100644 (file)
@@ -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++) {
index ce11deb12e060a9d5815255698e97bc8da2e310b..5f893f735384636a1de0eb2ef0e1d978e1c0d50b 100644 (file)
@@ -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;
        }
 
index c5f203acb9b1f78cb93138d97395859187e3c1a2..7ec70b42bbeb01cb8f26744e1b4ffb98af2e93c4 100644 (file)
@@ -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;
index 15346ea166af24203770f552dbc3cb90528cd4f0..73432b2c3c9c67876e77105d57c389c72b386a73 100644 (file)
                } \
        } 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},