Skip to content

Commit

Permalink
Fix DFG construction for VERIFY_RETURN
Browse files Browse the repository at this point in the history
`use` only contains uses prior to definition. This was not
honoured for VERIFY_RETURN with a temporary operand.

The test case only breaks on PHP 7.2.
  • Loading branch information
nikic committed Jul 21, 2017
1 parent a8f98fc commit 69ec51e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
6 changes: 3 additions & 3 deletions ext/opcache/Optimizer/zend_dfg.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,11 @@ int zend_build_dfg(const zend_op_array *op_array, const zend_cfg *cfg, zend_dfg
}
} else if (opline->op1_type & (IS_VAR|IS_TMP_VAR)) {
var_num = EX_VAR_TO_NUM(opline->op1.var);
if (opline->opcode == ZEND_VERIFY_RETURN_TYPE) {
if (!DFG_ISSET(def, set_size, j, var_num)) {

This comment has been minimized.

Copy link
@chx

chx Jul 21, 2017

Would if (!DFG_ISSET(def, set_size, j, var_num) || opline->opcode == ZEND_VERIFY_RETURN_TYPE)? perhaps be better so only one DFG_SET(use, set_size, j, var_num); is needed?

This comment has been minimized.

Copy link
@nikic

nikic Jul 21, 2017

Author Member

The code in both branches is different. One sets use, the other sets def.

This comment has been minimized.

Copy link
@chx

chx Jul 21, 2017

Oh sorry, nevermind! I am blind.

DFG_SET(use, set_size, j, var_num);
}
if (opline->opcode == ZEND_VERIFY_RETURN_TYPE) {
DFG_SET(def, set_size, j, var_num);
} else if (!DFG_ISSET(def, set_size, j, var_num)) {
DFG_SET(use, set_size, j, var_num);
}
}
if (opline->op2_type == IS_CV) {
Expand Down
16 changes: 16 additions & 0 deletions ext/opcache/tests/verify_return_dfg.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
--TEST--
Incorrect liveness computation for verify-return
--FILE--
<?php
function test($foo): string
{
switch ($foo) {
default: $bar = 'x'; break;
case 'z': $bar = 'y'; break;
}
return (string)$bar;
}
?>
===DONE===
--EXPECT--
===DONE===

0 comments on commit 69ec51e

Please sign in to comment.