Skip to content

Commit f852fb7

Browse files
committed
Merge branch 'PHP-8.5' into PHP-8.6
* PHP-8.5: Fix JIT SWITCH_STRING type checks on referenced operand
2 parents f817620 + c647ee5 commit f852fb7

4 files changed

Lines changed: 57 additions & 2 deletions

File tree

‎NEWS‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ PHP NEWS
7070
. Fixed bug GH-24675 (function with >~1.7 MB of machine code corrupts JIT
7171
buffer accounting). (ndossche)
7272
. Call orig_post_shutdown_cb(). (ndossche)
73+
. Fixed JIT segfault on switch over a string reference holding a
74+
non-string value. (jorgsowa)
7375

7476
- OpenSSL:
7577
. Fixed build with OpenSSL 4.1. (Weilin Du)

‎ext/opcache/jit/zend_jit_ir.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16569,7 +16569,7 @@ static int zend_jit_switch(zend_jit_ctx *jit, const zend_op *opline, const zend_
1656916569
if (fallback_label) {
1657016570
jit_guard_Z_TYPE(jit, op1_addr, IS_REFERENCE, fallback_label);
1657116571
} else {
16572-
ir_ref if_ref = jit_if_Z_TYPE(jit, op1_addr, IS_STRING);
16572+
ir_ref if_ref = jit_if_Z_TYPE(jit, op1_addr, IS_REFERENCE);
1657316573
ir_IF_FALSE_cold(if_ref);
1657416574
ir_refs_add(slow_inputs, ir_END());
1657516575
ir_IF_TRUE(if_ref);
@@ -16579,7 +16579,7 @@ static int zend_jit_switch(zend_jit_ctx *jit, const zend_op *opline, const zend_
1657916579
op1_addr = ZEND_ADDR_REF_ZVAL(ref2);
1658016580

1658116581
if (fallback_label) {
16582-
jit_guard_Z_TYPE(jit, op1_addr, IS_LONG, fallback_label);
16582+
jit_guard_Z_TYPE(jit, op1_addr, IS_STRING, fallback_label);
1658316583
} else {
1658416584
if_string = jit_if_Z_TYPE(jit, op1_addr, IS_STRING);
1658516585
ir_IF_FALSE_cold(if_string);
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
--TEST--
2+
JIT SWITCH_STRING on a reference holding a non-string value
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.file_update_protection=0
7+
opcache.jit=tracing
8+
opcache.jit_hot_loop=1
9+
--EXTENSIONS--
10+
opcache
11+
--FILE--
12+
<?php
13+
function test($a) {
14+
$n = 0;
15+
foreach ($a as &$x) {
16+
switch ($x) {
17+
case "a": case "b": $n++; break;
18+
}
19+
}
20+
return $n;
21+
}
22+
var_dump(test(["a"]));
23+
var_dump(test([1]));
24+
?>
25+
--EXPECT--
26+
int(1)
27+
int(0)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
--TEST--
2+
JIT SWITCH_STRING on a reference (function JIT)
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.file_update_protection=0
7+
opcache.jit=function
8+
--EXTENSIONS--
9+
opcache
10+
--FILE--
11+
<?php
12+
function test($a) {
13+
$n = 0;
14+
foreach ($a as &$x) {
15+
switch ($x) {
16+
case "a": case "b": $n++; break;
17+
}
18+
}
19+
return $n;
20+
}
21+
var_dump(test(["a", "b", "c"]));
22+
var_dump(test([1]));
23+
?>
24+
--EXPECT--
25+
int(2)
26+
int(0)

0 commit comments

Comments
 (0)