Skip to content

Commit d561a99

Browse files
nikiccmb69
authored andcommitted
Fixed bug #78341
The smart branch logic assumed b->start refers to the old offsets, while b->start was already adjusted to the new offsets at this point. Delay the change until later. (cherry picked from commit 8e63bb5)
1 parent 63f1def commit d561a99

File tree

3 files changed

+31
-7
lines changed

3 files changed

+31
-7
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? ??? ????, PHP 7.3.8
44

5+
- OPcache:
6+
. Fixed bug #78341 (Failure to detect smart branch in DFA pass). (Nikita)
7+
58
- Phpdbg:
69
. Fixed bug #78297 (Include unexistent file memory leak). (Nikita)
710

ext/opcache/Optimizer/dfa_pass.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,8 @@ static void zend_ssa_remove_nops(zend_op_array *op_array, zend_ssa *ssa, zend_op
181181

182182
for (b = blocks; b < blocks_end; b++) {
183183
if (b->flags & (ZEND_BB_REACHABLE|ZEND_BB_UNREACHABLE_FREE)) {
184-
uint32_t end;
185-
186184
if (b->len) {
185+
uint32_t new_start, old_end;
187186
while (i < b->start) {
188187
shiftlist[i] = i - target;
189188
i++;
@@ -196,9 +195,9 @@ static void zend_ssa_remove_nops(zend_op_array *op_array, zend_ssa *ssa, zend_op
196195
b->len = 1;
197196
}
198197

199-
end = b->start + b->len;
200-
b->start = target;
201-
while (i < end) {
198+
new_start = target;
199+
old_end = b->start + b->len;
200+
while (i < old_end) {
202201
shiftlist[i] = i - target;
203202
if (EXPECTED(op_array->opcodes[i].opcode != ZEND_NOP) ||
204203
is_smart_branch_inhibiting_nop(op_array, target, i, b, blocks_end)) {
@@ -211,12 +210,13 @@ static void zend_ssa_remove_nops(zend_op_array *op_array, zend_ssa *ssa, zend_op
211210
}
212211
i++;
213212
}
214-
if (target != end) {
213+
b->start = new_start;
214+
if (target != old_end) {
215215
zend_op *opline;
216216
zend_op *new_opline;
217217

218218
b->len = target - b->start;
219-
opline = op_array->opcodes + end - 1;
219+
opline = op_array->opcodes + old_end - 1;
220220
if (opline->opcode == ZEND_NOP) {
221221
continue;
222222
}

ext/opcache/tests/bug78341.phpt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
Bug #78341: Failure to detect smart branch in DFA pass
3+
--FILE--
4+
<?php
5+
6+
function test($a) {
7+
// Just some dead code...
8+
if (strpos("foo", "foo") !== 0) {
9+
echo "Foo";
10+
}
11+
12+
$x = $a === null;
13+
if ($x) {
14+
var_dump($x);
15+
}
16+
}
17+
test(null);
18+
19+
?>
20+
--EXPECT--
21+
bool(true)

0 commit comments

Comments
 (0)