Skip to content

Commit f9639b5

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

2 files changed

Lines changed: 52 additions & 0 deletions

File tree

‎Zend/Optimizer/escape_analysis.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ static bool is_allocation_def(zend_op_array *op_array, zend_ssa *ssa, int def, i
173173
&& !ce->destructor
174174
&& !ce->__get
175175
&& !ce->__set
176+
&& !ce->__isset
176177
&& !(ce->ce_flags & forbidden_flags)
177178
&& (ce->ce_flags & ZEND_ACC_CONSTANTS_UPDATED)) {
178179
return 1;
@@ -242,6 +243,7 @@ static bool is_local_def(zend_op_array *op_array, zend_ssa *ssa, int def, int va
242243
&& !ce->destructor
243244
&& !ce->__get
244245
&& !ce->__set
246+
&& !ce->__isset
245247
&& !ce->parent) {
246248
return 1;
247249
}

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

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
--TEST--
2+
DCE must not remove assignments to properties of an object escaping through __isset
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 C {
14+
public $x = 0;
15+
function __isset($n) {
16+
global $g;
17+
$g = $this;
18+
return true;
19+
}
20+
}
21+
22+
function f() {
23+
$o = new C;
24+
isset($o->foo);
25+
$o->x = 42;
26+
}
27+
28+
f();
29+
var_dump($g->x);
30+
31+
#[AllowDynamicProperties]
32+
class F {
33+
function __isset($n) {
34+
$this->x = 2;
35+
return true;
36+
}
37+
}
38+
39+
function i() {
40+
$o = new F;
41+
$o->x = 1;
42+
isset($o->foo);
43+
var_dump($o->x);
44+
}
45+
i();
46+
47+
?>
48+
--EXPECT--
49+
int(42)
50+
int(2)

0 commit comments

Comments
 (0)