Skip to content

Commit 8c22d3e

Browse files
committed
Make FETCH_R/IS, FETCH_DIM_R/IS, FETCH_OBJ_R/IS, FETCH_STATIC_PROP_R/IS return TMP_VAR, instead of VAR.
1 parent 49a4e69 commit 8c22d3e

File tree

4 files changed

+21
-13
lines changed

4 files changed

+21
-13
lines changed

Zend/zend_compile.c

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1903,12 +1903,14 @@ ZEND_API size_t zend_dirname(char *path, size_t len)
19031903
}
19041904
/* }}} */
19051905

1906-
static void zend_adjust_for_fetch_type(zend_op *opline, uint32_t type) /* {{{ */
1906+
static void zend_adjust_for_fetch_type(zend_op *opline, znode *result, uint32_t type) /* {{{ */
19071907
{
19081908
zend_uchar factor = (opline->opcode == ZEND_FETCH_STATIC_PROP_R) ? 1 : 3;
19091909

19101910
switch (type) {
19111911
case BP_VAR_R:
1912+
opline->result_type = IS_TMP_VAR;
1913+
result->op_type = IS_TMP_VAR;
19121914
return;
19131915
case BP_VAR_W:
19141916
opline->opcode += 1 * factor;
@@ -1917,6 +1919,8 @@ static void zend_adjust_for_fetch_type(zend_op *opline, uint32_t type) /* {{{ */
19171919
opline->opcode += 2 * factor;
19181920
return;
19191921
case BP_VAR_IS:
1922+
opline->result_type = IS_TMP_VAR;
1923+
result->op_type = IS_TMP_VAR;
19201924
opline->opcode += 3 * factor;
19211925
return;
19221926
case BP_VAR_FUNC_ARG:
@@ -2598,7 +2602,7 @@ static zend_op *zend_compile_simple_var_no_cv(znode *result, zend_ast *ast, uint
25982602
opline->extended_value = ZEND_FETCH_LOCAL;
25992603
}
26002604

2601-
zend_adjust_for_fetch_type(opline, type);
2605+
zend_adjust_for_fetch_type(opline, result, type);
26022606
return opline;
26032607
}
26042608
/* }}} */
@@ -2617,7 +2621,11 @@ static zend_bool is_this_fetch(zend_ast *ast) /* {{{ */
26172621
static void zend_compile_simple_var(znode *result, zend_ast *ast, uint32_t type, int delayed) /* {{{ */
26182622
{
26192623
if (is_this_fetch(ast)) {
2620-
zend_emit_op(result, ZEND_FETCH_THIS, NULL, NULL);
2624+
zend_op *opline = zend_emit_op(result, ZEND_FETCH_THIS, NULL, NULL);
2625+
if ((type == BP_VAR_R) || (type == BP_VAR_IS)) {
2626+
opline->result_type = IS_TMP_VAR;
2627+
result->op_type = IS_TMP_VAR;
2628+
}
26212629
} else if (zend_try_compile_cv(result, ast) == FAILURE) {
26222630
zend_compile_simple_var_no_cv(result, ast, type, delayed);
26232631
}
@@ -2676,7 +2684,7 @@ static zend_op *zend_delayed_compile_dim(znode *result, zend_ast *ast, uint32_t
26762684
}
26772685

26782686
opline = zend_delayed_emit_op(result, ZEND_FETCH_DIM_R, &var_node, &dim_node);
2679-
zend_adjust_for_fetch_type(opline, type);
2687+
zend_adjust_for_fetch_type(opline, result, type);
26802688
return opline;
26812689
}
26822690
/* }}} */
@@ -2711,7 +2719,7 @@ static zend_op *zend_delayed_compile_prop(znode *result, zend_ast *ast, uint32_t
27112719
opline->extended_value = zend_alloc_polymorphic_cache_slot();
27122720
}
27132721

2714-
zend_adjust_for_fetch_type(opline, type);
2722+
zend_adjust_for_fetch_type(opline, result, type);
27152723
return opline;
27162724
}
27172725
/* }}} */
@@ -2756,7 +2764,7 @@ zend_op *zend_compile_static_prop(znode *result, zend_ast *ast, uint32_t type, i
27562764
SET_NODE(opline->op2, &class_node);
27572765
}
27582766

2759-
zend_adjust_for_fetch_type(opline, type);
2767+
zend_adjust_for_fetch_type(opline, result, type);
27602768
return opline;
27612769
}
27622770
/* }}} */
@@ -3216,7 +3224,7 @@ uint32_t zend_compile_args(zend_ast *ast, zend_function *fbc) /* {{{ */
32163224
opcode = ZEND_SEND_REF;
32173225
} else {
32183226
zend_compile_var(&arg_node, arg, BP_VAR_R);
3219-
opcode = ZEND_SEND_VAR;
3227+
opcode = (arg_node.op_type == IS_TMP_VAR) ? ZEND_SEND_VAL : ZEND_SEND_VAR;
32203228
}
32213229
} else {
32223230
do {

ext/opcache/tests/opt/sccp_006.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ L1 (3): T2 = INIT_ARRAY 3 int(1) string("a")
2828
L2 (3): T2 = ADD_ARRAY_ELEMENT int(2) string("a")
2929
L3 (3): T2 = ADD_ARRAY_ELEMENT CV0($x) string("a")
3030
L4 (3): CV1($a) = QM_ASSIGN T2
31-
L5 (4): V2 = FETCH_DIM_R CV1($a) string("a")
32-
L6 (4): ECHO V2
31+
L5 (4): T2 = FETCH_DIM_R CV1($a) string("a")
32+
L6 (4): ECHO T2
3333
L7 (5): RETURN null
3434
LIVE RANGES:
3535
2: L2 - L4 (tmp/var)

ext/opcache/tests/opt/sccp_008.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,6 @@ L1 (3): JMPZ CV0($x) L4
3232
L2 (4): CV1($a) = QM_ASSIGN array(...)
3333
L3 (4): JMP L5
3434
L4 (6): CV1($a) = QM_ASSIGN array(...)
35-
L5 (8): V2 = FETCH_DIM_R CV1($a) int(1)
36-
L6 (8): ECHO V2
35+
L5 (8): T2 = FETCH_DIM_R CV1($a) int(1)
36+
L6 (8): ECHO T2
3737
L7 (9): RETURN null

ext/opcache/tests/opt/sccp_022.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,6 @@ L4 (4): OP_DATA int(5)
3434
L5 (5): ECHO int(5)
3535
L6 (6): ASSIGN_OBJ CV1($a) string("foo")
3636
L7 (6): OP_DATA int(5)
37-
L8 (7): V2 = FETCH_DIM_R CV1($a) int(1)
38-
L9 (7): ECHO V2
37+
L8 (7): T2 = FETCH_DIM_R CV1($a) int(1)
38+
L9 (7): ECHO T2
3939
L10 (8): RETURN null

0 commit comments

Comments
 (0)