Skip to content

Commit eef3e5e

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

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
@@ -1917,6 +1917,12 @@ static bool ZEND_FASTCALL zend_jit_verify_arg_slow(zval *arg, zend_arg_info *arg
19171917

19181918
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)
19191919
{
1920+
if (Z_TYPE_P(arg) == IS_NULL) {
1921+
ZEND_ASSERT(ZEND_TYPE_IS_SET(arg_info->type));
1922+
if (EXPECTED(ZEND_TYPE_CONTAINS_CODE(arg_info->type, IS_NULL))) {
1923+
return;
1924+
}
1925+
}
19201926
if (UNEXPECTED(!zend_check_user_type_slow(
19211927
&arg_info->type, arg, /* ref */ NULL, cache_slot, /* is_return_type */ true))) {
19221928
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)