diff --git a/NEWS b/NEWS index 9d7f31b5c1d..1d5c2c654bb 100644 --- a/NEWS +++ b/NEWS @@ -22,6 +22,8 @@ PHP NEWS - Opcache: . Fixed bug #81007 (JIT "not supported" on 32-bit x86 -- build problem?). (Nikita) + . Fixed bug #81015 (Opcache optimization assumes wrong part of ternary + operator in if-condition). (Nikita) - PDO_pgsql: . Reverted bug fix for #80892 (PDO::PARAM_INT is treated the same as diff --git a/ext/opcache/Optimizer/zend_ssa.c b/ext/opcache/Optimizer/zend_ssa.c index 3a6a098196f..d34ba6fc09b 100644 --- a/ext/opcache/Optimizer/zend_ssa.c +++ b/ext/opcache/Optimizer/zend_ssa.c @@ -285,6 +285,14 @@ static void place_essa_pis( default: continue; } + + /* The following patterns all inspect the opline directly before the JMPZ opcode. + * Make sure that it is part of the same block, otherwise it might not be a dominating + * assignment. */ + if (blocks[j].len == 1) { + continue; + } + if (opline->op1_type == IS_TMP_VAR && ((opline-1)->opcode == ZEND_IS_EQUAL || (opline-1)->opcode == ZEND_IS_NOT_EQUAL || diff --git a/ext/opcache/tests/bug81015.phpt b/ext/opcache/tests/bug81015.phpt new file mode 100644 index 00000000000..b5009e6a236 --- /dev/null +++ b/ext/opcache/tests/bug81015.phpt @@ -0,0 +1,26 @@ +--TEST-- +Bug #81015: Opcache optimization assumes wrong part of ternary operator in if-condition +--FILE-- + +--EXPECT-- +value +NULL +INVALID +NULL