Skip to content

Commit 9f7dd18

Browse files
committed
Link static var to CV from JMP_STATIC_DEF
1 parent 3bc6bf6 commit 9f7dd18

9 files changed

+59
-38
lines changed

Zend/Optimizer/sccp.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ static bool can_replace_op1(
249249
case ZEND_ROPE_ADD:
250250
case ZEND_ROPE_END:
251251
case ZEND_BIND_STATIC:
252+
case ZEND_JMP_STATIC_DEF:
252253
case ZEND_BIND_GLOBAL:
253254
case ZEND_MAKE_REF:
254255
case ZEND_UNSET_CV:

Zend/Optimizer/zend_dfg.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ static zend_always_inline void _zend_dfg_add_use_def_op(const zend_op_array *op_
150150
case ZEND_POST_DEC:
151151
case ZEND_BIND_GLOBAL:
152152
case ZEND_BIND_STATIC:
153+
case ZEND_JMP_STATIC_DEF:
153154
case ZEND_SEND_VAR_NO_REF:
154155
case ZEND_SEND_VAR_NO_REF_EX:
155156
case ZEND_SEND_VAR_EX:

Zend/Optimizer/zend_inference.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2930,6 +2930,10 @@ static zend_always_inline zend_result _zend_update_type_info(
29302930
}
29312931
UPDATE_SSA_TYPE(tmp, ssa_op->op1_def);
29322932
break;
2933+
case ZEND_JMP_STATIC_DEF:
2934+
tmp = MAY_BE_ANY | MAY_BE_ARRAY_KEY_ANY | MAY_BE_ARRAY_OF_ANY | MAY_BE_ARRAY_OF_REF | MAY_BE_REF;
2935+
UPDATE_SSA_TYPE(tmp, ssa_op->op1_def);
2936+
break;
29332937
case ZEND_SEND_VAR:
29342938
if (ssa_op->op1_def >= 0) {
29352939
tmp = t1;
@@ -4347,6 +4351,7 @@ static void zend_mark_cv_references(const zend_op_array *op_array, const zend_sc
43474351
case ZEND_SEND_REF:
43484352
case ZEND_SEND_VAR_EX:
43494353
case ZEND_SEND_FUNC_ARG:
4354+
case ZEND_JMP_STATIC_DEF:
43504355
break;
43514356
case ZEND_INIT_ARRAY:
43524357
case ZEND_ADD_ARRAY_ELEMENT:
@@ -4502,6 +4507,7 @@ ZEND_API bool zend_may_throw_ex(const zend_op *opline, const zend_ssa_op *ssa_op
45024507
case ZEND_ASSIGN_REF:
45034508
case ZEND_BIND_GLOBAL:
45044509
case ZEND_BIND_STATIC:
4510+
case ZEND_JMP_STATIC_DEF:
45054511
case ZEND_FETCH_DIM_IS:
45064512
case ZEND_FETCH_OBJ_IS:
45074513
case ZEND_SEND_REF:
@@ -4739,6 +4745,7 @@ ZEND_API bool zend_may_throw_ex(const zend_op *opline, const zend_ssa_op *ssa_op
47394745
case ZEND_UNSET_VAR:
47404746
return (t1 & (MAY_BE_OBJECT|MAY_BE_RESOURCE|MAY_BE_ARRAY_OF_OBJECT|MAY_BE_ARRAY_OF_RESOURCE|MAY_BE_ARRAY_OF_ARRAY));
47414747
case ZEND_BIND_STATIC:
4748+
case ZEND_JMP_STATIC_DEF:
47424749
if (t1 & (MAY_BE_OBJECT|MAY_BE_RESOURCE|MAY_BE_ARRAY_OF_OBJECT|MAY_BE_ARRAY_OF_RESOURCE|MAY_BE_ARRAY_OF_ARRAY)) {
47434750
/* Destructor may throw. */
47444751
return 1;

Zend/Optimizer/zend_ssa.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,7 @@ static zend_always_inline int _zend_ssa_rename_op(const zend_op_array *op_array,
679679
case ZEND_POST_DEC:
680680
case ZEND_BIND_GLOBAL:
681681
case ZEND_BIND_STATIC:
682+
case ZEND_JMP_STATIC_DEF:
682683
case ZEND_SEND_VAR_NO_REF:
683684
case ZEND_SEND_VAR_NO_REF_EX:
684685
case ZEND_SEND_VAR_EX:

Zend/zend_compile.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4904,6 +4904,8 @@ static void zend_compile_static_var(zend_ast *ast) /* {{{ */
49044904

49054905
uint32_t static_def_jmp_opnum = get_next_op_number();
49064906
opline = zend_emit_op(NULL, ZEND_JMP_STATIC_DEF, NULL, NULL);
4907+
opline->op1_type = IS_CV;
4908+
opline->op1.var = lookup_cv(var_name);
49074909
opline->extended_value = placeholder_offset;
49084910

49094911
znode expr;
@@ -4914,16 +4916,7 @@ static void zend_compile_static_var(zend_ast *ast) /* {{{ */
49144916
opline->op1.var = lookup_cv(var_name);
49154917
opline->extended_value = placeholder_offset | ZEND_BIND_REF;
49164918

4917-
uint32_t skip_bind_static_jmp_opnum = zend_emit_jump(0);
4918-
49194919
zend_update_jump_target_to_next(static_def_jmp_opnum);
4920-
4921-
opline = zend_emit_op(NULL, ZEND_BIND_STATIC, NULL, NULL);
4922-
opline->op1_type = IS_CV;
4923-
opline->op1.var = lookup_cv(var_name);
4924-
opline->extended_value = placeholder_offset | ZEND_BIND_REF;
4925-
4926-
zend_update_jump_target_to_next(skip_bind_static_jmp_opnum);
49274920
}
49284921
}
49294922
/* }}} */

Zend/zend_vm_def.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8894,11 +8894,14 @@ ZEND_VM_HANDLER(183, ZEND_BIND_STATIC, CV, ANY, REF)
88948894
ZEND_VM_NEXT_OPCODE_CHECK_EXCEPTION();
88958895
}
88968896

8897-
ZEND_VM_HANDLER(203, ZEND_JMP_STATIC_DEF, ANY, JMP_ADDR)
8897+
ZEND_VM_HANDLER(203, ZEND_JMP_STATIC_DEF, CV, JMP_ADDR)
88988898
{
88998899
USE_OPLINE
89008900
HashTable *ht;
89018901
zval *value;
8902+
zval *variable_ptr;
8903+
8904+
variable_ptr = GET_OP1_ZVAL_PTR_PTR_UNDEF(BP_VAR_W);
89028905

89038906
ht = ZEND_MAP_PTR_GET(EX(func)->op_array.static_variables_ptr);
89048907
if (!ht) {
@@ -8910,7 +8913,13 @@ ZEND_VM_HANDLER(203, ZEND_JMP_STATIC_DEF, ANY, JMP_ADDR)
89108913
if (Z_TYPE_EXTRA_P(value) & IS_STATIC_VAR_UNINITIALIZED) {
89118914
ZEND_VM_NEXT_OPCODE();
89128915
} else {
8916+
SAVE_OPLINE();
8917+
zval_ptr_dtor(variable_ptr);
8918+
ZEND_ASSERT(Z_TYPE_P(value) == IS_REFERENCE);
8919+
Z_ADDREF_P(value);
8920+
ZVAL_REF(variable_ptr, Z_REF_P(value));
89138921
ZEND_VM_JMP_EX(OP_JMP_ADDR(opline, opline->op2), 0);
8922+
ZEND_VM_NEXT_OPCODE_CHECK_EXCEPTION();
89148923
}
89158924
}
89168925

Zend/zend_vm_execute.h

Lines changed: 35 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Zend/zend_vm_handlers.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1353,7 +1353,7 @@
13531353
_(2544, ZEND_FETCH_GLOBALS_SPEC_UNUSED_UNUSED) \
13541354
_(2545, ZEND_VERIFY_NEVER_TYPE_SPEC_UNUSED_UNUSED) \
13551355
_(2546, ZEND_CALLABLE_CONVERT_SPEC_UNUSED_UNUSED) \
1356-
_(2547, ZEND_JMP_STATIC_DEF_SPEC) \
1356+
_(2547, ZEND_JMP_STATIC_DEF_SPEC_CV) \
13571357
_(2548, ZEND_RECV_NOTYPE_SPEC) \
13581358
_(2549, ZEND_JMP_FORWARD_SPEC) \
13591359
_(2555, ZEND_ADD_LONG_NO_OVERFLOW_SPEC_TMPVARCV_CONST) \

Zend/zend_vm_opcodes.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ static uint32_t zend_vm_opcodes_flags[204] = {
433433
0x00000101,
434434
0x00000101,
435435
0x00000101,
436-
0x00002000,
436+
0x00002001,
437437
};
438438

439439
ZEND_API const char* ZEND_FASTCALL zend_get_opcode_name(zend_uchar opcode) {

0 commit comments

Comments
 (0)