Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f681f90

Browse files
committedOct 6, 2021
JIT: Fixed register clobbering
1 parent 69fb20f commit f681f90

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed
 

‎ext/opcache/jit/zend_jit_x86.dasc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5924,6 +5924,9 @@ static int zend_jit_simple_assign(dasm_State **Dst,
59245924
|.cold_code
59255925
|1:
59265926
}
5927+
if (Z_REG(val_addr) == ZREG_R2) {
5928+
| mov aword T1, r2 // save
5929+
}
59275930
| // zend_refcounted *ref = Z_COUNTED_P(retval_ptr);
59285931
| GET_ZVAL_PTR r2, val_addr
59295932
| GC_DELREF r2
@@ -5948,6 +5951,9 @@ static int zend_jit_simple_assign(dasm_State **Dst,
59485951
| GC_ADDREF Ra(tmp_reg)
59495952
|2:
59505953
}
5954+
if (Z_REG(val_addr) == ZREG_R2) {
5955+
| mov r2, aword T1 // restore
5956+
}
59515957
if (save_r1) {
59525958
| mov aword T1, FCARG1a // save
59535959
}

‎ext/opcache/tests/jit/assign_042.phpt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
--TEST--
2+
JIT ASSIGN: Assign to of reference with 1 refcount
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.file_update_protection=0
7+
opcache.jit_buffer_size=1M
8+
opcache.protect_memory=1
9+
--FILE--
10+
<?php
11+
class Test {
12+
public $prop;
13+
function __construct() {
14+
$this->prop = $this->retref();
15+
}
16+
function &retref() {
17+
return str_repeat("a", 5);
18+
}
19+
}
20+
$o = new Test();
21+
var_dump($o);
22+
?>
23+
--EXPECTF--
24+
Notice: Only variable references should be returned by reference in %sassign_042.php on line 8
25+
object(Test)#1 (1) {
26+
["prop"]=>
27+
string(5) "aaaaa"
28+
}

0 commit comments

Comments
 (0)
Please sign in to comment.