summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikita Popov <nikita.ppv@gmail.com>2017-07-21 23:13:44 +0200
committerNikita Popov <nikita.ppv@gmail.com>2017-07-21 23:20:56 +0200
commit69ec51eb0221c76802a5a23e1c86cad1483faed2 (patch)
treee0cf0edac3b532d76916ff49440e55884aaae817
parenta8f98fc7f7c795eb6585e71160655a3cc06a9300 (diff)
downloadphp-git-69ec51eb0221c76802a5a23e1c86cad1483faed2.tar.gz
Fix DFG construction for VERIFY_RETURN
`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.
-rw-r--r--ext/opcache/Optimizer/zend_dfg.c6
-rw-r--r--ext/opcache/tests/verify_return_dfg.phpt16
2 files changed, 19 insertions, 3 deletions
diff --git a/ext/opcache/Optimizer/zend_dfg.c b/ext/opcache/Optimizer/zend_dfg.c
index 374c8146c8..f39c6368cd 100644
--- a/ext/opcache/Optimizer/zend_dfg.c
+++ b/ext/opcache/Optimizer/zend_dfg.c
@@ -144,11 +144,11 @@ op1_use:
}
} 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)) {
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) {
diff --git a/ext/opcache/tests/verify_return_dfg.phpt b/ext/opcache/tests/verify_return_dfg.phpt
new file mode 100644
index 0000000000..f2e66511ed
--- /dev/null
+++ b/ext/opcache/tests/verify_return_dfg.phpt
@@ -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===