Skip to content

Commit 7b7782d

Browse files
committed
preserve_none does not support var vars
1 parent 2126db2 commit 7b7782d

File tree

3 files changed

+15
-16
lines changed

3 files changed

+15
-16
lines changed

ext/opcache/jit/ir/ir_check.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@ bool ir_check(const ir_ctx *ctx)
9494
uint32_t flags;
9595
bool ok = 1;
9696

97+
if ((ctx->flags & (IR_VARARG_FUNC|IR_PRESERVE_NONE_FUNC)) == (IR_VARARG_FUNC|IR_PRESERVE_NONE_FUNC)) {
98+
fprintf(stderr, "IR_VARARG_FUNC and IR_PRESERVE_NONE_FUNC flags are mutually exclusive (preserve_none does not support var args)\n");
99+
ok = 0;
100+
}
101+
97102
for (i = IR_UNUSED + 1, insn = ctx->ir_base + i; i < ctx->insns_count;) {
98103
if (insn->op >= IR_LAST_OP) {
99104
fprintf(stderr, "ir_base[%d].op invalid opcode (%d)\n", i, insn->op);

ext/opcache/jit/ir/ir_emit.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,12 @@ bool ir_is_vararg(const ir_ctx *ctx, ir_insn *insn)
156156
const ir_proto_t *proto = ir_call_proto(ctx, insn);
157157

158158
if (proto) {
159-
return (proto->flags & IR_VARARG_FUNC) != 0;
159+
if (proto->flags & IR_VARARG_FUNC) {
160+
#ifdef IR_HAVE_PRESERVE_NONE
161+
IR_ASSERT(!(proto->flags & IR_PRESERVE_NONE_FUNC) && "preserve_none does not support var args");
162+
#endif
163+
return 1;
164+
}
160165
}
161166
return 0;
162167
}

ext/opcache/jit/ir/ir_x86.dasc

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2937,6 +2937,9 @@ store_int:
29372937
ir_match_fuse_load(ctx, insn->op1, ref);
29382938
return (ctx->mflags & IR_X86_BMI1) ? IR_BIT_COUNT : IR_CTPOP;
29392939
case IR_VA_START:
2940+
#ifdef IR_HAVE_PRESERVE_NONE
2941+
IR_ASSERT(!(ctx->flags & IR_PRESERVE_NONE_FUNC) && "preserve_none does not support var args");
2942+
#endif
29402943
ctx->flags2 |= IR_HAS_VA_START;
29412944
if ((ctx->ir_base[insn->op2].op == IR_ALLOCA) || (ctx->ir_base[insn->op2].op == IR_VADDR)) {
29422945
ir_use_list *use_list = &ctx->use_lists[insn->op2];
@@ -3789,20 +3792,9 @@ static void ir_emit_prologue(ir_ctx *ctx)
37893792
| mov [Ra(fp)+offset+24], Ra(IR_REG_INT_ARG4)
37903793
#elif defined(IR_TARGET_X64)
37913794
|.if X64
3792-
int int_reg_params_count = IR_REG_INT_ARGS;
37933795
const int8_t *int_reg_params = _ir_int_reg_params;
37943796
const int8_t *fp_reg_params = _ir_fp_reg_params;
37953797

3796-
IR_CHECK_CALLING_CONV(ctx->flags);
3797-
3798-
# ifdef IR_HAVE_PRESERVE_NONE
3799-
// TODO: test
3800-
if (ctx->flags & IR_PRESERVE_NONE_FUNC) {
3801-
int_reg_params_count = IR_REG_INT_PNARGS;
3802-
int_reg_params = _ir_int_pn_reg_params;
3803-
}
3804-
# endif
3805-
38063798
uint32_t i;
38073799
ir_reg fp;
38083800
int offset;
@@ -3819,7 +3811,7 @@ static void ir_emit_prologue(ir_ctx *ctx)
38193811
if ((ctx->flags2 & (IR_HAS_VA_ARG_GP|IR_HAS_VA_COPY)) && ctx->gp_reg_params < IR_REG_INT_ARGS) {
38203812
/* skip named args */
38213813
offset += sizeof(void*) * ctx->gp_reg_params;
3822-
for (i = ctx->gp_reg_params; i < int_reg_params_count; i++) {
3814+
for (i = ctx->gp_reg_params; i < IR_REG_INT_ARGS; i++) {
38233815
| mov qword [Ra(fp)+offset], Rq(int_reg_params[i])
38243816
offset += sizeof(void*);
38253817
}
@@ -8350,7 +8342,6 @@ static void ir_emit_va_start(ir_ctx *ctx, ir_ref def, ir_insn *insn)
83508342
overflow_arg_area_offset = ctx->stack_frame_size + ctx->call_stack_size + sizeof(void*) + ctx->param_stack_size;
83518343
}
83528344

8353-
// TODO: preserve none
83548345
if ((ctx->flags2 & (IR_HAS_VA_ARG_GP|IR_HAS_VA_COPY)) && ctx->gp_reg_params < IR_REG_INT_ARGS) {
83558346
| lea Ra(tmp_reg), aword [Ra(fp)+reg_save_area_offset]
83568347
have_reg_save_area = 1;
@@ -8518,7 +8509,6 @@ static void ir_emit_va_arg(ir_ctx *ctx, ir_ref def, ir_insn *insn)
85188509
op2_reg = (ctx->flags & IR_USE_FRAME_POINTER) ? IR_REG_FRAME_POINTER : IR_REG_STACK_POINTER;
85198510
offset = IR_SPILL_POS_TO_OFFSET(ctx->ir_base[insn->op2].op3);
85208511
}
8521-
// TODO: preserve none
85228512
if (IR_IS_TYPE_INT(type)) {
85238513
| mov Rd(tmp_reg), dword [Ra(op2_reg)+(offset+offsetof(ir_va_list, gp_offset))]
85248514
| cmp Rd(tmp_reg), sizeof(void*)*IR_REG_INT_ARGS
@@ -10614,7 +10604,6 @@ void ir_fix_stack_frame(ir_ctx *ctx)
1061410604
ctx->flags2 |= IR_16B_FRAME_ALIGNMENT;
1061510605
ctx->stack_frame_size = IR_ALIGNED_SIZE(ctx->stack_frame_size, 16);
1061610606
ctx->locals_area_size = ctx->stack_frame_size;
10617-
// TODO: preserve none
1061810607
if ((ctx->flags2 & (IR_HAS_VA_ARG_GP|IR_HAS_VA_COPY)) && ctx->gp_reg_params < IR_REG_INT_ARGS) {
1061910608
additional_size += sizeof(void*) * IR_REG_INT_ARGS;
1062010609
}

0 commit comments

Comments
 (0)