Skip to content

Commit f983373

Browse files
committed
Merge branch 'PHP-8.1'
* PHP-8.1: JIT: fixed MUL+SEND optimization when MUL throws an exception
2 parents f21a248 + 679bfb1 commit f983373

File tree

3 files changed

+55
-6
lines changed

3 files changed

+55
-6
lines changed

ext/opcache/jit/zend_jit_arm64.dasc

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4421,7 +4421,11 @@ static int zend_jit_math_helper(dasm_State **Dst,
44214421
| FREE_OP op1_type, op1, op1_info, 0, opline, ZREG_TMP1, ZREG_TMP2
44224422
| FREE_OP op2_type, op2, op2_info, 0, opline, ZREG_TMP1, ZREG_TMP2
44234423
if (may_throw) {
4424-
zend_jit_check_exception(Dst);
4424+
if (Z_MODE(res_addr) == IS_MEM_ZVAL && Z_REG(res_addr) == ZREG_RX) {
4425+
zend_jit_check_exception_undef_result(Dst, opline);
4426+
} else {
4427+
zend_jit_check_exception(Dst);
4428+
}
44254429
}
44264430
if (Z_MODE(res_addr) == IS_REG) {
44274431
zend_jit_addr real_addr = ZEND_ADDR_MEM_ZVAL(ZREG_FP, res_var);
@@ -4736,7 +4740,11 @@ static int zend_jit_long_math_helper(dasm_State **Dst,
47364740
| FREE_OP op1_type, op1, op1_info, 0, opline, ZREG_TMP1, ZREG_TMP2
47374741
| FREE_OP op2_type, op2, op2_info, 0, opline, ZREG_TMP1, ZREG_TMP2
47384742
if (may_throw) {
4739-
zend_jit_check_exception(Dst);
4743+
if (Z_MODE(res_addr) == IS_MEM_ZVAL && Z_REG(res_addr) == ZREG_RX) {
4744+
zend_jit_check_exception_undef_result(Dst, opline);
4745+
} else {
4746+
zend_jit_check_exception(Dst);
4747+
}
47404748
}
47414749
if (Z_MODE(res_addr) == IS_REG) {
47424750
zend_jit_addr real_addr = ZEND_ADDR_MEM_ZVAL(ZREG_FP, res_var);
@@ -4834,7 +4842,11 @@ static int zend_jit_concat_helper(dasm_State **Dst,
48344842
| FREE_OP op1_type, op1, op1_info, 0, opline, ZREG_TMP1, ZREG_TMP2
48354843
| FREE_OP op2_type, op2, op2_info, 0, opline, ZREG_TMP1, ZREG_TMP2
48364844
if (may_throw) {
4837-
zend_jit_check_exception(Dst);
4845+
if (Z_MODE(res_addr) == IS_MEM_ZVAL && Z_REG(res_addr) == ZREG_RX) {
4846+
zend_jit_check_exception_undef_result(Dst, opline);
4847+
} else {
4848+
zend_jit_check_exception(Dst);
4849+
}
48384850
}
48394851
if ((op1_info & MAY_BE_STRING) && (op2_info & MAY_BE_STRING)) {
48404852
| b <5

ext/opcache/jit/zend_jit_x86.dasc

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4844,7 +4844,11 @@ static int zend_jit_math_helper(dasm_State **Dst,
48444844
| FREE_OP op1_type, op1, op1_info, 0, opline
48454845
| FREE_OP op2_type, op2, op2_info, 0, opline
48464846
if (may_throw) {
4847-
zend_jit_check_exception(Dst);
4847+
if (Z_MODE(res_addr) == IS_MEM_ZVAL && Z_REG(res_addr) == ZREG_RX) {
4848+
zend_jit_check_exception_undef_result(Dst, opline);
4849+
} else {
4850+
zend_jit_check_exception(Dst);
4851+
}
48484852
}
48494853
if (Z_MODE(res_addr) == IS_REG) {
48504854
zend_jit_addr real_addr = ZEND_ADDR_MEM_ZVAL(ZREG_FP, res_var);
@@ -5177,7 +5181,11 @@ static int zend_jit_long_math_helper(dasm_State **Dst,
51775181
| FREE_OP op1_type, op1, op1_info, 0, opline
51785182
| FREE_OP op2_type, op2, op2_info, 0, opline
51795183
if (may_throw) {
5180-
zend_jit_check_exception(Dst);
5184+
if (Z_MODE(res_addr) == IS_MEM_ZVAL && Z_REG(res_addr) == ZREG_RX) {
5185+
zend_jit_check_exception_undef_result(Dst, opline);
5186+
} else {
5187+
zend_jit_check_exception(Dst);
5188+
}
51815189
}
51825190
if (Z_MODE(res_addr) == IS_REG) {
51835191
zend_jit_addr real_addr = ZEND_ADDR_MEM_ZVAL(ZREG_FP, res_var);
@@ -5293,7 +5301,11 @@ static int zend_jit_concat_helper(dasm_State **Dst,
52935301
| FREE_OP op1_type, op1, op1_info, 0, opline
52945302
| FREE_OP op2_type, op2, op2_info, 0, opline
52955303
if (may_throw) {
5296-
zend_jit_check_exception(Dst);
5304+
if (Z_MODE(res_addr) == IS_MEM_ZVAL && Z_REG(res_addr) == ZREG_RX) {
5305+
zend_jit_check_exception_undef_result(Dst, opline);
5306+
} else {
5307+
zend_jit_check_exception(Dst);
5308+
}
52975309
}
52985310
#if 1
52995311
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+
--EXTENSIONS--
11+
opcache
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)