Skip to content

Commit f4a2e33

Browse files
committed
Merge branch 'PHP-8.5'
* PHP-8.5: Fix function JIT JMPNZ smart branch
2 parents 75ed209 + 559b3fe commit f4a2e33

File tree

3 files changed

+53
-3
lines changed

3 files changed

+53
-3
lines changed

ext/opcache/jit/zend_jit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2891,7 +2891,7 @@ static int zend_jit(const zend_op_array *op_array, zend_ssa *ssa, const zend_op
28912891
if (i == end
28922892
&& (opline->result_type & (IS_SMART_BRANCH_JMPZ|IS_SMART_BRANCH_JMPNZ)) != 0) {
28932893
/* smart branch split across basic blocks */
2894-
if (!zend_jit_set_cond(&ctx, opline + 2, opline->result.var)) {
2894+
if (!zend_jit_set_cond(&ctx, opline, opline + 2, opline->result.var)) {
28952895
goto jit_failure;
28962896
}
28972897
}

ext/opcache/jit/zend_jit_ir.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3967,11 +3967,12 @@ static int zend_jit_cond_jmp(zend_jit_ctx *jit, const zend_op *next_opline, int
39673967
return 1;
39683968
}
39693969

3970-
static int zend_jit_set_cond(zend_jit_ctx *jit, const zend_op *next_opline, uint32_t var)
3970+
static int zend_jit_set_cond(zend_jit_ctx *jit, const zend_op *opline, const zend_op *next_opline, uint32_t var)
39713971
{
39723972
ir_ref ref;
39733973

3974-
ref = ir_ADD_U32(ir_ZEXT_U32(jit_CMP_IP(jit, IR_EQ, next_opline)), ir_CONST_U32(IS_FALSE));
3974+
ir_op op = (opline->result_type & IS_SMART_BRANCH_JMPZ) ? IR_EQ : IR_NE;
3975+
ref = ir_ADD_U32(ir_ZEXT_U32(jit_CMP_IP(jit, op, next_opline)), ir_CONST_U32(IS_FALSE));
39753976

39763977
// EX_VAR(var) = ...
39773978
ir_STORE(ir_ADD_OFFSET(jit_FP(jit), var + offsetof(zval, u1.type_info)), ref);

ext/opcache/tests/jit/gh21593.phpt

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
--TEST--
2+
GH-21593: Function JIT JMPNZ smart branch
3+
--CREDITS--
4+
paulmhh
5+
--EXTENSIONS--
6+
opcache
7+
--INI--
8+
opcache.enable=1
9+
opcache.enable_cli=1
10+
opcache.jit=function
11+
--FILE--
12+
<?php
13+
14+
function test1($a) {
15+
if (isset($a?->a)) {
16+
echo "1\n";
17+
}
18+
}
19+
20+
function test2($a) {
21+
if (!isset($a?->a)) {
22+
echo "2\n";
23+
}
24+
}
25+
26+
function test3($a) {
27+
if (empty($a?->a)) {
28+
echo "3\n";
29+
}
30+
}
31+
32+
function test4($a) {
33+
if (!empty($a?->a)) {
34+
echo "4\n";
35+
}
36+
}
37+
38+
$a = new stdClass;
39+
$a->a = 'a';
40+
41+
test1($a);
42+
test2($a);
43+
test3($a);
44+
test4($a);
45+
46+
?>
47+
--EXPECT--
48+
1
49+
4

0 commit comments

Comments
 (0)