com php-src: Do not swap operands in array addition: Zend/tests/array_addition_not_commutative.phpt ext/op cache/Optimizer/pass3.c

From: Date: Sun, 13 Dec 2015 23:29:05 +0000
Subject: com php-src: Do not swap operands in array addition: Zend/tests/array_addition_not_commutative.phpt ext/op cache/Optimizer/pass3.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-90253@lists.php.net to get a copy of this message
Commit: 7dc5bc5063f7f8265e32069908dfee797d4a8b02 Author: Nikita Popov <nikic@php.net> Mon, 14 Dec 2015 00:28:41 +0100 Parents: 07b33992a2784bf9e3bbf1d46400c718e704a436 Branches: PHP-7.0 master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=7dc5bc5063f7f8265e32069908dfee797d4a8b02 Log: Do not swap operands in array addition As we support constant array operands nowadays, the original check didn't work anymore. Changed paths: A Zend/tests/array_addition_not_commutative.phpt M ext/opcache/Optimizer/pass3.c Diff: diff --git a/Zend/tests/array_addition_not_commutative.phpt b/Zend/tests/array_addition_not_commutative.phpt new file mode 100644 index 0000000...f4e5342 --- /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-- +<?php + +$array = [1, 2, 3]; +$array = [4, 5, 6] + $array; +var_dump($array); + +?> +--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 3e589df..43258c7 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);

« previous php.cvs (#90253) next »