Skip to content

Commit fae6bed

Browse files
committed
Fix bug #69871 (short-circuiting failure with smart_branch)
1 parent 846d0e6 commit fae6bed

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

Zend/tests/bug69871.phpt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
--TEST--
2+
Bug #69871 (Short-circuiting failure with smart_branch)
3+
--FILE--
4+
<?php
5+
6+
$a = true;
7+
if (isset($a) && 0) {
8+
var_dump(true);
9+
} else {
10+
var_dump(false);
11+
}
12+
13+
?>
14+
--EXPECT--
15+
bool(false)

Zend/zend_execute.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2428,9 +2428,21 @@ static zend_always_inline zend_generator *zend_get_running_generator(zend_execut
24282428
# define ZEND_VM_SMART_BRANCH(_result, _check) do { \
24292429
int __result; \
24302430
if (EXPECTED((opline+1)->opcode == ZEND_JMPZ)) { \
2431-
__result = (_result); \
2431+
if (UNEXPECTED((opline+1)->op1_type == IS_CONST)) { \
2432+
zend_uchar __type = Z_TYPE_P(EX_CONSTANT((opline+1)->op1)); \
2433+
ZEND_ASSERT(__type == IS_TRUE || __type == IS_FALSE); /* assume boolean */ \
2434+
__result = __type == IS_TRUE; \
2435+
} else { \
2436+
__result = (_result); \
2437+
} \
24322438
} else if (EXPECTED((opline+1)->opcode == ZEND_JMPNZ)) { \
2433-
__result = !(_result); \
2439+
if (UNEXPECTED((opline+1)->op1_type == IS_CONST)) { \
2440+
zend_uchar __type = Z_TYPE_P(EX_CONSTANT((opline+1)->op1)); \
2441+
ZEND_ASSERT(__type == IS_TRUE || __type == IS_FALSE); /* assume boolean */ \
2442+
__result = __type != IS_TRUE; \
2443+
} else { \
2444+
__result = !(_result); \
2445+
} \
24342446
} else { \
24352447
break; \
24362448
} \

0 commit comments

Comments
 (0)