fix: core dump when x64 peephole like 'mov 1,eax', for ../examples/auto_gc_0.c
authoryu.dongliang <18588496441@163.com>
Wed, 29 Nov 2023 03:53:25 +0000 (11:53 +0800)
committeryu.dongliang <18588496441@163.com>
Wed, 29 Nov 2023 03:53:25 +0000 (11:53 +0800)
examples/auto_gc_0.c [new file with mode: 0644]
native/x64/scf_x64.c
native/x64/scf_x64_bb_color.c
native/x64/scf_x64_inst.c
native/x64/scf_x64_inst_binary.c
native/x64/scf_x64_inst_util.c
native/x64/scf_x64_peephole.c
native/x64/scf_x64_reg.h

diff --git a/examples/auto_gc_0.c b/examples/auto_gc_0.c
new file mode 100644 (file)
index 0000000..96a6ffc
--- /dev/null
@@ -0,0 +1,16 @@
+include "../lib/scf_capi.c";
+
+int* f()
+{
+       return scf__auto_malloc(sizeof(int));
+}
+
+int main()
+{
+       int* p = f();
+
+       *p = 1;
+
+       printf("%d\n", *p);
+       return 0;
+}
index 9b55d5031a0155e492cc48fe3e0a689fb36fa129..937c847bf3e97f7f27df66be5adb64aa47ac4337 100644 (file)
@@ -121,7 +121,7 @@ static int _x64_function_init(scf_function_t* f, scf_vector_t* local_vars)
 
 static int _x64_save_rabi(scf_function_t* f)
 {
-       scf_register_t* rbp;
+       scf_register_t*     rbp;
        scf_instruction_t*  inst;
        scf_x64_OpCode_t*   mov;
 
@@ -416,10 +416,10 @@ static int _x64_argv_save(scf_basic_block_t* bb, scf_function_t* f)
 
                assert(v->arg_flag);
 
-               scf_dag_node_t*     dn;
-               scf_dag_node_t*     dn2;
+               scf_dag_node_t*    dn;
+               scf_dag_node_t*    dn2;
                scf_dn_status_t*   active;
-               scf_register_t* rabi;
+               scf_register_t*    rabi;
 
                for (l = scf_list_head(&f->dag_list_head); l != scf_list_sentinel(&f->dag_list_head);
                                l = scf_list_next(l)) {
index 4200d13431364ad3a519e3fa15e33636dce518cf..fb04a078d7cea0dbe70649b7e1c83a3841843203 100644 (file)
@@ -107,7 +107,7 @@ intptr_t x64_bb_find_color(scf_vector_t* dn_colors, scf_dag_node_t* dn)
 int x64_bb_load_dn(intptr_t color, scf_dag_node_t* dn, scf_3ac_code_t* c, scf_basic_block_t* bb, scf_function_t* f)
 {
        scf_variable_t*     v = dn->var;
-       scf_register_t* r;
+       scf_register_t*     r;
        scf_instruction_t*  inst;
 
        int inst_bytes;
index 8e2f664ae5c871f97633ee596ab80a48a0b76fe1..985f753facd12f5d547361274de71a3fded4e7bf 100644 (file)
@@ -106,7 +106,7 @@ static int _x64_inst_call_stack_size(scf_3ac_code_t* c)
 
 static int _x64_inst_call_argv(scf_3ac_code_t* c, scf_function_t* f)
 {
-       scf_register_t* rsp  = x64_find_register("rsp");
+       scf_register_t*     rsp  = x64_find_register("rsp");
 
        scf_x64_OpCode_t*   lea;
        scf_x64_OpCode_t*   mov;
@@ -229,7 +229,7 @@ static int _x64_inst_call_argv(scf_3ac_code_t* c, scf_function_t* f)
 static int _x64_call_save_ret_regs(scf_3ac_code_t* c, scf_function_t* f, scf_function_t* pf)
 {
        scf_register_t* r;
-       scf_variable_t*     v;
+       scf_variable_t* v;
 
        int i;
        for (i = 0; i < pf->rets->size; i++) {
@@ -287,8 +287,8 @@ static int _x64_call_update_dsts(scf_3ac_code_t* c, scf_function_t* f, scf_regis
        scf_dag_node_t*     dn;
        scf_variable_t*     v;
 
-       scf_register_t* rd;
-       scf_register_t* rs;
+       scf_register_t*     rd;
+       scf_register_t*     rs;
        scf_x64_OpCode_t*   mov;
 
        int nb_float   = 0;
@@ -442,8 +442,8 @@ static int _x64_inst_call_handler(scf_native_t* ctx, scf_3ac_code_t* c)
                        return -ENOMEM;
        }
 
-       scf_register_t* rsp  = x64_find_register("rsp");
-       scf_register_t* rax  = x64_find_register("rax");
+       scf_register_t*     rsp  = x64_find_register("rsp");
+       scf_register_t*     rax  = x64_find_register("rax");
 //     scf_x64_OpCode_t*   xor;
        scf_x64_OpCode_t*   mov;
        scf_x64_OpCode_t*   sub;
@@ -614,7 +614,7 @@ static int _x64_inst_unary(scf_native_t* ctx, scf_3ac_code_t* c, int OpCode_type
        }
 
        scf_instruction_t*  inst   = NULL;
-       scf_register_t* rd     = NULL;
+       scf_register_t*     rd     = NULL;
        scf_variable_t*     var    = dst->dag_node->var;
 
        scf_x64_OpCode_t*   OpCode = x64_find_OpCode(OpCode_type, var->size, var->size, SCF_X64_E);
@@ -658,7 +658,7 @@ static int _x64_inst_unary_assign(scf_native_t* ctx, scf_3ac_code_t* c, int OpCo
        }
 
        scf_instruction_t*  inst   = NULL;
-       scf_register_t* rs     = NULL;
+       scf_register_t*     rs     = NULL;
        scf_variable_t*     var    = src->dag_node->var;
 
        scf_x64_OpCode_t*   OpCode = x64_find_OpCode(OpCode_type, var->size, var->size, SCF_X64_E);
@@ -711,9 +711,9 @@ static int _x64_inst_unary_post_assign(scf_native_t* ctx, scf_3ac_code_t* c, int
                        return -ENOMEM;
        }
 
-       scf_instruction_t*  inst   = NULL;
-       scf_register_t* rs     = NULL;
-       scf_variable_t*     var    = src->dag_node->var;
+       scf_instruction_t*  inst = NULL;
+       scf_register_t*     rs   = NULL;
+       scf_variable_t*     var  = src->dag_node->var;
 
        int ret = x64_inst_op2(SCF_X64_MOV, dst->dag_node, src->dag_node, c, f);
        if (ret < 0)
@@ -763,8 +763,8 @@ static int _x64_inst_neg_handler(scf_native_t* ctx, scf_3ac_code_t* c)
                return _x64_inst_unary(ctx, c, SCF_X64_NEG);
 
        scf_instruction_t*  inst = NULL;
-       scf_register_t* rd   = NULL;
-       scf_register_t* rs   = NULL;
+       scf_register_t*     rd   = NULL;
+       scf_register_t*     rs   = NULL;
        scf_x64_OpCode_t*   pxor = x64_find_OpCode(SCF_X64_PXOR,  8, 8, SCF_X64_E2G);
        scf_x64_OpCode_t*   sub  = x64_find_OpCode(SCF_X64_SUBSS, 4, 4, SCF_X64_E2G);
 
@@ -861,7 +861,7 @@ static int _x64_inst_assign_array_index(scf_native_t* ctx, scf_3ac_code_t* c, in
        scf_variable_t*     vb     = base->dag_node->var;
        scf_variable_t*     vs     = src ->dag_node->var;
 
-       scf_register_t* rs     = NULL;
+       scf_register_t*     rs     = NULL;
        x64_sib_t           sib    = {0};
 
        scf_x64_OpCode_t*   OpCode;
@@ -970,7 +970,7 @@ static int _x64_inst_array_index(scf_native_t* ctx, scf_3ac_code_t* c, int lea_f
        scf_variable_t*     vi  = index->dag_node->var;
        scf_variable_t*     vs  = scale->dag_node->var;
 
-       scf_register_t* rd  = NULL;
+       scf_register_t*     rd  = NULL;
        x64_sib_t           sib = {0};
 
        scf_x64_OpCode_t*   OpCode;
@@ -1044,7 +1044,7 @@ static int _x64_inst_address_of_handler(scf_native_t* ctx, scf_3ac_code_t* c)
 
        scf_3ac_operand_t*  dst  = c->dsts->data[0];
        scf_3ac_operand_t*  src  = c->srcs->data[0];
-       scf_register_t* rd   = NULL;
+       scf_register_t*     rd   = NULL;
        scf_rela_t*         rela = NULL;
 
        scf_x64_OpCode_t*   lea;
@@ -1258,7 +1258,7 @@ static int _x64_inst_cast_handler(scf_native_t* ctx, scf_3ac_code_t* c)
        scf_x64_OpCode_t*   lea;
        scf_instruction_t*  inst;
 
-       scf_register_t* rd   = NULL;
+       scf_register_t*     rd   = NULL;
        scf_rela_t*         rela = NULL;
 
        scf_variable_t*     vd   = dst->dag_node->var;
@@ -1386,8 +1386,8 @@ static int _x64_inst_return_handler(scf_native_t* ctx, scf_3ac_code_t* c)
        scf_x64_context_t*  x64  = ctx->priv;
        scf_function_t*     f    = x64->f;
        scf_3ac_operand_t*  src  = NULL;
-       scf_variable_t*     v    = NULL;
        scf_instruction_t*  inst = NULL;
+       scf_variable_t*     v    = NULL;
        scf_rela_t*         rela = NULL;
 
        scf_register_t* rd   = NULL;
@@ -1510,10 +1510,10 @@ static int _x64_inst_memset_handler(scf_native_t* ctx, scf_3ac_code_t* c)
        scf_3ac_operand_t*  count = c->srcs->data[2];
        scf_instruction_t*  inst  = NULL;
 
-       scf_register_t* rax   = x64_find_register("rax");
-       scf_register_t* rcx   = x64_find_register("rcx");
-       scf_register_t* rdi   = x64_find_register("rdi");
-       scf_register_t* rd;
+       scf_register_t*     rax   = x64_find_register("rax");
+       scf_register_t*     rcx   = x64_find_register("rcx");
+       scf_register_t*     rdi   = x64_find_register("rdi");
+       scf_register_t*     rd;
        scf_x64_OpCode_t*   mov;
        scf_x64_OpCode_t*   stos;
 
@@ -1609,7 +1609,7 @@ static int _x64_inst_load_handler(scf_native_t* ctx, scf_3ac_code_t* c)
        if (!c->dsts || c->dsts->size != 1)
                return -EINVAL;
 
-       scf_register_t* r   = NULL;
+       scf_register_t*     r   = NULL;
        scf_x64_context_t*  x64 = ctx->priv;
        scf_function_t*     f   = x64->f;
 
@@ -1658,7 +1658,7 @@ static int _x64_inst_reload_handler(scf_native_t* ctx, scf_3ac_code_t* c)
        if (!c->dsts || c->dsts->size != 1)
                return -EINVAL;
 
-       scf_register_t* r   = NULL;
+       scf_register_t*     r   = NULL;
        scf_x64_context_t*  x64 = ctx->priv;
        scf_function_t*     f   = x64->f;
 
@@ -1887,9 +1887,9 @@ static int _x64_inst_va_start_handler(scf_native_t* ctx, scf_3ac_code_t* c)
        scf_loge("c->srcs->size: %d\n", c->srcs->size);
        assert(3 == c->srcs->size);
 
-       scf_register_t* rbp   = x64_find_register("rbp");
-       scf_register_t* rptr  = NULL;
-       scf_register_t* rap   = NULL;
+       scf_register_t*     rbp   = x64_find_register("rbp");
+       scf_register_t*     rptr  = NULL;
+       scf_register_t*     rap   = NULL;
        scf_instruction_t*  inst  = NULL;
        scf_3ac_operand_t*  ap    = c->srcs->data[0];
        scf_3ac_operand_t*  ptr   = c->srcs->data[2];
@@ -1953,9 +1953,9 @@ static int _x64_inst_va_end_handler(scf_native_t* ctx, scf_3ac_code_t* c)
 
        assert(2 == c->srcs->size);
 
-       scf_register_t* rbp  = x64_find_register("rbp");
-       scf_register_t* rptr = NULL;
-       scf_register_t* rap  = NULL;
+       scf_register_t*     rbp  = x64_find_register("rbp");
+       scf_register_t*     rptr = NULL;
+       scf_register_t*     rap  = NULL;
        scf_instruction_t*  inst = NULL;
        scf_3ac_operand_t*  ap   = c->srcs->data[0];
        scf_3ac_operand_t*  ptr  = c->srcs->data[1];
index 293bfa5fc5ef7424d3e15c5bf571079c8c129448..e7b66e5c7d65ee27052c509456da69377b5cc211 100644 (file)
@@ -3,7 +3,7 @@
 static int _binary_assign_sib_float(scf_register_t* rb, scf_register_t* ri, int32_t scale, int32_t disp, scf_dag_node_t* src, scf_3ac_code_t* c, scf_function_t* f, int OpCode_type)
 {
        scf_variable_t*     v    = src->var;
-       scf_register_t* rs   = NULL;
+       scf_register_t*     rs   = NULL;
        scf_rela_t*         rela = NULL;
 
        scf_x64_OpCode_t*   OpCode;
@@ -60,10 +60,10 @@ end:
 static int _binary_assign_sib_int(x64_sib_t* sib, scf_dag_node_t* src, scf_3ac_code_t* c, scf_function_t* f, int OpCode_type)
 {
        scf_variable_t*     v  = src->var;
-       scf_register_t* rs = NULL;
+       scf_register_t*     rs = NULL;
 
-       scf_register_t* rb = sib->base;
-       scf_register_t* ri = sib->index;
+       scf_register_t*     rb = sib->base;
+       scf_register_t*     ri = sib->index;
        int32_t scale          = sib->scale;
        int32_t disp           = sib->disp;
 
@@ -189,7 +189,7 @@ static int _binary_SIB2G(scf_native_t* ctx, scf_3ac_code_t* c, int OpCode_type,
        scf_variable_t*     vb  = base ->dag_node->var;
        scf_variable_t*     vi  = index->dag_node->var;
 
-       scf_register_t* rd  = NULL;
+       scf_register_t*     rd  = NULL;
        x64_sib_t           sib = {0};
 
        scf_x64_OpCode_t*   lea;
index 45e5483ebb3d44a01ec4be4961527e7cd4055cd6..ac87331a89700963253ecd579d7ca33713478691 100644 (file)
@@ -234,9 +234,9 @@ scf_instruction_t* x64_make_inst_G(scf_x64_OpCode_t* OpCode, scf_register_t* r)
        inst->code[inst->len - 1] += r->id & 0x7;
 
        if (SCF_X64_PUSH == OpCode->type)
-               inst->src.base = (scf_register_t*)r;
+               inst->src.base = r;
        else if (SCF_X64_POP == OpCode->type)
-               inst->dst.base = (scf_register_t*)r;
+               inst->dst.base = r;
 
        return inst;
 }
@@ -260,7 +260,7 @@ scf_instruction_t* x64_make_inst_I2G(scf_x64_OpCode_t* OpCode, scf_register_t* r
                p[i] = imm[i];
        }
 
-       inst->dst.base = (scf_register_t*)r_dst;
+       inst->dst.base = r_dst;
        inst->src.imm_size = size;
        return inst;
 }
@@ -281,15 +281,15 @@ scf_instruction_t* x64_make_inst_E(scf_x64_OpCode_t* OpCode, scf_register_t* r)
        inst->code[inst->len++] = ModRM;
 
        if (SCF_X64_INC == OpCode->type || SCF_X64_INC == OpCode->type) {
-               inst->src.base = (scf_register_t*)r;
-               inst->dst.base = (scf_register_t*)r;
+               inst->src.base = r;
+               inst->dst.base = r;
 
        } else if (SCF_X64_MUL  == OpCode->type
                        || SCF_X64_DIV  == OpCode->type
                        || SCF_X64_IMUL == OpCode->type
                        || SCF_X64_IDIV == OpCode->type
                        || SCF_X64_CALL == OpCode->type)
-               inst->src.base = (scf_register_t*)r;
+               inst->src.base = r;
 
        return inst;
 }
@@ -312,7 +312,7 @@ scf_instruction_t* x64_make_inst_I2E(scf_x64_OpCode_t* OpCode, scf_register_t* r
                p[i] = imm[i];
        }
 
-       inst->dst.base = (scf_register_t*)r_dst;
+       inst->dst.base = r_dst;
        inst->src.imm_size = size;
        return inst;
 }
@@ -362,11 +362,11 @@ scf_instruction_t* x64_make_inst_M(scf_rela_t** prela, scf_x64_OpCode_t* OpCode,
 
        if (SCF_X64_INC == OpCode->type || SCF_X64_INC == OpCode->type) {
 
-               inst->src.base = (scf_register_t*)r_base;
+               inst->src.base = r_base;
                inst->src.disp = offset;
                inst->src.flag = 1;
 
-               inst->dst.base = (scf_register_t*)r_base;
+               inst->dst.base = r_base;
                inst->dst.disp = offset;
                inst->dst.flag = 1;
 
@@ -376,7 +376,7 @@ scf_instruction_t* x64_make_inst_M(scf_rela_t** prela, scf_x64_OpCode_t* OpCode,
                        || SCF_X64_IDIV == OpCode->type
                        || SCF_X64_CALL == OpCode->type) {
 
-               inst->src.base = (scf_register_t*)r_base;
+               inst->src.base = r_base;
                inst->src.disp = offset;
                inst->src.flag = 1;
        }
@@ -439,7 +439,7 @@ scf_instruction_t* x64_make_inst_I2M(scf_rela_t** prela, scf_x64_OpCode_t* OpCod
                p[i] = imm[i];
        }
 
-       inst->dst.base = (scf_register_t*)r_base;
+       inst->dst.base = r_base;
        inst->dst.disp = offset;
        inst->dst.flag = 1;
 
@@ -454,7 +454,7 @@ scf_instruction_t* x64_make_inst_G2M(scf_rela_t** prela, scf_x64_OpCode_t* OpCod
                return NULL;
        }
 
-       scf_register_t* rbp  = x64_find_register("rbp");
+       scf_register_t*     rbp  = x64_find_register("rbp");
        scf_instruction_t*  inst = NULL;
 
        uint32_t base;
@@ -493,8 +493,8 @@ scf_instruction_t* x64_make_inst_G2M(scf_rela_t** prela, scf_x64_OpCode_t* OpCod
                return NULL;
        }
 
-       inst->src.base = (scf_register_t*)r_src;
-       inst->dst.base = (scf_register_t*)r_base;
+       inst->src.base = r_src;
+       inst->dst.base = r_base;
        inst->dst.disp = offset;
        inst->dst.flag = 1;
 
@@ -508,7 +508,7 @@ scf_instruction_t* x64_make_inst_M2G(scf_rela_t** prela, scf_x64_OpCode_t* OpCod
                return NULL;
        }
 
-       scf_register_t* rbp  = x64_find_register("rbp");
+       scf_register_t*     rbp  = x64_find_register("rbp");
        scf_instruction_t*  inst = NULL;
 
        uint32_t base;
@@ -546,8 +546,8 @@ scf_instruction_t* x64_make_inst_M2G(scf_rela_t** prela, scf_x64_OpCode_t* OpCod
                return NULL;
        }
 
-       inst->dst.base = (scf_register_t*)r_dst;
-       inst->src.base = (scf_register_t*)r_base;
+       inst->dst.base = r_dst;
+       inst->src.base = r_base;
        inst->src.disp = offset;
        inst->src.flag = 1;
 
@@ -570,8 +570,8 @@ scf_instruction_t* x64_make_inst_P2G(scf_x64_OpCode_t* OpCode, scf_register_t* r
                return NULL;
        }
 
-       inst->dst.base = (scf_register_t*)r_dst;
-       inst->src.base = (scf_register_t*)r_base;
+       inst->dst.base = r_dst;
+       inst->src.base = r_base;
        inst->src.disp = offset;
        inst->src.flag = 1;
 
@@ -605,8 +605,8 @@ scf_instruction_t* x64_make_inst_G2P(scf_x64_OpCode_t* OpCode, scf_register_t* r
                return NULL;
        }
 
-       inst->src.base = (scf_register_t*)r_src;
-       inst->dst.base = (scf_register_t*)r_base;
+       inst->src.base = r_src;
+       inst->dst.base = r_base;
        inst->dst.disp = offset;
        inst->dst.flag = 1;
 
@@ -650,7 +650,7 @@ scf_instruction_t* x64_make_inst_I2P(scf_x64_OpCode_t* OpCode, scf_register_t* r
 
        inst->src.imm_size = size;
 
-       inst->dst.base = (scf_register_t*)r_base;
+       inst->dst.base = r_base;
        inst->dst.disp = offset;
        inst->dst.flag = 1;
 
@@ -675,8 +675,8 @@ scf_instruction_t* x64_make_inst_G2E(scf_x64_OpCode_t* OpCode, scf_register_t* r
 
        inst->code[inst->len++] = ModRM;
 
-       inst->src.base = (scf_register_t*)r_src;
-       inst->dst.base = (scf_register_t*)r_dst;
+       inst->src.base = r_src;
+       inst->dst.base = r_dst;
 
        return inst;
 }
@@ -699,8 +699,8 @@ scf_instruction_t* x64_make_inst_E2G(scf_x64_OpCode_t* OpCode, scf_register_t* r
 
        inst->code[inst->len++] = ModRM;
 
-       inst->src.base = (scf_register_t*)r_src;
-       inst->dst.base = (scf_register_t*)r_dst;
+       inst->src.base = r_src;
+       inst->dst.base = r_dst;
 
        return inst;
 }
@@ -782,10 +782,10 @@ scf_instruction_t* x64_make_inst_SIB2G(scf_x64_OpCode_t* OpCode, scf_register_t*
        if (!inst)
                return NULL;
 
-       inst->dst.base  = (scf_register_t*)r_dst;
+       inst->dst.base  = r_dst;
 
-       inst->src.base  = (scf_register_t*)r_base;
-       inst->src.index = (scf_register_t*)r_index;
+       inst->src.base  = r_base;
+       inst->src.index = r_index;
        inst->src.scale = scale;
        inst->src.disp  = disp;
        inst->src.flag  = 1;
@@ -804,10 +804,10 @@ scf_instruction_t* x64_make_inst_G2SIB(scf_x64_OpCode_t* OpCode, scf_register_t*
        if (!inst)
                return NULL;
 
-       inst->src.base  = (scf_register_t*)r_src;
+       inst->src.base  = r_src;
 
-       inst->dst.base  = (scf_register_t*)r_base;
-       inst->dst.index = (scf_register_t*)r_index;
+       inst->dst.base  = r_base;
+       inst->dst.index = r_index;
        inst->dst.scale = scale;
        inst->dst.disp  = disp;
        inst->dst.flag  = 1;
@@ -841,8 +841,8 @@ scf_instruction_t* x64_make_inst_I2SIB(scf_x64_OpCode_t* OpCode, scf_register_t*
 
        inst->src.imm_size = size;
 
-       inst->dst.base  = (scf_register_t*)r_base;
-       inst->dst.index = (scf_register_t*)r_index;
+       inst->dst.base  = r_base;
+       inst->dst.index = r_index;
        inst->dst.scale = scale;
        inst->dst.disp  = disp;
        inst->dst.flag  = 1;
index 81725589c57e4aba4e8809f585276aec302b2633..bedc6b8db8d136ee5a270b1dfeadfc07222f49af 100644 (file)
@@ -40,6 +40,7 @@ static int _x64_peephole_common(scf_vector_t* std_insts, scf_instruction_t* inst
 
        scf_instruction_t* inst2;
        scf_instruction_t* std;
+       scf_x64_OpCode_t*  OpCode;
 
        int j;
        for (j  = std_insts->size - 1; j >= 0; j--) {
@@ -92,9 +93,13 @@ static int _x64_peephole_common(scf_vector_t* std_insts, scf_instruction_t* inst
                        if (inst->src.flag) {
                                assert(std->dst.flag);
 
-                               inst2 = x64_make_inst_E2G((scf_x64_OpCode_t*)inst->OpCode,
-                                               (scf_register_t*)inst->dst.base,
-                                               (scf_register_t*)std->src.base);
+                               if (std->src.base)
+                                       inst2  = x64_make_inst_E2G((scf_x64_OpCode_t*)inst->OpCode, inst->dst.base, std->src.base);
+                               else {
+                                       OpCode = x64_find_OpCode(inst->OpCode->type, std->src.imm_size, inst->dst.base->bytes, SCF_X64_I2G);
+
+                                       inst2  = x64_make_inst_I2G(OpCode, inst->dst.base, (uint8_t*)&std->src.imm, std->src.imm_size);
+                               }
                                if (!inst2)
                                        return -ENOMEM;
 
@@ -119,13 +124,13 @@ static int _x64_peephole_common(scf_vector_t* std_insts, scf_instruction_t* inst
 
                                        if (!inst->dst.index)
                                                inst2 = x64_make_inst_G2P((scf_x64_OpCode_t*)inst->OpCode,
-                                                               (scf_register_t*)inst->dst.base, inst->dst.disp,
-                                                               (scf_register_t*)std->src.base);
+                                                               inst->dst.base, inst->dst.disp,
+                                                               std->src.base);
                                        else
                                                inst2 = x64_make_inst_G2SIB((scf_x64_OpCode_t*)inst->OpCode,
-                                                               (scf_register_t*)inst->dst.base,
-                                                               (scf_register_t*)inst->dst.index, inst->dst.scale, inst->dst.disp,
-                                                               (scf_register_t*)std->src.base);
+                                                               inst->dst.base,
+                                                               inst->dst.index, inst->dst.scale, inst->dst.disp,
+                                                               std->src.base);
                                        if (!inst2)
                                                return -ENOMEM;
 
@@ -154,8 +159,8 @@ static int _x64_peephole_common(scf_vector_t* std_insts, scf_instruction_t* inst
 
                        if (x64_inst_data_is_reg(&inst->dst)) {
 
-                               r0 = (scf_register_t*) std ->src.base;
-                               r1 = (scf_register_t*) inst->dst.base;
+                               r0 = std ->src.base;
+                               r1 = inst->dst.base;
 
                                if (X64_COLOR_CONFLICT(r0->color, r1->color))
                                        assert(0 == scf_vector_del(std_insts, std));
@@ -199,9 +204,7 @@ static int _x64_peephole_cmp(scf_vector_t* std_insts, scf_instruction_t* inst)
                        else
                                goto check;
 
-                       inst2 = x64_make_inst_E2G((scf_x64_OpCode_t*) inst->OpCode,
-                                       (scf_register_t*) inst->dst.base,
-                                       (scf_register_t*) inst->src.base);
+                       inst2 = x64_make_inst_E2G((scf_x64_OpCode_t*) inst->OpCode, inst->dst.base, inst->src.base);
                        if (!inst2)
                                return -ENOMEM;
 
@@ -224,12 +227,12 @@ static int _x64_peephole_cmp(scf_vector_t* std_insts, scf_instruction_t* inst)
 
                        if (inst->src.imm_size > 0)
                                inst2 = x64_make_inst_I2E((scf_x64_OpCode_t*)inst->OpCode,
-                                               (scf_register_t*)inst->dst.base,
+                                               inst->dst.base,
                                                (uint8_t*)&inst->src.imm, inst->src.imm_size);
                        else
                                inst2 = x64_make_inst_G2E((scf_x64_OpCode_t*)inst->OpCode,
-                                               (scf_register_t*)inst->dst.base,
-                                               (scf_register_t*)inst->src.base);
+                                               inst->dst.base,
+                                               inst->src.base);
                        if (!inst2)
                                return -ENOMEM;
 
@@ -299,7 +302,7 @@ static void _x64_peephole_function(scf_vector_t* tmp_insts, scf_function_t* f, i
 
                if (x64_inst_data_is_reg(&inst->dst)) {
 
-                       r0 = (scf_register_t*)inst->dst.base;
+                       r0 = inst->dst.base;
 
                        if (X64_COLOR_CONFLICT(rax->color, r0->color))
                                continue;
@@ -323,8 +326,8 @@ static void _x64_peephole_function(scf_vector_t* tmp_insts, scf_function_t* f, i
 
                        if (x64_inst_data_is_reg(&inst->dst)) {
 
-                               r0 = (scf_register_t*)inst ->dst.base;
-                               r1 = (scf_register_t*)inst2->src.base;
+                               r0 = inst ->dst.base;
+                               r1 = inst2->src.base;
 
                                if (SCF_X64_CALL == inst2->OpCode->type) {
 
@@ -352,7 +355,7 @@ static void _x64_peephole_function(scf_vector_t* tmp_insts, scf_function_t* f, i
 
                                if (scf_inst_data_same(&inst->dst, &inst2->src))
                                        break;
-                               else if (rsp == (scf_register_t*)inst->dst.base)
+                               else if (rsp == inst->dst.base)
                                        break;
                                else if (SCF_OP_VA_START == inst->c->op->type
                                                || SCF_OP_VA_ARG == inst->c->op->type
index 840018bcc8e485b8ab47115ef99b03b36bc965b7..57f42d3ac5bf9cf25bd2efce7ef42d19d62c0eec 100644 (file)
@@ -158,8 +158,8 @@ void                x64_call_rabi(int* p_nints, int* p_nfloats, scf_3ac_code_t*
 
 static inline int   x64_inst_data_is_reg(scf_inst_data_t* id)
 {
-       scf_register_t* rsp = (scf_register_t*)x64_find_register("rsp");
-       scf_register_t* rbp = (scf_register_t*)x64_find_register("rbp");
+       scf_register_t* rsp = x64_find_register("rsp");
+       scf_register_t* rbp = x64_find_register("rbp");
 
        if (!id->flag && id->base && id->base != rsp && id->base != rbp && 0 == id->imm_size)
                return 1;
@@ -168,8 +168,8 @@ static inline int   x64_inst_data_is_reg(scf_inst_data_t* id)
 
 static inline int   x64_inst_data_is_local(scf_inst_data_t* id)
 {
-       scf_register_t* rbp = (scf_register_t*)x64_find_register("rbp");
-       scf_register_t* rsp = (scf_register_t*)x64_find_register("rsp");
+       scf_register_t* rbp = x64_find_register("rbp");
+       scf_register_t* rsp = x64_find_register("rsp");
 
        if (id->flag && (id->base == rbp || id->base == rsp))
                return 1;