Skip to content

Commit e857936

Browse files
committed
Fixed bug #80805
Handle missing result_var in binary_op_result_type. (cherry picked from commit 8446e28)
1 parent 988c3f9 commit e857936

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ PHP NEWS
1515
. Fixed bug #80713 (SegFault when disabling ATTR_EMULATE_PREPARES and
1616
MySQL 8.0). (Nikita)
1717

18+
- opcache:
19+
. Fixed bug #80805 (create simple class and get error in opcache.so). (Nikita)
20+
1821
- phpdbg:
1922
. Fixed bug #80757 (Exit code is 0 when could not open file). (Felipe)
2023

ext/opcache/Optimizer/zend_inference.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2141,7 +2141,7 @@ static uint32_t assign_dim_result_type(
21412141

21422142
/* For binary ops that have compound assignment operators */
21432143
static uint32_t binary_op_result_type(
2144-
zend_ssa *ssa, zend_uchar opcode, uint32_t t1, uint32_t t2, uint32_t result_var,
2144+
zend_ssa *ssa, zend_uchar opcode, uint32_t t1, uint32_t t2, int result_var,
21452145
zend_long optimization_level) {
21462146
uint32_t tmp = 0;
21472147
uint32_t t1_type = (t1 & MAY_BE_ANY) | (t1 & MAY_BE_UNDEF ? MAY_BE_NULL : 0);
@@ -2159,7 +2159,8 @@ static uint32_t binary_op_result_type(
21592159
switch (opcode) {
21602160
case ZEND_ADD:
21612161
if (t1_type == MAY_BE_LONG && t2_type == MAY_BE_LONG) {
2162-
if (!ssa->var_info[result_var].has_range ||
2162+
if (result_var < 0 ||
2163+
!ssa->var_info[result_var].has_range ||
21632164
ssa->var_info[result_var].range.underflow ||
21642165
ssa->var_info[result_var].range.overflow) {
21652166
/* may overflow */
@@ -2185,7 +2186,8 @@ static uint32_t binary_op_result_type(
21852186
case ZEND_SUB:
21862187
case ZEND_MUL:
21872188
if (t1_type == MAY_BE_LONG && t2_type == MAY_BE_LONG) {
2188-
if (!ssa->var_info[result_var].has_range ||
2189+
if (result_var < 0 ||
2190+
!ssa->var_info[result_var].has_range ||
21892191
ssa->var_info[result_var].range.underflow ||
21902192
ssa->var_info[result_var].range.overflow) {
21912193
/* may overflow */
@@ -2627,7 +2629,8 @@ static int zend_update_type_info(const zend_op_array *op_array,
26272629
}
26282630

26292631
tmp |= binary_op_result_type(
2630-
ssa, opline->extended_value, t1, t2, ssa_ops[i].op1_def, optimization_level);
2632+
ssa, opline->extended_value, t1, t2,
2633+
opline->opcode == ZEND_ASSIGN_OP ? ssa_ops[i].op1_def : -1, optimization_level);
26312634
if (tmp & (MAY_BE_STRING|MAY_BE_ARRAY)) {
26322635
tmp |= MAY_BE_RC1;
26332636
}

ext/opcache/tests/bug80805.phpt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
--TEST--
2+
Bug #80805: create simple class and get error in opcache.so
3+
--FILE--
4+
<?php
5+
6+
class Test {
7+
public int $foo;
8+
public function __construct()
9+
{
10+
$this->foo = 2;
11+
}
12+
public function inc(): int
13+
{
14+
return $this->foo += 2;
15+
}
16+
}
17+
18+
$test = new Test();
19+
var_dump($test->foo);
20+
$test->inc();
21+
var_dump($test->foo);
22+
23+
?>
24+
--EXPECT--
25+
int(2)
26+
int(4)

0 commit comments

Comments
 (0)