Skip to content

Commit f890c9c

Browse files
committed
Fix return type verification with undef var
This was loading EG(uninitialized_value) into r0 rather than FCARG1a. However, if we fix this issue an existing test fails because the undef var warning promoted to exception is not caught early enough, so we need to explicitly check for the exception before performing the type check.
1 parent 22ef1fb commit f890c9c

File tree

2 files changed

+34
-6
lines changed

2 files changed

+34
-6
lines changed

ext/opcache/jit/zend_jit_x86.dasc

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14854,29 +14854,33 @@ static zend_bool zend_jit_verify_return_type(dasm_State **Dst, const zend_op *op
1485414854
needs_slow_check = 0;
1485514855
} else if (is_power_of_two(type_mask)) {
1485614856
uint32_t type_code = concrete_type(type_mask);
14857-
| IF_NOT_ZVAL_TYPE op1_addr, type_code, >7
14857+
| IF_NOT_ZVAL_TYPE op1_addr, type_code, >6
1485814858
} else {
1485914859
| mov edx, 1
1486014860
| GET_ZVAL_TYPE cl, op1_addr
1486114861
| shl edx, cl
1486214862
| test edx, type_mask
14863-
| je >7
14863+
| je >6
1486414864
}
1486514865
}
1486614866
if (needs_slow_check) {
1486714867
if (slow_check_in_cold) {
1486814868
|.cold_code
14869-
|7:
14869+
|6:
1487014870
}
1487114871
| SET_EX_OPLINE opline, r1
1487214872
if (op1_info & MAY_BE_UNDEF) {
14873-
| IF_NOT_ZVAL_TYPE op1_addr, IS_UNDEF, >8
14873+
| IF_NOT_ZVAL_TYPE op1_addr, IS_UNDEF, >7
1487414874
| mov FCARG1a, opline->op1.var
1487514875
| EXT_CALL zend_jit_undefined_op_helper, FCARG2a
14876-
| LOAD_ADDR_ZTS r0, executor_globals, uninitialized_zval
14876+
| test r0, r0
14877+
| jz ->exception_handler
14878+
| LOAD_ADDR_ZTS FCARG1a, executor_globals, uninitialized_zval
14879+
| jmp >8
1487714880
}
14878-
|8:
14881+
|7:
1487914882
| LOAD_ZVAL_ADDR FCARG1a, op1_addr
14883+
|8:
1488014884
| mov FCARG2a, EX->func
1488114885
|.if X64
1488214886
| LOAD_ADDR CARG3, (ptrdiff_t)arg_info
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
--TEST--
2+
VERIFY_RETURN with undef var
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.file_update_protection=0
7+
opcache.jit_buffer_size=1M
8+
--FILE--
9+
<?php
10+
11+
function test(): int {
12+
return $undef;
13+
}
14+
15+
try {
16+
test();
17+
} catch (TypeError $e) {
18+
echo $e->getMessage(), "\n";
19+
}
20+
21+
?>
22+
--EXPECTF--
23+
Warning: Undefined variable $undef in %s on line %d
24+
test(): Return value must be of type int, null returned

0 commit comments

Comments
 (0)