Skip to content

Commit 011afaf

Browse files
committed
Merge branch 'PHP-7.1' of git.php.net:/php-src into PHP-7.1
2 parents 147f1f2 + 5f4f832 commit 011afaf

File tree

2 files changed

+38
-6
lines changed

2 files changed

+38
-6
lines changed

ext/opcache/Optimizer/optimize_func_calls.c

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,6 @@ static void zend_delete_call_instructions(zend_op *opline)
7171
break;
7272
case ZEND_SEND_VAL:
7373
case ZEND_SEND_VAR:
74-
case ZEND_SEND_VAR_NO_REF:
75-
case ZEND_SEND_REF:
7674
if (call == 0) {
7775
if (opline->op1_type == IS_CONST) {
7876
MAKE_NOP(opline);
@@ -102,24 +100,36 @@ static void zend_try_inline_call(zend_op_array *op_array, zend_op *fcall, zend_o
102100
zend_op *ret_opline = func->op_array.opcodes + func->op_array.num_args;
103101

104102
if (ret_opline->op1_type == IS_CONST) {
103+
uint32_t i, num_args = func->op_array.num_args;
104+
num_args += (func->op_array.fn_flags & ZEND_ACC_VARIADIC) != 0;
105105

106106
if (fcall->opcode == ZEND_INIT_METHOD_CALL && fcall->op1_type == IS_UNUSED) {
107107
/* TODO: we can't inlne methods, because $this may be used
108108
* not in object context ???
109109
*/
110110
return;
111111
}
112+
113+
for (i = 0; i < num_args; i++) {
114+
/* Don't inline functions with by-reference arguments. This would require
115+
* correct handling of INDIRECT arguments. */
116+
if (func->op_array.arg_info[i].pass_by_reference) {
117+
return;
118+
}
119+
}
120+
112121
if (fcall->extended_value < func->op_array.num_args) {
113122
/* don't inline funcions with named constants in default arguments */
114-
uint32_t n = fcall->extended_value;
123+
i = fcall->extended_value;
115124

116125
do {
117-
if (Z_CONSTANT_P(RT_CONSTANT(&func->op_array, func->op_array.opcodes[n].op2))) {
126+
if (Z_CONSTANT_P(RT_CONSTANT(&func->op_array, func->op_array.opcodes[i].op2))) {
118127
return;
119128
}
120-
n++;
121-
} while (n < func->op_array.num_args);
129+
i++;
130+
} while (i < func->op_array.num_args);
122131
}
132+
123133
if (RETURN_VALUE_USED(opline)) {
124134
zval zv;
125135

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
Inlining of functions with ref arguments
3+
--FILE--
4+
<?php
5+
6+
function by_ref(&$var)
7+
{
8+
}
9+
function &get_array() {
10+
$array = [new stdClass];
11+
return $array;
12+
}
13+
function test()
14+
{
15+
by_ref(get_array()[0]);
16+
print "ok!\n";
17+
}
18+
test();
19+
20+
?>
21+
--EXPECT--
22+
ok!

0 commit comments

Comments
 (0)