Skip to content

Emit EXT_STMT after each pipe stage, and attach the TMP var that holds the intermediary result #19377

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Zend/Optimizer/block_pass.c
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,14 @@ static void zend_optimize_block(zend_basic_block *block, zend_op_array *op_array
}
break;

case ZEND_EXT_STMT:
if (opline->op1_type & (IS_TMP_VAR|IS_VAR)) {
/* Variable will be deleted later by FREE, so we can't optimize it */
Tsource[VAR_NUM(opline->op1.var)] = NULL;
break;
}
break;

case ZEND_CASE:
case ZEND_CASE_STRICT:
case ZEND_COPY_TMP:
Expand Down
18 changes: 12 additions & 6 deletions Zend/zend_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,8 @@ static void zend_do_free(znode *op1) /* {{{ */
} else {
while (opline >= CG(active_op_array)->opcodes) {
if ((opline->opcode == ZEND_FETCH_LIST_R ||
opline->opcode == ZEND_FETCH_LIST_W) &&
opline->opcode == ZEND_FETCH_LIST_W ||
opline->opcode == ZEND_EXT_STMT) &&
opline->op1_type == IS_VAR &&
opline->op1.var == op1->u.op.var) {
zend_emit_op(NULL, ZEND_FREE, op1, NULL);
Expand Down Expand Up @@ -1920,7 +1921,7 @@ static void zend_add_to_list(void *result, void *item) /* {{{ */
}
/* }}} */

static void zend_do_extended_stmt(void) /* {{{ */
static void zend_do_extended_stmt(znode* result) /* {{{ */
{
zend_op *opline;

Expand All @@ -1931,6 +1932,9 @@ static void zend_do_extended_stmt(void) /* {{{ */
opline = get_next_op();

opline->opcode = ZEND_EXT_STMT;
if (result) {
SET_NODE(opline->op1, result);
}
}
/* }}} */

Expand Down Expand Up @@ -6050,7 +6054,7 @@ static void zend_compile_for(zend_ast *ast) /* {{{ */

zend_update_jump_target_to_next(opnum_jmp);
zend_compile_for_expr_list(&result, cond_ast);
zend_do_extended_stmt();
zend_do_extended_stmt(NULL);

zend_emit_cond_jump(ZEND_JMPNZ, &result, opnum_start);

Expand Down Expand Up @@ -6171,7 +6175,7 @@ static void zend_compile_if(zend_ast *ast) /* {{{ */

if (i > 0) {
CG(zend_lineno) = cond_ast->lineno;
zend_do_extended_stmt();
zend_do_extended_stmt(NULL);
}

zend_compile_expr(&cond_node, cond_ast);
Expand Down Expand Up @@ -6500,6 +6504,8 @@ static void zend_compile_pipe(znode *result, zend_ast *ast)
}

zend_compile_expr(result, fcall_ast);
CG(zend_lineno) = fcall_ast->lineno;
zend_do_extended_stmt(result);
}

static void zend_compile_match(znode *result, zend_ast *ast)
Expand Down Expand Up @@ -8532,7 +8538,7 @@ static zend_op_array *zend_compile_func_decl_ex(
/* put the implicit return on the really last line */
CG(zend_lineno) = decl->end_lineno;

zend_do_extended_stmt();
zend_do_extended_stmt(NULL);
zend_emit_final_return(0);

pass_two(CG(active_op_array));
Expand Down Expand Up @@ -11602,7 +11608,7 @@ static void zend_compile_stmt(zend_ast *ast) /* {{{ */
CG(zend_lineno) = ast->lineno;

if ((CG(compiler_options) & ZEND_COMPILE_EXTENDED_STMT) && !zend_is_unticked_stmt(ast)) {
zend_do_extended_stmt();
zend_do_extended_stmt(NULL);
}

switch (ast->kind) {
Expand Down
3 changes: 2 additions & 1 deletion Zend/zend_opcode.c
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,8 @@ static bool keeps_op1_alive(zend_op *opline) {
|| opline->opcode == ZEND_MATCH_ERROR
|| opline->opcode == ZEND_FETCH_LIST_R
|| opline->opcode == ZEND_FETCH_LIST_W
|| opline->opcode == ZEND_COPY_TMP) {
|| opline->opcode == ZEND_COPY_TMP
|| opline->opcode == ZEND_EXT_STMT) {
return 1;
}
ZEND_ASSERT(opline->opcode != ZEND_FE_FETCH_R
Expand Down