Skip to content

Commit 559b3fe

Browse files
committed
Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4: Fix function JIT JMPNZ smart branch
2 parents d6a28fb + 455ae28 commit 559b3fe

File tree

4 files changed

+54
-3
lines changed

4 files changed

+54
-3
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ PHP NEWS
1515
- Opcache:
1616
. Fixed bug GH-21158 (JIT: Assertion jit->ra[var].flags & (1<<0) failed in
1717
zend_jit_use_reg). (Arnaud)
18+
. Fixed bug GH-21593 (Borked function JIT JMPNZ smart branch). (ilutov)
1819

1920
- DOM:
2021
. Fixed bug GH-21566 (Dom\XMLDocument::C14N() emits duplicate xmlns

ext/opcache/jit/zend_jit.c

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

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)