Skip to content

Commit 9fbb019

Browse files
committed
Move adjust_for_fetch_type directly after emission
And drop the distinction between compile_X and compile_X_common. This avoids WTF moments like compile_simple_var_no_cv completely ignoring the BP_VAR type passed to it...
1 parent d9da166 commit 9fbb019

File tree

1 file changed

+21
-40
lines changed

1 file changed

+21
-40
lines changed

Zend/zend_compile.c

Lines changed: 21 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2610,6 +2610,7 @@ static zend_op *zend_compile_simple_var_no_cv(znode *result, zend_ast *ast, uint
26102610
opline->extended_value = ZEND_FETCH_LOCAL;
26112611
}
26122612

2613+
zend_adjust_for_fetch_type(opline, type);
26132614
return opline;
26142615
}
26152616
/* }}} */
@@ -2630,8 +2631,7 @@ static void zend_compile_simple_var(znode *result, zend_ast *ast, uint32_t type,
26302631
if (is_this_fetch(ast)) {
26312632
zend_emit_op(result, ZEND_FETCH_THIS, NULL, NULL);
26322633
} else if (zend_try_compile_cv(result, ast) == FAILURE) {
2633-
zend_op *opline = zend_compile_simple_var_no_cv(result, ast, type, delayed);
2634-
zend_adjust_for_fetch_type(opline, type);
2634+
zend_compile_simple_var_no_cv(result, ast, type, delayed);
26352635
}
26362636
}
26372637
/* }}} */
@@ -2672,6 +2672,7 @@ static zend_op *zend_delayed_compile_dim(znode *result, zend_ast *ast, uint32_t
26722672
{
26732673
zend_ast *var_ast = ast->child[0];
26742674
zend_ast *dim_ast = ast->child[1];
2675+
zend_op *opline;
26752676

26762677
znode var_node, dim_node;
26772678

@@ -2691,25 +2692,20 @@ static zend_op *zend_delayed_compile_dim(znode *result, zend_ast *ast, uint32_t
26912692
zend_handle_numeric_op(&dim_node);
26922693
}
26932694

2694-
return zend_delayed_emit_op(result, ZEND_FETCH_DIM_R, &var_node, &dim_node);
2695+
opline = zend_delayed_emit_op(result, ZEND_FETCH_DIM_R, &var_node, &dim_node);
2696+
zend_adjust_for_fetch_type(opline, type);
2697+
return opline;
26952698
}
26962699
/* }}} */
26972700

2698-
static inline zend_op *zend_compile_dim_common(znode *result, zend_ast *ast, uint32_t type) /* {{{ */
2701+
static zend_op *zend_compile_dim(znode *result, zend_ast *ast, uint32_t type) /* {{{ */
26992702
{
27002703
uint32_t offset = zend_delayed_compile_begin();
27012704
zend_delayed_compile_dim(result, ast, type);
27022705
return zend_delayed_compile_end(offset);
27032706
}
27042707
/* }}} */
27052708

2706-
void zend_compile_dim(znode *result, zend_ast *ast, uint32_t type) /* {{{ */
2707-
{
2708-
zend_op *opline = zend_compile_dim_common(result, ast, type);
2709-
zend_adjust_for_fetch_type(opline, type);
2710-
}
2711-
/* }}} */
2712-
27132709
static zend_op *zend_delayed_compile_prop(znode *result, zend_ast *ast, uint32_t type) /* {{{ */
27142710
{
27152711
zend_ast *obj_ast = ast->child[0];
@@ -2732,26 +2728,20 @@ static zend_op *zend_delayed_compile_prop(znode *result, zend_ast *ast, uint32_t
27322728
zend_alloc_polymorphic_cache_slot(opline->op2.constant);
27332729
}
27342730

2731+
zend_adjust_for_fetch_type(opline, type);
27352732
return opline;
27362733
}
27372734
/* }}} */
27382735

2739-
static zend_op *zend_compile_prop_common(znode *result, zend_ast *ast, uint32_t type) /* {{{ */
2736+
static zend_op *zend_compile_prop(znode *result, zend_ast *ast, uint32_t type) /* {{{ */
27402737
{
27412738
uint32_t offset = zend_delayed_compile_begin();
27422739
zend_delayed_compile_prop(result, ast, type);
27432740
return zend_delayed_compile_end(offset);
27442741
}
27452742
/* }}} */
27462743

2747-
void zend_compile_prop(znode *result, zend_ast *ast, uint32_t type) /* {{{ */
2748-
{
2749-
zend_op *opline = zend_compile_prop_common(result, ast, type);
2750-
zend_adjust_for_fetch_type(opline, type);
2751-
}
2752-
/* }}} */
2753-
2754-
zend_op *zend_compile_static_prop_common(znode *result, zend_ast *ast, uint32_t type, int delayed) /* {{{ */
2744+
zend_op *zend_compile_static_prop(znode *result, zend_ast *ast, uint32_t type, int delayed) /* {{{ */
27552745
{
27562746
zend_ast *class_ast = ast->child[0];
27572747
zend_ast *prop_ast = ast->child[1];
@@ -2780,14 +2770,8 @@ zend_op *zend_compile_static_prop_common(znode *result, zend_ast *ast, uint32_t
27802770
SET_NODE(opline->op2, &class_node);
27812771
}
27822772

2783-
return opline;
2784-
}
2785-
/* }}} */
2786-
2787-
void zend_compile_static_prop(znode *result, zend_ast *ast, uint32_t type, int delayed) /* {{{ */
2788-
{
2789-
zend_op *opline = zend_compile_static_prop_common(result, ast, type, delayed);
27902773
zend_adjust_for_fetch_type(opline, type);
2774+
return opline;
27912775
}
27922776
/* }}} */
27932777

@@ -4306,15 +4290,15 @@ void zend_compile_unset(zend_ast *ast) /* {{{ */
43064290
}
43074291
return;
43084292
case ZEND_AST_DIM:
4309-
opline = zend_compile_dim_common(NULL, var_ast, BP_VAR_UNSET);
4293+
opline = zend_compile_dim(NULL, var_ast, BP_VAR_UNSET);
43104294
opline->opcode = ZEND_UNSET_DIM;
43114295
return;
43124296
case ZEND_AST_PROP:
4313-
opline = zend_compile_prop_common(NULL, var_ast, BP_VAR_UNSET);
4297+
opline = zend_compile_prop(NULL, var_ast, BP_VAR_UNSET);
43144298
opline->opcode = ZEND_UNSET_OBJ;
43154299
return;
43164300
case ZEND_AST_STATIC_PROP:
4317-
opline = zend_compile_static_prop_common(NULL, var_ast, BP_VAR_UNSET, 0);
4301+
opline = zend_compile_static_prop(NULL, var_ast, BP_VAR_UNSET, 0);
43184302
opline->opcode = ZEND_UNSET_STATIC_PROP;
43194303
return;
43204304
EMPTY_SWITCH_DEFAULT_CASE()
@@ -7194,7 +7178,7 @@ void zend_compile_post_incdec(znode *result, zend_ast *ast) /* {{{ */
71947178
zend_ensure_writable_variable(var_ast);
71957179

