Skip to content

Commit dfe9c2a

Browse files
nielsdosdevnexen
authored andcommitted
Fix incorrect comparison in block optimization pass
We're in the case of ZEND_JMPZ_EX or ZEND_JMPNZ_EX. The opcode gets overwritten and only after the overwriting gets checked if we're in a JMPZ or JMPNZ case. This results in a wrong optimization. Close GH-10329
1 parent 42eed7b commit dfe9c2a

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

NEWS

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ PHP NEWS
99
. Fixed bug GH-10072 (PHP crashes when execute_ex is overridden and a __call
1010
trampoline is used from internal code). (Derick)
1111
. Fix GH-10251 (Assertion `(flag & (1<<3)) == 0' failed). (nielsdos)
12+
. Fix wrong comparison in block optimisation pass after opcode update. (nieldsdos)
1213

1314
- Date:
1415
. Fixed bug GH-9891 (DateTime modify with unixtimestamp (@) must work like

Zend/Optimizer/block_pass.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -671,13 +671,13 @@ static void zend_optimize_block(zend_basic_block *block, zend_op_array *op_array
671671
case ZEND_JMPNZ_EX:
672672
while (1) {
673673
if (opline->op1_type == IS_CONST) {
674-
if (zend_is_true(&ZEND_OP1_LITERAL(opline)) ==
675-
(opline->opcode == ZEND_JMPZ_EX)) {
674+
bool is_jmpz_ex = opline->opcode == ZEND_JMPZ_EX;
675+
if (zend_is_true(&ZEND_OP1_LITERAL(opline)) == is_jmpz_ex) {
676676

677677
++(*opt_count);
678678
opline->opcode = ZEND_QM_ASSIGN;
679679
zval_ptr_dtor_nogc(&ZEND_OP1_LITERAL(opline));
680-
ZVAL_BOOL(&ZEND_OP1_LITERAL(opline), opline->opcode == ZEND_JMPZ_EX);
680+
ZVAL_BOOL(&ZEND_OP1_LITERAL(opline), is_jmpz_ex);
681681
opline->op2.num = 0;
682682
block->successors_count = 1;
683683
block->successors[0] = block->successors[1];

0 commit comments

Comments
 (0)