Skip to content

Commit be3c9b0

Browse files
committed
Fit JIT variable not stored before YIELD
1 parent 0fc3a2e commit be3c9b0

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

ext/opcache/jit/zend_jit_vm_helpers.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -937,11 +937,18 @@ zend_jit_trace_stop ZEND_FASTCALL zend_jit_trace_execute(zend_execute_data *ex,
937937
break;
938938
}
939939

940+
#ifdef HAVE_GCC_GLOBAL_REGS
941+
const zend_op *prev_opline = opline;
942+
#endif
940943
handler = (zend_vm_opcode_handler_t)ZEND_OP_TRACE_INFO(opline, offset)->call_handler;
941944
#ifdef HAVE_GCC_GLOBAL_REGS
942945
handler();
943946
if (UNEXPECTED(opline == zend_jit_halt_op)) {
944-
stop = ZEND_JIT_TRACE_STOP_RETURN;
947+
if (prev_opline->opcode == ZEND_YIELD) {
948+
stop = ZEND_JIT_TRACE_STOP_INTERPRETER;
949+
} else {
950+
stop = ZEND_JIT_TRACE_STOP_RETURN;
951+
}
945952
opline = NULL;
946953
halt = ZEND_JIT_TRACE_HALT;
947954
break;
@@ -951,7 +958,11 @@ zend_jit_trace_stop ZEND_FASTCALL zend_jit_trace_execute(zend_execute_data *ex,
951958
rc = handler(ZEND_OPCODE_HANDLER_ARGS_PASSTHRU);
952959
if (rc != 0) {
953960
if (rc < 0) {
954-
stop = ZEND_JIT_TRACE_STOP_RETURN;
961+
if (opline->opcode == ZEND_YIELD) {
962+
stop = ZEND_JIT_TRACE_STOP_INTERPRETER;
963+
} else {
964+
stop = ZEND_JIT_TRACE_STOP_RETURN;
965+
}
955966
opline = NULL;
956967
halt = ZEND_JIT_TRACE_HALT;
957968
break;

ext/opcache/tests/jit/gh19493.phpt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
--TEST--
2+
GH-19493: Var not stored before YIELD
3+
--FILE--
4+
<?php
5+
6+
function f() {
7+
$offset = 0;
8+
yield true;
9+
for ($i = 0; $i < 100; $i++) {
10+
$offset++;
11+
if ($offset === 99) {
12+
break;
13+
}
14+
yield true;
15+
}
16+
return $offset;
17+
}
18+
$gen = f();
19+
foreach ($gen as $v) {}
20+
var_dump($gen->getReturn());
21+
22+
?>
23+
--EXPECT--
24+
int(99)

0 commit comments

Comments
 (0)