Skip to content

Commit 637d257

Browse files
committed
Fix RCn inference for [QM_]ASSIGN
If we infer the rhs of an assignment as RC1, the type of a CV should still be RCn. Otherwise, every use of the variable would constitute a definition from RC1 to RCn, which is likely not desirable.
1 parent fbd3a24 commit 637d257

File tree

4 files changed

+47
-2
lines changed

4 files changed

+47
-2
lines changed

Zend/Optimizer/zend_inference.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2704,7 +2704,7 @@ static zend_always_inline zend_result _zend_update_type_info(
27042704
}
27052705
if (t1 & (MAY_BE_RC1|MAY_BE_RCN)) {
27062706
tmp |= (t1 & (MAY_BE_RC1|MAY_BE_RCN));
2707-
if (opline->opcode == ZEND_COPY_TMP || opline->op1_type == IS_CV) {
2707+
if (opline->opcode == ZEND_COPY_TMP || opline->op1_type == IS_CV || opline->result_type == IS_CV) {
27082708
tmp |= MAY_BE_RCN;
27092709
}
27102710
}
@@ -3073,7 +3073,7 @@ static zend_always_inline zend_result _zend_update_type_info(
30733073
if (t1 & MAY_BE_REF) {
30743074
tmp |= MAY_BE_REF;
30753075
}
3076-
if (t2 & MAY_BE_REF) {
3076+
if (opline->op1_type == IS_CV || (t2 & MAY_BE_REF)) {
30773077
tmp |= MAY_BE_RC1 | MAY_BE_RCN;
30783078
} else if (opline->op2_type & (IS_TMP_VAR|IS_VAR)) {
30793079
tmp |= t2 & (MAY_BE_RC1|MAY_BE_RCN);
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
Type inference verification 001
3+
--FILE--
4+
<?php
5+
function escape($val) {
6+
global $g;
7+
$g = $val;
8+
}
9+
function test() {
10+
$val = date_create();
11+
escape($val);
12+
spl_object_id($val);
13+
}
14+
test();
15+
?>
16+
===DONE===
17+
--EXPECT--
18+
===DONE===
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
Type inference verification 002
3+
--FILE--
4+
<?php
5+
function test() {
6+
$val = date_create();
7+
$alias = $val;
8+
spl_object_id($val);
9+
}
10+
test();
11+
?>
12+
===DONE===
13+
--EXPECT--
14+
===DONE===
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
--TEST--
2+
Type inference verification 003
3+
--FILE--
4+
<?php
5+
function test() {
6+
$val = date_create();
7+
[$val, spl_object_id($val)];
8+
}
9+
test();
10+
?>
11+
===DONE===
12+
--EXPECT--
13+
===DONE===

0 commit comments

Comments
 (0)