Skip to content

Commit 572c09d

Browse files
committed
Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0: Fixed incorrect DCE of a constructor call
2 parents b4ccc52 + 7b629af commit 572c09d

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

Zend/Optimizer/dce.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,10 @@ int dce_optimize_op_array(zend_op_array *op_array, zend_ssa *ssa, bool reorder_d
620620
while ((i = zend_bitset_pop_first(ctx.instr_worklist, ctx.instr_worklist_len)) >= 0) {
621621
zend_bitset_excl(ctx.instr_dead, i);
622622
add_operands_to_worklists(&ctx, &op_array->opcodes[i], &ssa->ops[i], ssa, 1);
623-
if (i < op_array->last && op_array->opcodes[i+1].opcode == ZEND_OP_DATA) {
623+
if (i < op_array->last
624+
&& (op_array->opcodes[i+1].opcode == ZEND_OP_DATA
625+
|| (op_array->opcodes[i].opcode == ZEND_NEW
626+
&& op_array->opcodes[i+1].opcode == ZEND_DO_FCALL))) {
624627
zend_bitset_excl(ctx.instr_dead, i+1);
625628
add_operands_to_worklists(&ctx, &op_array->opcodes[i+1], &ssa->ops[i+1], ssa, 1);
626629
}

ext/opcache/tests/opt/dce_012.phpt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
--TEST--
2+
Incorrect DCE of constructor DO_FCALL
3+
--FILE--
4+
<?php
5+
function test() {
6+
$a = null;
7+
for ($i = 0; $i < 10; $i++) {
8+
$obj = $a = $a;
9+
$obj = new stdClass;
10+
$obj->orop1 = 'abc';
11+
}
12+
13+
foreach (range(0, 6) as $levels) {
14+
print "$levels level" . ($levels == C ? "" : "s") . "aaa";
15+
}
16+
17+
$obj->prop1 = null;
18+
}
19+
test();
20+
?>
21+
--EXPECTF--
22+
Fatal error: Uncaught Error: Undefined constant "C" in %sdce_012.php:11
23+
Stack trace:
24+
#0 %sdce_012.php(16): test()
25+
#1 {main}
26+
thrown in %sdce_012.php on line 11

0 commit comments

Comments
 (0)