Skip to content

Commit 06275d9

Browse files
committed
JIT: fixed MUL+SEND optimization when MUL throws an exception
1 parent e22fb46 commit 06275d9

File tree

2 files changed

+40
-3
lines changed

2 files changed

+40
-3
lines changed

ext/opcache/jit/zend_jit_x86.dasc

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4831,7 +4831,11 @@ static int zend_jit_math_helper(dasm_State **Dst,
48314831
| FREE_OP op1_type, op1, op1_info, 0, opline
48324832
| FREE_OP op2_type, op2, op2_info, 0, opline
48334833
if (may_throw) {
4834-
zend_jit_check_exception(Dst);
4834+
if (Z_MODE(res_addr) == IS_MEM_ZVAL && Z_REG(res_addr) == ZREG_RX) {
4835+
zend_jit_check_exception_undef_result(Dst, opline);
4836+
} else {
4837+
zend_jit_check_exception(Dst);
4838+
}
48354839
}
48364840
if (Z_MODE(res_addr) == IS_REG) {
48374841
zend_jit_addr real_addr = ZEND_ADDR_MEM_ZVAL(ZREG_FP, res_var);
@@ -5167,7 +5171,11 @@ static int zend_jit_long_math_helper(dasm_State **Dst,
51675171
| FREE_OP op1_type, op1, op1_info, 0, opline
51685172
| FREE_OP op2_type, op2, op2_info, 0, opline
51695173
if (may_throw) {
5170-
zend_jit_check_exception(Dst);
5174+
if (Z_MODE(res_addr) == IS_MEM_ZVAL && Z_REG(res_addr) == ZREG_RX) {
5175+
zend_jit_check_exception_undef_result(Dst, opline);
5176+
} else {
5177+
zend_jit_check_exception(Dst);
5178+
}
51715179
}
51725180
if (Z_MODE(res_addr) == IS_REG) {
51735181
zend_jit_addr real_addr = ZEND_ADDR_MEM_ZVAL(ZREG_FP, res_var);
@@ -5281,7 +5289,11 @@ static int zend_jit_concat_helper(dasm_State **Dst,
52815289
| FREE_OP op1_type, op1, op1_info, 0, opline
52825290
| FREE_OP op2_type, op2, op2_info, 0, opline
52835291
if (may_throw) {
5284-
zend_jit_check_exception(Dst);
5292+
if (Z_MODE(res_addr) == IS_MEM_ZVAL && Z_REG(res_addr) == ZREG_RX) {
5293+
zend_jit_check_exception_undef_result(Dst, opline);
5294+
} else {
5295+
zend_jit_check_exception(Dst);
5296+
}
52855297
}
52865298
#if 1
52875299
if ((op1_info & MAY_BE_STRING) && (op2_info & MAY_BE_STRING)) {

ext/opcache/tests/jit/mul_005.phpt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
--TEST--
2+
JIT MUL: 005 exception and SEND optimization
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.file_update_protection=0
7+
opcache.jit_buffer_size=1M
8+
opcache.jit=function
9+
opcache.protect_memory=1
10+
--SKIPIF--
11+
<?php require_once('skipif.inc'); ?>
12+
--FILE--
13+
<?php
14+
function test($a) {
15+
var_dump(+$a);
16+
}
17+
18+
try {
19+
test('foo');
20+
} catch (TypeError $e) {
21+
echo $e->getMessage(), "\n";
22+
}
23+
?>
24+
--EXPECT--
25+
Unsupported operand types: string * int

0 commit comments

Comments
 (0)