Skip to content

Commit fbe6696

Browse files
committed
Revert "Use zend_ast_apply in zend_eval_const_expr (#11261)"
This reverts commit 1c733c8. Fixes GH-11320
1 parent 8ed66b4 commit fbe6696

File tree

1 file changed

+46
-24
lines changed

1 file changed

+46
-24
lines changed

Zend/zend_compile.c

Lines changed: 46 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10597,7 +10597,7 @@ static zend_op *zend_delayed_compile_var(znode *result, zend_ast *ast, uint32_t
1059710597
}
1059810598
/* }}} */
1059910599

10600-
static void zend_eval_const_expr_inner(zend_ast **ast_ptr, void *ctx) /* {{{ */
10600+
static void zend_eval_const_expr(zend_ast **ast_ptr) /* {{{ */
1060110601
{
1060210602
zend_ast *ast = *ast_ptr;
1060310603
zval result;
@@ -10606,25 +10606,10 @@ static void zend_eval_const_expr_inner(zend_ast **ast_ptr, void *ctx) /* {{{ */
1060610606
return;
1060710607
}
1060810608

10609-
/* Set isset fetch indicator here, opcache disallows runtime altering of the AST */
10610-
if (ast->kind == ZEND_AST_DIM
10611-
&& (ast->attr & ZEND_DIM_IS)
10612-
&& ast->child[0]->kind == ZEND_AST_DIM) {
10613-
ast->child[0]->attr |= ZEND_DIM_IS;
10614-
}
10615-
10616-
/* We don't want to evaluate the class name of ZEND_AST_CLASS_NAME nodes. We need to be able to
10617-
* differenciate between literal class names and expressions that evaluate to strings. Strings
10618-
* are not actually allowed in ::class expressions.
10619-
*
10620-
* ZEND_AST_COALESCE and ZEND_AST_CONDITIONAL will manually evaluate only the children for the
10621-
* taken paths. */
10622-
if (ast->kind != ZEND_AST_CLASS_NAME && ast->kind != ZEND_AST_COALESCE && ast->kind != ZEND_AST_CONDITIONAL) {
10623-
zend_ast_apply(ast, zend_eval_const_expr_inner, ctx);
10624-
}
10625-
1062610609
switch (ast->kind) {
1062710610
case ZEND_AST_BINARY_OP:
10611+
zend_eval_const_expr(&ast->child[0]);
10612+
zend_eval_const_expr(&ast->child[1]);
1062810613
if (ast->child[0]->kind != ZEND_AST_ZVAL || ast->child[1]->kind != ZEND_AST_ZVAL) {
1062910614
return;
1063010615
}
@@ -10637,6 +10622,8 @@ static void zend_eval_const_expr_inner(zend_ast **ast_ptr, void *ctx) /* {{{ */
1063710622
break;
1063810623
case ZEND_AST_GREATER:
1063910624
case ZEND_AST_GREATER_EQUAL:
10625+
zend_eval_const_expr(&ast->child[0]);
10626+
zend_eval_const_expr(&ast->child[1]);
1064010627
if (ast->child[0]->kind != ZEND_AST_ZVAL || ast->child[1]->kind != ZEND_AST_ZVAL) {
1064110628
return;
1064210629
}
@@ -10648,6 +10635,8 @@ static void zend_eval_const_expr_inner(zend_ast **ast_ptr, void *ctx) /* {{{ */
1064810635
case ZEND_AST_OR:
1064910636
{
1065010637
bool child0_is_true, child1_is_true;
10638+
zend_eval_const_expr(&ast->child[0]);
10639+
zend_eval_const_expr(&ast->child[1]);
1065110640
if (ast->child[0]->kind != ZEND_AST_ZVAL) {
1065210641
return;
1065310642
}
@@ -10671,6 +10660,7 @@ static void zend_eval_const_expr_inner(zend_ast **ast_ptr, void *ctx) /* {{{ */
1067110660
break;
1067210661
}
1067310662
case ZEND_AST_UNARY_OP:
10663+
zend_eval_const_expr(&ast->child[0]);
1067410664
if (ast->child[0]->kind != ZEND_AST_ZVAL) {
1067510665
return;
1067610666
}
@@ -10681,6 +10671,7 @@ static void zend_eval_const_expr_inner(zend_ast **ast_ptr, void *ctx) /* {{{ */
1068110671
break;
1068210672
case ZEND_AST_UNARY_PLUS:
1068310673
case ZEND_AST_UNARY_MINUS:
10674+
zend_eval_const_expr(&ast->child[0]);
1068410675
if (ast->child[0]->kind != ZEND_AST_ZVAL) {
1068510676
return;
1068610677
}
@@ -10751,6 +10742,13 @@ static void zend_eval_const_expr_inner(zend_ast **ast_ptr, void *ctx) /* {{{ */
1075110742
zend_error(E_COMPILE_ERROR, "Array and string offset access syntax with curly braces is no longer supported");
1075210743
}
1075310744

