Skip to content

Commit 5cbea46

Browse files
committed
Clean unfinished calls correctly
1 parent 06bacd6 commit 5cbea46

File tree

9 files changed

+598
-561
lines changed

9 files changed

+598
-561
lines changed

Zend/tests/match/block_003.phpt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
--TEST--
22
Match blocks
3-
--XFAIL--
43
--FILE--
54
<?php
65

Zend/zend_compile.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ void zend_oparray_context_begin(zend_oparray_context *prev_context) /* {{{ */
316316
CG(context).last_brk_cont = 0;
317317
CG(context).brk_cont_array = NULL;
318318
CG(context).labels = NULL;
319+
CG(context).has_unfinished_calls = false;
319320
}
320321
/* }}} */
321322

@@ -3991,6 +3992,9 @@ static bool zend_compile_call_common(znode *result, zend_ast *args_ast, zend_fun
39913992
return true;
39923993
}
39933994

3995+
bool prev_unfinished_calls = CG(context).has_unfinished_calls;
3996+
CG(context).has_unfinished_calls = true;
3997+
39943998
bool may_have_extra_named_args;
39953999
uint32_t arg_count = zend_compile_args(args_ast, fbc, &may_have_extra_named_args);
39964000

@@ -4009,6 +4013,7 @@ static bool zend_compile_call_common(znode *result, zend_ast *args_ast, zend_fun
40094013
}
40104014
opline->lineno = lineno;
40114015
zend_do_extended_fcall_end();
4016+
CG(context).has_unfinished_calls = prev_unfinished_calls;
40124017
return false;
40134018
}
40144019
/* }}} */
@@ -5175,6 +5180,11 @@ static bool zend_handle_loops_and_finally_ex(zend_long depth, uint32_t excluded_
51755180
if (!loop_var) {
51765181
return 1;
51775182
}
5183+
5184+
if (CG(context).has_unfinished_calls) {
5185+
zend_emit_op(NULL, ZEND_CLEAN_UNFINISHED_CALLS, NULL, NULL);
5186+
}
5187+
51785188
if (depth == -1) {
51795189
depth = zend_stack_count(&CG(loop_var_stack)) + 1;
51805190
}

Zend/zend_compile.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,8 @@ typedef struct _zend_oparray_context {
189189
int last_brk_cont;
190190
zend_brk_cont_element *brk_cont_array;
191191
HashTable *labels;
192+
/* Whether we're currently evaluating function arguments. */
193+
bool has_unfinished_calls;
192194
} zend_oparray_context;
193195

194196
/* Class, property and method flags class|meth.|prop.|const*/

Zend/zend_vm_def.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9548,6 +9548,14 @@ ZEND_VM_HANDLER(202, ZEND_CALLABLE_CONVERT, UNUSED, UNUSED)
95489548
ZEND_VM_NEXT_OPCODE();
95499549
}
95509550

9551+
ZEND_VM_HANDLER(204, ZEND_CLEAN_UNFINISHED_CALLS, UNUSED, UNUSED)
9552+
{
9553+
USE_OPLINE
9554+
uint32_t opnum = opline - EX(func)->op_array.opcodes;
9555+
cleanup_unfinished_calls(execute_data, opnum);
9556+
ZEND_VM_NEXT_OPCODE();
9557+
}
9558+
95519559
ZEND_VM_HOT_TYPE_SPEC_HANDLER(ZEND_JMP, (OP_JMP_ADDR(op, op->op1) > op), ZEND_JMP_FORWARD, JMP_ADDR, ANY)
95529560
{
95539561
USE_OPLINE

0 commit comments

Comments
 (0)