]> granicus.if.org Git - php/commitdiff
Fcall optimization: Avoid FETCH_DIM_R with UNUSED op2
authorNikita Popov <nikic@php.net>
Thu, 10 Nov 2016 20:36:46 +0000 (21:36 +0100)
committerNikita Popov <nikic@php.net>
Thu, 10 Nov 2016 20:36:46 +0000 (21:36 +0100)
ext/opcache/Optimizer/optimize_func_calls.c
ext/opcache/tests/optimize_func_calls_001.phpt [new file with mode: 0644]

index 5804a5fb0e2217a4cad3b2dab0baba234c8a0d81..ccac5b9fbc37c5db7ee4bcf681fa06535abb7f57 100644 (file)
@@ -112,6 +112,13 @@ void optimize_func_calls(zend_op_array *op_array, zend_optimizer_ctx *ctx)
                                                opline->extended_value &= ZEND_FETCH_TYPE_MASK;
                                                opline->opcode -= 9;
                                        } else {
+                                               if (opline->opcode == ZEND_FETCH_DIM_FUNC_ARG
+                                                               && opline->op2_type == IS_UNUSED) {
+                                                       /* FETCH_DIM_FUNC_ARG supports UNUSED op2, while FETCH_DIM_R does not.
+                                                        * Performing the replacement would create an invalid opcode. */
+                                                       break;
+                                               }
+
                                                opline->extended_value &= ZEND_FETCH_TYPE_MASK;
                                                opline->opcode -= 12;
                                        }
diff --git a/ext/opcache/tests/optimize_func_calls_001.phpt b/ext/opcache/tests/optimize_func_calls_001.phpt
new file mode 100644 (file)
index 0000000..5745b3f
--- /dev/null
@@ -0,0 +1,15 @@
+--TEST--
+Don't create FETCH_DIM_R with UNUSED op2
+--FILE--
+<?php
+
+// Order matters
+test($arr[]);
+function test($arg) {}
+
+?>
+--EXPECTF--
+Fatal error: Uncaught Error: Cannot use [] for reading in %s:%d
+Stack trace:
+#0 {main}
+  thrown in %s on line %d