Skip to content

Commit 9854f20

Browse files
committed
Fix missing reference unwrap for FE_FETCH_R in JIT
Fixes GH-21264
1 parent da6d890 commit 9854f20

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

ext/opcache/jit/zend_jit_ir.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14105,6 +14105,13 @@ static int zend_jit_fe_fetch(zend_jit_ctx *jit, const zend_op *opline, uint32_t
1410514105
return 0;
1410614106
}
1410714107
} else {
14108+
// JIT: ZVAL_DEREF(value);
14109+
if (val_info & MAY_BE_REF) {
14110+
ir_ref ref = jit_ZVAL_ADDR(jit, val_addr);
14111+
ref = jit_ZVAL_DEREF_ref(jit, ref);
14112+
val_addr = ZEND_ADDR_REF_ZVAL(ref);
14113+
val_info &= ~MAY_BE_REF;
14114+
}
1410814115
// JIT: ZVAL_COPY(res, value);
1410914116
jit_ZVAL_COPY(jit, var_addr, -1, val_addr, val_info, true);
1411014117
}

ext/opcache/tests/jit/gh21264.phpt

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
--TEST--
2+
GH-21264: Missing reference unwrap for FE_FETCH_R in JIT
3+
--EXTENSIONS--
4+
opcache
5+
--INI--
6+
opcache.enable=1
7+
opcache.enable_cli=1
8+
opcache.jit=function
9+
--FILE--
10+
<?php
11+
12+
class C {
13+
public array $array;
14+
15+
public static function identity($x) {
16+
return $x;
17+
}
18+
19+
public function test() {
20+
return array_map(self::identity(...), $this->array);
21+
}
22+
}
23+
24+
function test() {
25+
$c = new C;
26+
$element = 'qux';
27+
$c->array = [&$element, &$element];
28+
var_dump($c->test());
29+
}
30+
31+
test();
32+
test();
33+
34+
?>
35+
--EXPECT--
36+
array(2) {
37+
[0]=>
38+
string(3) "qux"
39+
[1]=>
40+
string(3) "qux"
41+
}
42+
array(2) {
43+
[0]=>
44+
string(3) "qux"
45+
[1]=>
46+
string(3) "qux"
47+
}

0 commit comments

Comments
 (0)