fix: core dump when test 'examples/declare_vars.c'
authoryu.dongliang <18588496441@163.com>
Sat, 25 Nov 2023 15:54:13 +0000 (23:54 +0800)
committeryu.dongliang <18588496441@163.com>
Sat, 25 Nov 2023 15:56:06 +0000 (23:56 +0800)
core/scf_3ac.c
core/scf_dag.h
examples/declare_vars.c [new file with mode: 0644]
native/x64/scf_x64_peephole.c
parse/scf_dfa_var.c
parse/scf_parse.h

index e62d8e0167411ff20719e18a2c4a95d33b29c4ce..3d1ff121bfdbee28a47038a6ee5f7b5233d7e26b 100644 (file)
@@ -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;
index 2afa80ce463e3f116bba5e77ced2d9e59e389e8c..f90e9d1cd51f31a4e4a4523e4f7bd9a60a3fc2f8 100644 (file)
@@ -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 (file)
index 0000000..cf7c5a2
--- /dev/null
@@ -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;
+}
index 63ec4cc2236c25302293eeed337d52a891e18c36..81725589c57e4aba4e8809f585276aec302b2633 100644 (file)
@@ -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) {
 
index c7d634cb89c767b84a22f6f3e07967b5d0c1a6b8..99e839ba3a2b5759e7102d6b05cdb487679c1b3b 100644 (file)
@@ -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);
index d8dc890a95f3fc1300b15a1ae9b132644e74e46c..8ef3d05cfa729e21982c396099425d77b6cee77f 100644 (file)
@@ -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;