Skip to content

Commit 4bf483f

Browse files
ndosschearnaud-lb
andcommitted
Fix property hook escape analysis causing misoptimization
Co-authored-by: Arnaud Le Blanc <365207+arnaud-lb@users.noreply.github.com>
1 parent f9639b5 commit 4bf483f

2 files changed

Lines changed: 57 additions & 0 deletions

File tree

‎Zend/Optimizer/escape_analysis.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ static bool is_allocation_def(zend_op_array *op_array, zend_ssa *ssa, int def, i
174174
&& !ce->__get
175175
&& !ce->__set
176176
&& !ce->__isset
177+
&& !ce->num_hooked_props
177178
&& !(ce->ce_flags & forbidden_flags)
178179
&& (ce->ce_flags & ZEND_ACC_CONSTANTS_UPDATED)) {
179180
return 1;
@@ -244,6 +245,7 @@ static bool is_local_def(zend_op_array *op_array, zend_ssa *ssa, int def, int va
244245
&& !ce->__get
245246
&& !ce->__set
246247
&& !ce->__isset
248+
&& !ce->num_hooked_props
247249
&& !ce->parent) {
248250
return 1;
249251
}

‎ext/opcache/tests/opt/dce_017.phpt‎

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
--TEST--
2+
DCE must not remove assignments to properties of an object escaping through a property hook
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.optimization_level=-1
7+
opcache.file_update_protection=0
8+
--EXTENSIONS--
9+
opcache
10+
--FILE--
11+
<?php
12+
13+
class D {
14+
public $x = 0;
15+
public $h {
16+
get {
17+
global $g;
18+
$g = $this;
19+
return 1;
20+
}
21+
}
22+
}
23+
24+
function g() {
25+
$o = new D;
26+
$o->h;
27+
$o->x = 42;
28+
}
29+
30+
g();
31+
var_dump($g->x);
32+
33+
class E {
34+
public $x = 0;
35+
public $h {
36+
set {
37+
global $g;
38+
$g = $this;
39+
}
40+
}
41+
}
42+
43+
function h() {
44+
$o = new E;
45+
$o->h = 1;
46+
$o->x = 42;
47+
}
48+
49+
h();
50+
var_dump($g->x);
51+
52+
?>
53+
--EXPECT--
54+
int(42)
55+
int(42)

0 commit comments

Comments
 (0)