diff options
author | Nikita Popov <nikic@php.net> | 2016-11-10 21:36:46 +0100 |
---|---|---|
committer | Nikita Popov <nikic@php.net> | 2016-11-10 21:36:46 +0100 |
commit | bb3d0c0e17a614f2bcb2a257f8146affced86341 (patch) | |
tree | 4ea2f5de4655a2350be0060795028c99c713e893 | |
parent | 15ac4904727d22acdb9722871ef8f4acb7ddccae (diff) | |
download | php-git-bb3d0c0e17a614f2bcb2a257f8146affced86341.tar.gz |
Fcall optimization: Avoid FETCH_DIM_R with UNUSED op2
-rw-r--r-- | ext/opcache/Optimizer/optimize_func_calls.c | 7 | ||||
-rw-r--r-- | ext/opcache/tests/optimize_func_calls_001.phpt | 15 |
2 files changed, 22 insertions, 0 deletions
diff --git a/ext/opcache/Optimizer/optimize_func_calls.c b/ext/opcache/Optimizer/optimize_func_calls.c index 5804a5fb0e..ccac5b9fbc 100644 --- a/ext/opcache/Optimizer/optimize_func_calls.c +++ b/ext/opcache/Optimizer/optimize_func_calls.c @@ -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 index 0000000000..5745b3fad0 --- /dev/null +++ b/ext/opcache/tests/optimize_func_calls_001.phpt @@ -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 |