From 7dc5bc5063f7f8265e32069908dfee797d4a8b02 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Mon, 14 Dec 2015 00:28:41 +0100 Subject: [PATCH] Do not swap operands in array addition As we support constant array operands nowadays, the original check didn't work anymore. --- .../tests/array_addition_not_commutative.phpt | 19 +++++++++++++++++++ ext/opcache/Optimizer/pass3.c | 4 +++- 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 Zend/tests/array_addition_not_commutative.phpt diff --git a/Zend/tests/array_addition_not_commutative.phpt b/Zend/tests/array_addition_not_commutative.phpt new file mode 100644 index 0000000000..f4e534231e --- /dev/null +++ b/Zend/tests/array_addition_not_commutative.phpt @@ -0,0 +1,19 @@ +--TEST-- +Array addition is not commutative -- do not swap operands +--FILE-- + +--EXPECT-- +array(3) { + [0]=> + int(4) + [1]=> + int(5) + [2]=> + int(6) +} diff --git a/ext/opcache/Optimizer/pass3.c b/ext/opcache/Optimizer/pass3.c index 3e589df628..43258c7d9f 100644 --- a/ext/opcache/Optimizer/pass3.c +++ b/ext/opcache/Optimizer/pass3.c @@ -106,7 +106,9 @@ void zend_optimizer_pass3(zend_op_array *op_array) zend_uchar tmp_type = opline->op1_type; znode_op tmp = opline->op1; - if (opline->opcode != ZEND_ADD || ZEND_OP1_TYPE(opline) == IS_CONST) { + if (opline->opcode != ZEND_ADD + || (ZEND_OP1_TYPE(opline) == IS_CONST + && Z_TYPE(ZEND_OP1_LITERAL(opline)) != IS_ARRAY)) { /* protection from array add: $a = array + $a is not commutative! */ COPY_NODE(opline->op1, opline->op2); COPY_NODE(opline->op2, tmp); -- 2.40.0