Skip to content

Commit 0015fc9

Browse files
committed
Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0: Fix relative offsets when copying JMPZNZ
2 parents 35ff71f + 7d48341 commit 0015fc9

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

Zend/Optimizer/pass3.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ void zend_optimizer_pass3(zend_op_array *op_array, zend_optimizer_ctx *ctx)
9494
ZVAL_COPY(&zv, &ZEND_OP1_LITERAL(opline));
9595
opline->op1.constant = zend_optimizer_add_literal(op_array, &zv);
9696
}
97+
/* Jump addresses may be encoded as offsets, recompute them. */
98+
ZEND_SET_OP_JMP_ADDR(opline, opline->op2, ZEND_OP2_JMP_ADDR(target));
99+
opline->extended_value = ZEND_OPLINE_TO_OFFSET(opline,
100+
ZEND_OFFSET_TO_OPLINE(target, target->extended_value));
97101
goto optimize_jmpznz;
98102
} else if ((target->opcode == ZEND_RETURN ||
99103
target->opcode == ZEND_RETURN_BY_REF ||
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--TEST--
2+
Check for correct treatment of relative JMPZNZ offsets when copying opline
3+
--FILE--
4+
<?php
5+
function test($c) {
6+
L1:
7+
if ($c) {
8+
goto L1;
9+
goto L1;
10+
}
11+
}
12+
test(false);
13+
?>
14+
===DONE===
15+
--EXPECT--
16+
===DONE===

0 commit comments

Comments
 (0)