Skip to content

Commit

Permalink
Merge branch 'PHP-8.0'
Browse files Browse the repository at this point in the history
* PHP-8.0:
  Fixed bug #81015
  • Loading branch information
nikic committed May 6, 2021
2 parents 779fe8e + dd3e56b commit 13467bd
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Zend/Optimizer/zend_ssa.c
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,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 ||
Expand Down
26 changes: 26 additions & 0 deletions ext/opcache/tests/bug81015.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
--TEST--
Bug #81015: Opcache optimization assumes wrong part of ternary operator in if-condition
--FILE--
<?php

function ternary(bool $enabled, ?string $value): void
{
// the "true" part is not as trivial in the real case
if ($enabled ? true : $value === null) {
echo ($value ?? 'NULL') . "\n";
} else {
echo "INVALID\n";
}
}

ternary(true, 'value');
ternary(true, null);
ternary(false, 'value');
ternary(false, null);

?>
--EXPECT--
value
NULL
INVALID
NULL

0 comments on commit 13467bd

Please sign in to comment.