Skip to content

Commit cfd954f

Browse files
committed
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3: Fix GH-16499: [JIT] Undefined to null coercion issues for return
2 parents fd39e23 + 920e3d6 commit cfd954f

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

Zend/Optimizer/zend_inference.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3959,6 +3959,9 @@ static zend_always_inline zend_result _zend_update_type_info(
39593959
} else {
39603960
zend_arg_info *ret_info = op_array->arg_info - 1;
39613961
tmp = zend_fetch_arg_info_type(script, ret_info, &ce);
3962+
if ((tmp & MAY_BE_NULL) && opline->op1_type == IS_CV) {
3963+
tmp |= MAY_BE_UNDEF;
3964+
}
39623965
tmp |= (t1 & MAY_BE_INDIRECT);
39633966

39643967
// TODO: We could model more precisely how illegal types are converted.

ext/opcache/jit/zend_jit_helpers.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1831,6 +1831,12 @@ static bool ZEND_FASTCALL zend_jit_verify_arg_slow(zval *arg, zend_arg_info *arg
18311831

18321832
static void ZEND_FASTCALL zend_jit_verify_return_slow(zval *arg, const zend_op_array *op_array, zend_arg_info *arg_info, void **cache_slot)
18331833
{
1834+
if (Z_TYPE_P(arg) == IS_NULL) {
1835+
ZEND_ASSERT(ZEND_TYPE_IS_SET(arg_info->type));
1836+
if (EXPECTED(ZEND_TYPE_CONTAINS_CODE(arg_info->type, IS_NULL))) {
1837+
return;
1838+
}
1839+
}
18341840
if (UNEXPECTED(!zend_check_user_type_slow(
18351841
&arg_info->type, arg, /* ref */ NULL, cache_slot, /* is_return_type */ true))) {
18361842
zend_verify_return_error((zend_function*)op_array, arg);

ext/opcache/tests/jit/gh16499.phpt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
--TEST--
2+
GH-16499 (Undefined to null coercion issues for return)
3+
--EXTENSIONS--
4+
opcache
5+
--INI--
6+
opcache.jit_buffer_size=64M
7+
--FILE--
8+
<?php
9+
function test($cond): ?int {
10+
if ($cond) {
11+
$i = 'foo';
12+
}
13+
return $i;
14+
}
15+
16+
var_dump(test(false));
17+
var_dump(test(false));
18+
?>
19+
--EXPECTF--
20+
Warning: Undefined variable $i in %sgh16499.php on line 6
21+
22+
Warning: Undefined variable $i in %sgh16499.php on line 6
23+
NULL
24+
25+
Warning: Undefined variable $i in %sgh16499.php on line 6
26+
27+
Warning: Undefined variable $i in %sgh16499.php on line 6
28+
NULL

0 commit comments

Comments
 (0)