Skip to content

Commit db0e365

Browse files
authored
Fix missing reference unwrap for FE_FETCH_R in JIT (GH-21265)
Fixes GH-21264
1 parent 3bf7d9a commit db0e365

File tree

3 files changed

+85
-0
lines changed

3 files changed

+85
-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
}
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+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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=tracing
9+
--FILE--
10+
<?php
11+
12+
class C {
13+
public $prop = 0;
14+
}
15+
16+
function test($array) {
17+
$c = new C;
18+
foreach ($array as $c->prop) {
19+
$c->prop++;
20+
}
21+
}
22+
23+
$element = 0;
24+
$array = [&$element, &$element];
25+
test($array);
26+
test($array);
27+
var_dump($element);
28+
29+
?>
30+
--EXPECT--
31+
int(0)

0 commit comments

Comments
 (0)