Skip to content

Commit dd3e56b

Browse files
committed
Merge branch 'PHP-7.4' into PHP-8.0
* PHP-7.4: Fixed bug #81015
2 parents bf9dc53 + 178bbe3 commit dd3e56b

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ PHP NEWS
2222
- Opcache:
2323
. Fixed bug #81007 (JIT "not supported" on 32-bit x86 -- build problem?).
2424
(Nikita)
25+
. Fixed bug #81015 (Opcache optimization assumes wrong part of ternary
26+
operator in if-condition). (Nikita)
2527

2628
- PDO_pgsql:
2729
. Reverted bug fix for #80892 (PDO::PARAM_INT is treated the same as

ext/opcache/Optimizer/zend_ssa.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,14 @@ static void place_essa_pis(
285285
default:
286286
continue;
287287
}
288+
289+
/* The following patterns all inspect the opline directly before the JMPZ opcode.
290+
* Make sure that it is part of the same block, otherwise it might not be a dominating
291+
* assignment. */
292+
if (blocks[j].len == 1) {
293+
continue;
294+
}
295+
288296
if (opline->op1_type == IS_TMP_VAR &&
289297
((opline-1)->opcode == ZEND_IS_EQUAL ||
290298
(opline-1)->opcode == ZEND_IS_NOT_EQUAL ||

ext/opcache/tests/bug81015.phpt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
--TEST--
2+
Bug #81015: Opcache optimization assumes wrong part of ternary operator in if-condition
3+
--FILE--
4+
<?php
5+
6+
function ternary(bool $enabled, ?string $value): void
7+
{
8+
// the "true" part is not as trivial in the real case
9+
if ($enabled ? true : $value === null) {
10+
echo ($value ?? 'NULL') . "\n";
11+
} else {
12+
echo "INVALID\n";
13+
}
14+
}
15+
16+
ternary(true, 'value');
17+
ternary(true, null);
18+
ternary(false, 'value');
19+
ternary(false, null);
20+
21+
?>
22+
--EXPECT--
23+
value
24+
NULL
25+
INVALID
26+
NULL

0 commit comments

Comments
 (0)