diff --git a/NEWS b/NEWS index a02f31271095..659f470f2f68 100644 --- a/NEWS +++ b/NEWS @@ -172,6 +172,8 @@ PHP NEWS . Fixed tracing JIT taking the wrong branch after a VM interrupt. (Brian Marks) . Fix JIT register allocation for ASSIGN to traced reference. (ndossche) + . Fixed bug GH-25756 (OPcache: "Invalid opcode 62/4/0" when assigning a + reference in a return). (Ilia Alshanetsky, Pratik Bhujel) - OpenSSL: . Fixed bug GH-25172 (TLS session reuse shares request-lifetime callback diff --git a/Zend/Optimizer/block_pass.c b/Zend/Optimizer/block_pass.c index 0601994479e6..f790c3bf620d 100644 --- a/Zend/Optimizer/block_pass.c +++ b/Zend/Optimizer/block_pass.c @@ -910,7 +910,7 @@ static void zend_optimize_block(zend_basic_block *block, zend_op_array *op_array case ZEND_RETURN: if (opline->op1_type == IS_TMP_VAR) { src = VAR_SOURCE(opline->op1); - if (src && src->opcode == ZEND_QM_ASSIGN) { + if (src && src->opcode == ZEND_QM_ASSIGN && src->op1_type != IS_VAR) { zend_op *op = src + 1; bool optimize = true; diff --git a/ext/opcache/tests/gh25756.phpt b/ext/opcache/tests/gh25756.phpt new file mode 100644 index 000000000000..30fb73083c4d --- /dev/null +++ b/ext/opcache/tests/gh25756.phpt @@ -0,0 +1,99 @@ +--TEST-- +GH-25756 (OPcache: "Invalid opcode 62/4/0" when assigning a reference in a return) +--EXTENSIONS-- +opcache +--INI-- +opcache.enable=1 +opcache.enable_cli=1 +--FILE-- +p = &$b; +} + +function test_assign_dim_ref() { + $b = 'dim_val'; + $arr = []; + return $arr[0] = &$b; +} + +class StaticPropHolder { + public static $p; +} + +function test_assign_static_prop_ref(&$b) { + return StaticPropHolder::$p = &$b; +} + +function test_list_by_ref() { + $arr = ['list_val']; + return [&$a] = $arr; +} + +function test_ternary_assign_ref(bool $cond) { + $b = 'ternary_val'; + return $cond ? ($a = &$b) : 'other'; +} + +function test_match_assign_ref(bool $cond) { + $b = 'match_val'; + return match ($cond) { + true => $a = &$b, + default => 'other', + }; +} + +function test_typed_assign_ref(): string { + $b = 'typed_val'; + return $a = &$b; +} + +$obj = new stdClass(); +$obj_src = 'obj_prop'; +$obj_ret = test_assign_obj_ref($obj, $obj_src); +$obj_src = 'obj_changed'; + +$static_src = 'static_prop'; +$static_ret = test_assign_static_prop_ref($static_src); +$static_src = 'static_changed'; + +$arrow_src = 'arrow_val'; +$arrow = fn() => $a = &$arrow_src; + +echo "1: ", test_assign_ref(), "\n"; +echo "2: ", test_assign_func_ref(), "\n"; +echo "3: ", $obj_ret, " / ", $obj->p, "\n"; +echo "4: ", test_assign_dim_ref(), "\n"; +echo "5: ", $static_ret, " / ", StaticPropHolder::$p, "\n"; +echo "6: ", implode(',', test_list_by_ref()), "\n"; +echo "7: ", test_ternary_assign_ref(true), "\n"; +echo "8: ", test_match_assign_ref(true), "\n"; +echo "9: ", test_typed_assign_ref(), "\n"; +echo "10: ", $arrow(), "\n"; +?> +--EXPECT-- +1: success +2: from_func +3: obj_prop / obj_changed +4: dim_val +5: static_prop / static_changed +6: list_val +7: ternary_val +8: match_val +9: typed_val +10: arrow_val