[php-src] master: Merge branch 'PHP-8.5' into PHP-8.6
| From: | Jorg Sowa | Date: | Tue, 27 Oct 2026 21:34:35 +0000 |
| Subject: | [php-src] master: Merge branch 'PHP-8.5' into PHP-8.6 | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-142857@lists.php.net to get a copy of this message | ||
Author: Jorg Sowa (jorgsowa)
Date: 2026-10-27T22:33:05+01:00
Commit: https://github.com/php/php-src/commit/f852fb7bcd723ec70f66d7fbe1c435ae219244f2
Raw diff: https://github.com/php/php-src/commit/f852fb7bcd723ec70f66d7fbe1c435ae219244f2.diff
Merge branch 'PHP-8.5' into PHP-8.6
* PHP-8.5:
Fix JIT SWITCH_STRING type checks on referenced operand
Changed paths:
A ext/opcache/tests/jit/switch_002.phpt
A ext/opcache/tests/jit/switch_003.phpt
M NEWS
M ext/opcache/jit/zend_jit_ir.c
Diff:
diff --git a/NEWS b/NEWS
index ad5aee09c778..8eabb66296fa 100644
--- a/NEWS
+++ b/NEWS
@@ -70,6 +70,8 @@ PHP NEWS
. Fixed bug GH-24675 (function with >~1.7 MB of machine code corrupts JIT
buffer accounting). (ndossche)
. Call orig_post_shutdown_cb(). (ndossche)
+ . Fixed JIT segfault on switch over a string reference holding a
+ non-string value. (jorgsowa)
- OpenSSL:
. Fixed build with OpenSSL 4.1. (Weilin Du)
diff --git a/ext/opcache/jit/zend_jit_ir.c b/ext/opcache/jit/zend_jit_ir.c
index 3853b71aa6b4..106ca59f3d5d 100644
--- a/ext/opcache/jit/zend_jit_ir.c
+++ b/ext/opcache/jit/zend_jit_ir.c
@@ -16569,7 +16569,7 @@ static int zend_jit_switch(zend_jit_ctx *jit, const zend_op *opline, const
zend_
if (fallback_label) {
jit_guard_Z_TYPE(jit, op1_addr, IS_REFERENCE, fallback_label);
} else {
- ir_ref if_ref = jit_if_Z_TYPE(jit, op1_addr, IS_STRING);
+ ir_ref if_ref = jit_if_Z_TYPE(jit, op1_addr, IS_REFERENCE);
ir_IF_FALSE_cold(if_ref);
ir_refs_add(slow_inputs, ir_END());
ir_IF_TRUE(if_ref);
@@ -16579,7 +16579,7 @@ static int zend_jit_switch(zend_jit_ctx *jit, const zend_op *opline, const
zend_
op1_addr = ZEND_ADDR_REF_ZVAL(ref2);
if (fallback_label) {
- jit_guard_Z_TYPE(jit, op1_addr, IS_LONG, fallback_label);
+ jit_guard_Z_TYPE(jit, op1_addr, IS_STRING, fallback_label);
} else {
if_string = jit_if_Z_TYPE(jit, op1_addr, IS_STRING);
ir_IF_FALSE_cold(if_string);
diff --git a/ext/opcache/tests/jit/switch_002.phpt b/ext/opcache/tests/jit/switch_002.phpt
new file mode 100644
index 000000000000..580a1134c22e
--- /dev/null
+++ b/ext/opcache/tests/jit/switch_002.phpt
@@ -0,0 +1,27 @@
+--TEST--
+JIT SWITCH_STRING on a reference holding a non-string value
+--INI--
+opcache.enable=1
+opcache.enable_cli=1
+opcache.file_update_protection=0
+opcache.jit=tracing
+opcache.jit_hot_loop=1
+--EXTENSIONS--
+opcache
+--FILE--
+<?php
+function test($a) {
+ $n = 0;
+ foreach ($a as &$x) {
+ switch ($x) {
+ case "a": case "b": $n++; break;
+ }
+ }
+ return $n;
+}
+var_dump(test(["a"]));
+var_dump(test([1]));
+?>
+--EXPECT--
+int(1)
+int(0)
diff --git a/ext/opcache/tests/jit/switch_003.phpt b/ext/opcache/tests/jit/switch_003.phpt
new file mode 100644
index 000000000000..2a33f6dac457
--- /dev/null
+++ b/ext/opcache/tests/jit/switch_003.phpt
@@ -0,0 +1,26 @@
+--TEST--
+JIT SWITCH_STRING on a reference (function JIT)
+--INI--
+opcache.enable=1
+opcache.enable_cli=1
+opcache.file_update_protection=0
+opcache.jit=function
+--EXTENSIONS--
+opcache
+--FILE--
+<?php
+function test($a) {
+ $n = 0;
+ foreach ($a as &$x) {
+ switch ($x) {
+ case "a": case "b": $n++; break;
+ }
+ }
+ return $n;
+}
+var_dump(test(["a", "b", "c"]));
+var_dump(test([1]));
+?>
+--EXPECT--
+int(2)
+int(0)