Skip to content

Commit

Permalink
Don't replace tmp with cv in YIELD argument
Browse files Browse the repository at this point in the history
For by-ref generators, these may have different behavior.

Fixes oss-fuzz 6059739298004992.
  • Loading branch information
nikic committed Oct 12, 2021
1 parent 845a67f commit 9ebe849
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
21 changes: 21 additions & 0 deletions Zend/tests/generators/yield_by_reference_optimization.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
--TEST--
Make sure optimization does not interfere with yield by ref
--FILE--
<?php

function &gen() {
yield $v = 0;
yield $v = 1;
}

foreach (gen() as $v) {
var_dump($v);
}

?>
--EXPECTF--
Notice: Only variable references should be yielded by reference in %s on line %d
int(0)

Notice: Only variable references should be yielded by reference in %s on line %d
int(1)
3 changes: 2 additions & 1 deletion ext/opcache/Optimizer/dfa_pass.c
Original file line number Diff line number Diff line change
Expand Up @@ -1010,7 +1010,8 @@ static int zend_dfa_try_to_replace_result(zend_op_array *op_array, zend_ssa *ssa
&& op_array->opcodes[use].opcode != ZEND_FREE
&& op_array->opcodes[use].opcode != ZEND_SEND_VAL
&& op_array->opcodes[use].opcode != ZEND_SEND_VAL_EX
&& op_array->opcodes[use].opcode != ZEND_VERIFY_RETURN_TYPE) {
&& op_array->opcodes[use].opcode != ZEND_VERIFY_RETURN_TYPE
&& op_array->opcodes[use].opcode != ZEND_YIELD) {
if (use > def) {
int i = use;
const zend_op *opline = &op_array->opcodes[use];
Expand Down

0 comments on commit 9ebe849

Please sign in to comment.