Skip to content

Commit f19dd67

Browse files
committed
SCCP: Fix handling of ASSIGN_OBJ_REF
The generic BOT handling is not away of OP_DATA, so need to handle this opcode before we get to that.
1 parent 6738241 commit f19dd67

File tree

2 files changed

+38
-10
lines changed

2 files changed

+38
-10
lines changed

ext/opcache/Optimizer/sccp.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1440,6 +1440,17 @@ static void sccp_visit_instr(scdf_ctx *scdf, zend_op *opline, zend_ssa_op *ssa_o
14401440
SET_RESULT_BOT(result);
14411441
}
14421442
return;
1443+
case ZEND_ASSIGN_STATIC_PROP_REF:
1444+
case ZEND_ASSIGN_OBJ_REF:
1445+
/* Handled here because we also need to BOT the OP_DATA operand, while the generic
1446+
* code below will not do so. */
1447+
SET_RESULT_BOT(result);
1448+
SET_RESULT_BOT(op1);
1449+
SET_RESULT_BOT(op2);
1450+
opline++;
1451+
ssa_op++;
1452+
SET_RESULT_BOT(op1);
1453+
break;
14431454
}
14441455

14451456
if ((op1 && IS_BOT(op1)) || (op2 && IS_BOT(op2))) {
@@ -1915,16 +1926,6 @@ static void sccp_visit_instr(scdf_ctx *scdf, zend_op *opline, zend_ssa_op *ssa_o
19151926
SET_RESULT_BOT(result);
19161927
break;
19171928
}
1918-
case ZEND_ASSIGN_STATIC_PROP_REF:
1919-
case ZEND_ASSIGN_OBJ_REF:
1920-
SET_RESULT_BOT(result);
1921-
SET_RESULT_BOT(op1);
1922-
SET_RESULT_BOT(op2);
1923-
opline++;
1924-
ssa_op++;
1925-
op1 = get_op1_value(ctx, opline, ssa_op);
1926-
SET_RESULT_BOT(op1);
1927-
break;
19281929
default:
19291930
{
19301931
/* If we have no explicit implementation return BOT */

ext/opcache/tests/opt/sccp_029.phpt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
--TEST--
2+
SCCP 029: Don't propagate assignments to references to typed properties
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.optimization_level=-1
7+
opcache.preload=
8+
--SKIPIF--
9+
<?php require_once('skipif.inc'); ?>
10+
--FILE--
11+
<?php
12+
13+
class Test {
14+
public string $x = "x";
15+
}
16+
function test() {
17+
$test = new Test();
18+
$ref = "y";
19+
$test->x =& $ref;
20+
$ref = 42;
21+
var_dump($ref);
22+
}
23+
test();
24+
25+
?>
26+
--EXPECT--
27+
string(2) "42"

0 commit comments

Comments
 (0)