71967180
if (var_ast->kind == ZEND_AST_PROP) {
7197-
zend_op *opline = zend_compile_prop_common(NULL, var_ast, BP_VAR_RW);
7181+
zend_op *opline = zend_compile_prop(NULL, var_ast, BP_VAR_RW);
71987182
opline->opcode = ast->kind == ZEND_AST_POST_INC ? ZEND_POST_INC_OBJ : ZEND_POST_DEC_OBJ;
71997183
zend_make_tmp_result(result, opline);
72007184
} else {
@@ -7214,7 +7198,7 @@ void zend_compile_pre_incdec(znode *result, zend_ast *ast) /* {{{ */
72147198
zend_ensure_writable_variable(var_ast);
72157199

72167200
if (var_ast->kind == ZEND_AST_PROP) {
7217-
zend_op *opline = zend_compile_prop_common(result, var_ast, BP_VAR_RW);
7201+
zend_op *opline = zend_compile_prop(result, var_ast, BP_VAR_RW);
72187202
opline->opcode = ast->kind == ZEND_AST_PRE_INC ? ZEND_PRE_INC_OBJ : ZEND_PRE_DEC_OBJ;
72197203
} else {
72207204
znode var_node;
@@ -7490,15 +7474,15 @@ void zend_compile_isset_or_empty(znode *result, zend_ast *ast) /* {{{ */
74907474
}
74917475
break;
74927476
case ZEND_AST_DIM:
7493-
opline = zend_compile_dim_common(result, var_ast, BP_VAR_IS);
7477+
opline = zend_compile_dim(result, var_ast, BP_VAR_IS);
74947478
opline->opcode = ZEND_ISSET_ISEMPTY_DIM_OBJ;
74957479
break;
74967480
case ZEND_AST_PROP:
7497-
opline = zend_compile_prop_common(result, var_ast, BP_VAR_IS);
7481+
opline = zend_compile_prop(result, var_ast, BP_VAR_IS);
74987482
opline->opcode = ZEND_ISSET_ISEMPTY_PROP_OBJ;
74997483
break;
75007484
case ZEND_AST_STATIC_PROP:
7501-
opline = zend_compile_static_prop_common(result, var_ast, BP_VAR_IS, 0);
7485+
opline = zend_compile_static_prop(result, var_ast, BP_VAR_IS, 0);
75027486
opline->opcode = ZEND_ISSET_ISEMPTY_STATIC_PROP;
75037487
break;
75047488
EMPTY_SWITCH_DEFAULT_CASE()
@@ -8363,18 +8347,15 @@ void zend_compile_var(znode *result, zend_ast *ast, uint32_t type) /* {{{ */
83638347

83648348
void zend_delayed_compile_var(znode *result, zend_ast *ast, uint32_t type) /* {{{ */
83658349
{
8366-
zend_op *opline;
83678350
switch (ast->kind) {
83688351
case ZEND_AST_VAR:
83698352
zend_compile_simple_var(result, ast, type, 1);
83708353
return;
83718354
case ZEND_AST_DIM:
8372-
opline = zend_delayed_compile_dim(result, ast, type);
8373-
zend_adjust_for_fetch_type(opline, type);
8355+
zend_delayed_compile_dim(result, ast, type);
83748356
return;
83758357
case ZEND_AST_PROP:
8376-
opline = zend_delayed_compile_prop(result, ast, type);
8377-
zend_adjust_for_fetch_type(opline, type);
8358+
zend_delayed_compile_prop(result, ast, type);
83788359
return;
83798360
case ZEND_AST_STATIC_PROP:
83808361
zend_compile_static_prop(result, ast, type, 1);

0 commit comments

Comments
 (0)