Skip to content

Commit 7b629af

Browse files
committed
Fixed incorrect DCE of a constructor call
Fixez oss-fuzz #42049
1 parent c29f6ba commit 7b629af

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

ext/opcache/Optimizer/dce.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,10 @@ int dce_optimize_op_array(zend_op_array *op_array, zend_ssa *ssa, zend_bool reor
592592
while ((i = zend_bitset_pop_first(ctx.instr_worklist, ctx.instr_worklist_len)) >= 0) {
593593
zend_bitset_excl(ctx.instr_dead, i);
594594
add_operands_to_worklists(&ctx, &op_array->opcodes[i], &ssa->ops[i], ssa, 1);
595-
if (i < op_array->last && op_array->opcodes[i+1].opcode == ZEND_OP_DATA) {
595+
if (i < op_array->last
596+
&& (op_array->opcodes[i+1].opcode == ZEND_OP_DATA
597+
|| (op_array->opcodes[i].opcode == ZEND_NEW
598+
&& op_array->opcodes[i+1].opcode == ZEND_DO_FCALL))) {
596599
zend_bitset_excl(ctx.instr_dead, i+1);
597600
add_operands_to_worklists(&ctx, &op_array->opcodes[i+1], &ssa->ops[i+1], ssa, 1);
598601
}

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)