10745+
/* Set isset fetch indicator here, opcache disallows runtime altering of the AST */
10746+
if ((ast->attr & ZEND_DIM_IS) && ast->child[0]->kind == ZEND_AST_DIM) {
10747+
ast->child[0]->attr |= ZEND_DIM_IS;
10748+
}
10749+
10750+
zend_eval_const_expr(&ast->child[0]);
10751+
zend_eval_const_expr(&ast->child[1]);
1075410752
if (ast->child[0]->kind != ZEND_AST_ZVAL || ast->child[1]->kind != ZEND_AST_ZVAL) {
1075510753
return;
1075610754
}
@@ -10828,6 +10826,9 @@ static void zend_eval_const_expr_inner(zend_ast **ast_ptr, void *ctx) /* {{{ */
1082810826
zend_ast *name_ast;
1082910827
zend_string *resolved_name;
1083010828

10829+
zend_eval_const_expr(&ast->child[0]);
10830+
zend_eval_const_expr(&ast->child[1]);
10831+
1083110832
if (UNEXPECTED(ast->child[1]->kind != ZEND_AST_ZVAL
1083210833
|| Z_TYPE_P(zend_ast_get_zval(ast->child[1])) != IS_STRING)) {
1083310834
return;
@@ -10857,6 +10858,33 @@ static void zend_eval_const_expr_inner(zend_ast **ast_ptr, void *ctx) /* {{{ */
1085710858
}
1085810859
break;
1085910860
}
10861+
// TODO: We should probably use zend_ast_apply to recursively walk nodes without
10862+
// special handling. It is required that all nodes that are part of a const expr
10863+
// are visited. Probably we should be distinguishing evaluation of const expr and
10864+
// normal exprs here.
10865+
case ZEND_AST_ARG_LIST:
10866+
{
10867+
zend_ast_list *list = zend_ast_get_list(ast);
10868+
for (uint32_t i = 0; i < list->children; i++) {
10869+
zend_eval_const_expr(&list->child[i]);
10870+
}
10871+
return;
10872+
}
10873+
case ZEND_AST_NEW:
10874+
zend_eval_const_expr(&ast->child[0]);
10875+
zend_eval_const_expr(&ast->child[1]);
10876+
return;
10877+
case ZEND_AST_NAMED_ARG:
10878+
zend_eval_const_expr(&ast->child[1]);
10879+
return;
10880+
case ZEND_AST_CONST_ENUM_INIT:
10881+
zend_eval_const_expr(&ast->child[2]);
10882+
return;
10883+
case ZEND_AST_PROP:
10884+
case ZEND_AST_NULLSAFE_PROP:
10885+
zend_eval_const_expr(&ast->child[0]);
10886+
zend_eval_const_expr(&ast->child[1]);
10887+
return;
1086010888
default:
1086110889
return;
1086210890
}
@@ -10865,9 +10893,3 @@ static void zend_eval_const_expr_inner(zend_ast **ast_ptr, void *ctx) /* {{{ */
1086510893
*ast_ptr = zend_ast_create_zval(&result);
1086610894
}
1086710895
/* }}} */
10868-
10869-
10870-
static void zend_eval_const_expr(zend_ast **ast_ptr) /* {{{ */
10871-
{
10872-
zend_eval_const_expr_inner(ast_ptr, NULL);
10873-
}

0 commit comments

Comments
 (0)