]> granicus.if.org Git - php/commitdiff
Fixed edge cases introduced by 170ed1f5a7b2f2f052445761080c96a3a3cfa884
authorDmitry Stogov <dmitry@zend.com>
Thu, 10 Oct 2019 08:48:31 +0000 (11:48 +0300)
committerDmitry Stogov <dmitry@zend.com>
Thu, 10 Oct 2019 08:48:31 +0000 (11:48 +0300)
ext/opcache/Optimizer/block_pass.c
ext/opcache/tests/opt/block_pass_001.phpt [new file with mode: 0644]
ext/opcache/tests/opt/block_pass_002.phpt [new file with mode: 0644]

index 46ec6c0769d82a0d8b39850d0340d807e85b0bc2..983d5cf1a9c581a5a8089d7a053ed65740f8be4d 100644 (file)
@@ -892,7 +892,12 @@ optimize_const_unary_op:
                                           !zend_bitset_in(used_ext, VAR_NUM(opline->op1.var))) {
                                        /* T1 = ..., T2 = QM_ASSIGN(T1) to T2 = ..., NOP */
                                        src = VAR_SOURCE(opline->op1);
-                                       if (src) {
+                                       if (src &&
+                                               src->opcode != ZEND_COPY_TMP &&
+                                               src->opcode != ZEND_ADD_ARRAY_ELEMENT &&
+                                               src->opcode != ZEND_ADD_ARRAY_UNPACK &&
+                                               (src->opcode != ZEND_DECLARE_LAMBDA_FUNCTION ||
+                                                src == opline -1)) {
                                                src->result.var = opline->result.var;
                                                VAR_SOURCE(opline->op1) = NULL;
                                                VAR_SOURCE(opline->result) = src;
diff --git a/ext/opcache/tests/opt/block_pass_001.phpt b/ext/opcache/tests/opt/block_pass_001.phpt
new file mode 100644 (file)
index 0000000..788994e
--- /dev/null
@@ -0,0 +1,24 @@
+--TEST--
+Block Pass 001: QM_ASSIGN and DECLARE_LAMBDA_FUNCTION
+--INI--
+opcache.enable=1
+opcache.enable_cli=1
+opcache.optimization_level=-1
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+abstract class Broadcaster {
+    protected function normalizeChannelHandlerToCallable($callback)
+        {
+            return is_callable($callback) ? $callback : function (...$args) use ($callback) {
+                return Container::getInstance()
+                    ->make($callback)
+                ->join(...$args);
+        };
+    }
+}
+?>
+OK
+--EXPECT--
+OK
diff --git a/ext/opcache/tests/opt/block_pass_002.phpt b/ext/opcache/tests/opt/block_pass_002.phpt
new file mode 100644 (file)
index 0000000..ef7bf47
--- /dev/null
@@ -0,0 +1,19 @@
+--TEST--
+Block Pass 002: QM_ASSIGN and INIT_ARRAY
+--INI--
+opcache.enable=1
+opcache.enable_cli=1
+opcache.optimization_level=-1
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+function foo($key, $value, array $attributes) {
+       return is_array($value)
+               ? [$key, array_merge($value, $attributes)]
+               : [$value, $attributes];
+}
+?>
+OK
+--EXPECT--
+OK