diff --git a/NEWS b/NEWS index 1e88f9171ac73..d99b213b96beb 100644 --- a/NEWS +++ b/NEWS @@ -12,6 +12,7 @@ PHP NEWS iterator properties table). (ilutov) . Fixed unstable get_iterator pointer for hooked classes in shm on Windows. (ilutov) + . Fixed bug GH-17106 (ZEND_MATCH_ERROR misoptimization). (ilutov) - DBA: . Skip test if inifile is disabled. (orlitzky) diff --git a/Zend/Optimizer/zend_optimizer.c b/Zend/Optimizer/zend_optimizer.c index 823277694b4ff..9f2e3115d3666 100644 --- a/Zend/Optimizer/zend_optimizer.c +++ b/Zend/Optimizer/zend_optimizer.c @@ -640,6 +640,7 @@ bool zend_optimizer_replace_by_const(zend_op_array *op_array, case ZEND_SWITCH_LONG: case ZEND_SWITCH_STRING: case ZEND_MATCH: + case ZEND_MATCH_ERROR: case ZEND_JMP_NULL: { zend_op *end = op_array->opcodes + op_array->last; while (opline < end) { @@ -652,6 +653,7 @@ bool zend_optimizer_replace_by_const(zend_op_array *op_array, && opline->opcode != ZEND_SWITCH_LONG && opline->opcode != ZEND_SWITCH_STRING && opline->opcode != ZEND_MATCH + && opline->opcode != ZEND_MATCH_ERROR && opline->opcode != ZEND_JMP_NULL && (opline->opcode != ZEND_FREE || opline->extended_value != ZEND_FREE_ON_RETURN); diff --git a/Zend/zend_opcode.c b/Zend/zend_opcode.c index 0d1d8b6bf528f..12c2759656b2d 100644 --- a/Zend/zend_opcode.c +++ b/Zend/zend_opcode.c @@ -895,6 +895,7 @@ static bool keeps_op1_alive(zend_op *opline) { || opline->opcode == ZEND_SWITCH_LONG || opline->opcode == ZEND_SWITCH_STRING || opline->opcode == ZEND_MATCH + || opline->opcode == ZEND_MATCH_ERROR || opline->opcode == ZEND_FETCH_LIST_R || opline->opcode == ZEND_FETCH_LIST_W || opline->opcode == ZEND_COPY_TMP) { diff --git a/ext/opcache/tests/gh17106.phpt b/ext/opcache/tests/gh17106.phpt new file mode 100644 index 0000000000000..5b56131b5a29f --- /dev/null +++ b/ext/opcache/tests/gh17106.phpt @@ -0,0 +1,21 @@ +--TEST-- +GH-17106: ZEND_MATCH_ERROR misoptimization +--EXTENSIONS-- +opcache +--INI-- +opcache.enable_cli=1 +opcache.optimization_level=-1 +--FILE-- + 2 }); +var_dump(match (X) { 2 => 2 }); + +?> +--EXPECT-- +int(7) +int(2) +int(2)