Skip to content

Commit

Permalink
SCCP: Don't perform partial object propagation for typed props
Browse files Browse the repository at this point in the history
  • Loading branch information
nikic committed May 28, 2019
1 parent b2cb6a4 commit 6893f1f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
11 changes: 10 additions & 1 deletion ext/opcache/Optimizer/sccp.c
Expand Up @@ -1207,9 +1207,18 @@ static void sccp_visit_instr(scdf_ctx *scdf, zend_op *opline, zend_ssa_op *ssa_o
if (ssa_op->op1_def >= 0
&& ctx->scdf.ssa->vars[ssa_op->op1_def].escape_state == ESCAPE_STATE_NO_ESCAPE) {
zval *data = get_op1_value(ctx, opline+1, ssa_op+1);
zend_ssa_var_info *var_info = &ctx->scdf.ssa->var_info[ssa_op->op1_use];

/* Don't try to propagate assignments to (potentially) typed properties. We would
* need to deal with errors and type conversions first. */
if (!var_info->ce || (var_info->ce->ce_flags & ZEND_ACC_HAS_TYPE_HINTS)) {
SET_RESULT_BOT(result);
SET_RESULT_BOT(op1);
return;
}

/* If $a in $a->foo=$c is UNDEF, treat it like NULL. There is no warning. */
if ((ctx->scdf.ssa->var_info[ssa_op->op1_use].type & MAY_BE_ANY) == 0) {
if ((var_info->type & MAY_BE_ANY) == 0) {
op1 = &EG(uninitialized_zval);
}

Expand Down
25 changes: 25 additions & 0 deletions ext/opcache/tests/opt/sccp_028.phpt
@@ -0,0 +1,25 @@
--TEST--
SCCP 028: Don't propagate typed properties
--INI--
opcache.enable=1
opcache.enable_cli=1
opcache.optimization_level=-1
opcache.preload=
--SKIPIF--
<?php require_once('skipif.inc'); ?>
--FILE--
<?php

class Foo {
public int $bar = 1;
}
function test() {
$foo = new Foo();
$foo->bar = "10";
var_dump($foo->bar);
}
test();

?>
--EXPECT--
int(10)

0 comments on commit 6893f1f

Please sign in to comment.