mirror of
https://github.com/danog/ir.git
synced 2024-11-30 04:39:43 +01:00
Use inline functions to avoid false positive address sanitaizer warnings
This commit is contained in:
parent
3ac58893f2
commit
32ad3d1052
@ -3553,7 +3553,6 @@ static int32_t ir_emit_arguments(ir_ctx *ctx, ir_ref def, ir_insn *insn, ir_reg
|
||||
ir_copy *copies;
|
||||
bool do_pass3 = 0;
|
||||
ir_reg tmp_fp_reg = IR_REG_FP_LAST; /* Temporary register for FP loads and swap */
|
||||
int8_t *reg_ops;
|
||||
|
||||
n = ir_input_edges_count(ctx, insn);
|
||||
if (n < 3) {
|
||||
@ -3576,10 +3575,9 @@ static int32_t ir_emit_arguments(ir_ctx *ctx, ir_ref def, ir_insn *insn, ir_reg
|
||||
/* 1. move all register arguments that should be passed through stack
|
||||
* and collect arguments that should be passed through registers */
|
||||
copies = ir_mem_malloc((n - 2) * sizeof(ir_copy));
|
||||
reg_ops = ctx->regs[def];
|
||||
for (j = 3; j <= n; j++) {
|
||||
arg = ir_insn_op(insn, j);
|
||||
src_reg = reg_ops[j];
|
||||
src_reg = ir_get_alocated_reg(ctx, def, j);
|
||||
arg_insn = &ctx->ir_base[arg];
|
||||
type = arg_insn->type;
|
||||
if (IR_IS_TYPE_INT(type)) {
|
||||
@ -3645,7 +3643,7 @@ static int32_t ir_emit_arguments(ir_ctx *ctx, ir_ref def, ir_insn *insn, ir_reg
|
||||
fp_param = 0;
|
||||
for (j = 3; j <= n; j++) {
|
||||
arg = ir_insn_op(insn, j);
|
||||
src_reg = reg_ops[j];
|
||||
src_reg = ir_get_alocated_reg(ctx, def, j);
|
||||
arg_insn = &ctx->ir_base[arg];
|
||||
type = arg_insn->type;
|
||||
if (IR_IS_TYPE_INT(type)) {
|
||||
@ -4255,7 +4253,7 @@ static int ir_emit_dessa_move(ir_ctx *ctx, uint8_t type, ir_ref from, ir_ref to)
|
||||
|
||||
if (IR_IS_TYPE_INT(type)) {
|
||||
to_reg = to ? ctx->regs[phi][0] : ctx->regs[ref][0]; /* temporary register for integer swap (see ir_fix_dessa_tmps) */
|
||||
from_reg = from ? ctx->regs[phi][k] : ctx->regs[ref][0]; /* temporary register for integer swap (see ir_fix_dessa_tmps) */
|
||||
from_reg = from ? ir_get_alocated_reg(ctx, phi, k) : ctx->regs[ref][0]; /* temporary register for integer swap (see ir_fix_dessa_tmps) */
|
||||
if (from_reg != IR_REG_NONE && (from_reg & IR_REG_SPILL_LOAD)) {
|
||||
from_reg &= ~IR_REG_SPILL_LOAD;
|
||||
ir_emit_load(ctx, type, from_reg, from);
|
||||
@ -4288,7 +4286,7 @@ static int ir_emit_dessa_move(ir_ctx *ctx, uint8_t type, ir_ref from, ir_ref to)
|
||||
}
|
||||
} else {
|
||||
to_reg = to ? ctx->regs[phi][0] : ctx->regs[ref][2]; /* temporary register for fp swap (see ir_fix_dessa_tmps) */
|
||||
from_reg = from ? ctx->regs[phi][k] : ctx->regs[ref][2]; /* temporary register for fp swap (see ir_fix_dessa_tmps) */
|
||||
from_reg = from ? ir_get_alocated_reg(ctx, phi, k) : ctx->regs[ref][2]; /* temporary register for fp swap (see ir_fix_dessa_tmps) */
|
||||
if (from_reg != IR_REG_NONE && (from_reg & IR_REG_SPILL_LOAD)) {
|
||||
from_reg &= ~IR_REG_SPILL_LOAD;
|
||||
ir_emit_load(ctx, type, from_reg, from);
|
||||
|
18
ir_private.h
18
ir_private.h
@ -1045,6 +1045,24 @@ typedef struct _ir_reg_alloc_data {
|
||||
|
||||
int32_t ir_allocate_spill_slot(ir_ctx *ctx, ir_type type, ir_reg_alloc_data *data);
|
||||
|
||||
IR_ALWAYS_INLINE void ir_set_alocated_reg(ir_ctx *ctx, ir_ref ref, int op_num, int8_t reg)
|
||||
{
|
||||
int8_t *regs = ctx->regs[ref];
|
||||
|
||||
/* regs[] is not limited by the declared boundary 4, the real boundary checked below */
|
||||
IR_ASSERT(op_num <= IR_MAX(3, ir_input_edges_count(ctx, &ctx->ir_base[ref])));
|
||||
regs[op_num] = reg;
|
||||
}
|
||||
|
||||
IR_ALWAYS_INLINE int8_t ir_get_alocated_reg(ir_ctx *ctx, ir_ref ref, int op_num)
|
||||
{
|
||||
int8_t *regs = ctx->regs[ref];
|
||||
|
||||
/* regs[] is not limited by the declared boundary 4, the real boundary checked below */
|
||||
IR_ASSERT(op_num <= IR_MAX(3, ir_input_edges_count(ctx, &ctx->ir_base[ref])));
|
||||
return regs[op_num];
|
||||
}
|
||||
|
||||
/*** IR Target Interface ***/
|
||||
typedef enum _ir_reg ir_reg;
|
||||
typedef struct _ir_target_constraints ir_target_constraints;
|
||||
|
8
ir_ra.c
8
ir_ra.c
@ -2602,13 +2602,7 @@ static void assign_regs(ir_ctx *ctx)
|
||||
IR_ASSERT(use_pos->hint_ref > 0);
|
||||
ref = use_pos->hint_ref;
|
||||
}
|
||||
IR_ASSERT(use_pos->op_num <= IR_MAX(3, ir_input_edges_count(ctx, &ctx->ir_base[ref])));
|
||||
|
||||
/* It's allowed to write above reg_ops[4] boundary */
|
||||
/* (see the real boundaty check by the assertion above) */
|
||||
/* ctx->regs[ref][use_pos->op_num] = reg; */
|
||||
int8_t *reg_ops = ctx->regs[ref];
|
||||
reg_ops[use_pos->op_num] = reg;
|
||||
ir_set_alocated_reg(ctx, ref, use_pos->op_num, reg);
|
||||
|
||||
use_pos = use_pos->next;
|
||||
}
|
||||
|
10
ir_x86.dasc
10
ir_x86.dasc
@ -5763,7 +5763,6 @@ static int32_t ir_emit_arguments(ir_ctx *ctx, ir_ref def, ir_insn *insn, ir_reg
|
||||
ir_copy *copies;
|
||||
bool do_pass3 = 0;
|
||||
ir_reg tmp_fp_reg = IR_REG_FP_LAST; /* Temporary register for FP loads and swap */
|
||||
int8_t *reg_ops;
|
||||
|
||||
n = ir_input_edges_count(ctx, insn);
|
||||
if (n < 3) {
|
||||
@ -5795,10 +5794,9 @@ static int32_t ir_emit_arguments(ir_ctx *ctx, ir_ref def, ir_insn *insn, ir_reg
|
||||
/* 1. move all register arguments that should be passed through stack
|
||||
* and collect arguments that should be passed through registers */
|
||||
copies = ir_mem_malloc((n - 2) * sizeof(ir_copy));
|
||||
reg_ops = ctx->regs[def];
|
||||
for (j = 3; j <= n; j++) {
|
||||
arg = ir_insn_op(insn, j);
|
||||
src_reg = reg_ops[j];
|
||||
src_reg = ir_get_alocated_reg(ctx, def, j);
|
||||
arg_insn = &ctx->ir_base[arg];
|
||||
type = arg_insn->type;
|
||||
if (IR_IS_TYPE_INT(type)) {
|
||||
@ -5863,7 +5861,7 @@ static int32_t ir_emit_arguments(ir_ctx *ctx, ir_ref def, ir_insn *insn, ir_reg
|
||||
fp_param = 0;
|
||||
for (j = 3; j <= n; j++) {
|
||||
arg = ir_insn_op(insn, j);
|
||||
src_reg = reg_ops[j];
|
||||
src_reg = ir_get_alocated_reg(ctx, def, j);
|
||||
arg_insn = &ctx->ir_base[arg];
|
||||
type = arg_insn->type;
|
||||
if (IR_IS_TYPE_INT(type)) {
|
||||
@ -6773,7 +6771,7 @@ static int ir_emit_dessa_move(ir_ctx *ctx, uint8_t type, ir_ref from, ir_ref to)
|
||||
|
||||
if (IR_IS_TYPE_INT(type)) {
|
||||
to_reg = to ? ctx->regs[phi][0] : ctx->regs[ref][0]; /* temporary register for integer swap (see ir_fix_dessa_tmps) */
|
||||
from_reg = from ? ctx->regs[phi][k] : ctx->regs[ref][0]; /* temporary register for integer swap (see ir_fix_dessa_tmps) */
|
||||
from_reg = from ? ir_get_alocated_reg(ctx, phi, k) : ctx->regs[ref][0]; /* temporary register for integer swap (see ir_fix_dessa_tmps) */
|
||||
if (from_reg != IR_REG_NONE && (from_reg & IR_REG_SPILL_LOAD)) {
|
||||
from_reg &= ~IR_REG_SPILL_LOAD;
|
||||
ir_emit_load(ctx, type, from_reg, from);
|
||||
@ -6811,7 +6809,7 @@ static int ir_emit_dessa_move(ir_ctx *ctx, uint8_t type, ir_ref from, ir_ref to)
|
||||
}
|
||||
} else {
|
||||
to_reg = to ? ctx->regs[phi][0] : ctx->regs[ref][2]; /* temporary register for fp swap (see ir_fix_dessa_tmps) */
|
||||
from_reg = from ? ctx->regs[phi][k] : ctx->regs[ref][2]; /* temporary register for fp swap (see ir_fix_dessa_tmps) */
|
||||
from_reg = from ? ir_get_alocated_reg(ctx, phi, k) : ctx->regs[ref][2]; /* temporary register for fp swap (see ir_fix_dessa_tmps) */
|
||||
if (from_reg != IR_REG_NONE && (from_reg & IR_REG_SPILL_LOAD)) {
|
||||
from_reg &= ~IR_REG_SPILL_LOAD;
|
||||
ir_emit_load(ctx, type, from_reg, from);
|
||||
|
Loading…
Reference in New Issue
Block a user