From 8ca08ebe4433f89c64415a760011365220aca38d Mon Sep 17 00:00:00 2001 From: "yu.dongliang" <18588496441@163.com> Date: Wed, 29 Nov 2023 11:53:25 +0800 Subject: [PATCH] fix: core dump when x64 peephole like 'mov 1,eax', for ../examples/auto_gc_0.c --- examples/auto_gc_0.c | 16 ++++++++ native/x64/scf_x64.c | 8 ++-- native/x64/scf_x64_bb_color.c | 2 +- native/x64/scf_x64_inst.c | 60 ++++++++++++++-------------- native/x64/scf_x64_inst_binary.c | 10 ++--- native/x64/scf_x64_inst_util.c | 68 ++++++++++++++++---------------- native/x64/scf_x64_peephole.c | 43 ++++++++++---------- native/x64/scf_x64_reg.h | 8 ++-- 8 files changed, 117 insertions(+), 98 deletions(-) create mode 100644 examples/auto_gc_0.c diff --git a/examples/auto_gc_0.c b/examples/auto_gc_0.c new file mode 100644 index 0000000..96a6ffc --- /dev/null +++ b/examples/auto_gc_0.c @@ -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; +} diff --git a/native/x64/scf_x64.c b/native/x64/scf_x64.c index 9b55d50..937c847 100644 --- a/native/x64/scf_x64.c +++ b/native/x64/scf_x64.c @@ -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)) { diff --git a/native/x64/scf_x64_bb_color.c b/native/x64/scf_x64_bb_color.c index 4200d13..fb04a07 100644 --- a/native/x64/scf_x64_bb_color.c +++ b/native/x64/scf_x64_bb_color.c @@ -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; diff --git a/native/x64/scf_x64_inst.c b/native/x64/scf_x64_inst.c index 8e2f664..985f753 100644 --- a/native/x64/scf_x64_inst.c +++ b/native/x64/scf_x64_inst.c @@ -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]; diff --git a/native/x64/scf_x64_inst_binary.c b/native/x64/scf_x64_inst_binary.c index 293bfa5..e7b66e5 100644 --- a/native/x64/scf_x64_inst_binary.c +++ b/native/x64/scf_x64_inst_binary.c @@ -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; diff --git a/native/x64/scf_x64_inst_util.c b/native/x64/scf_x64_inst_util.c index 45e5483..ac87331 100644 --- a/native/x64/scf_x64_inst_util.c +++ b/native/x64/scf_x64_inst_util.c @@ -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; diff --git a/native/x64/scf_x64_peephole.c b/native/x64/scf_x64_peephole.c index 8172558..bedc6b8 100644 --- a/native/x64/scf_x64_peephole.c +++ b/native/x64/scf_x64_peephole.c @@ -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 diff --git a/native/x64/scf_x64_reg.h b/native/x64/scf_x64_reg.h index 840018b..57f42d3 100644 --- a/native/x64/scf_x64_reg.h +++ b/native/x64/scf_x64_reg.h @@ -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; -- 2.25.1