com php-src: Fix type inference of SEND_UNPACK with empty array: ext/opcache/Optimizer/zend_inference.c ext/
opcache/tests/send_unpack_empty_array.phpt

From: Date: Tue, 28 May 2019 14:40:56 +0000
Subject: com php-src: Fix type inference of SEND_UNPACK with empty array: ext/opcache/Optimizer/zend_inference.c ext/
opcache/tests/send_unpack_empty_array.phpt
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-106401@lists.php.net to get a copy of this message
Commit: 59dfaa3f99b9be8b0848fe7bafce3c52a821a1fc Author: Nikita Popov <nikita.ppv@gmail.com> Tue, 28 May 2019 16:39:49 +0200 Parents: d661a75d54be58515edf6e560ae7d71315ffcb83 Branches: PHP-7.2 PHP-7.3 PHP-7.4 master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=59dfaa3f99b9be8b0848fe7bafce3c52a821a1fc Log: Fix type inference of SEND_UNPACK with empty array An empty array will not be turned into an array of references. This violated the invariant than an array has values iff it has keys. Changed paths: M ext/opcache/Optimizer/zend_inference.c A ext/opcache/tests/send_unpack_empty_array.phpt Diff: diff --git a/ext/opcache/Optimizer/zend_inference.c b/ext/opcache/Optimizer/zend_inference.c index 9e88e45..64d6ba1 100644 --- a/ext/opcache/Optimizer/zend_inference.c +++ b/ext/opcache/Optimizer/zend_inference.c @@ -2856,8 +2856,10 @@ static int zend_update_type_info(const zend_op_array *op_array, tmp = t1; if (t1 & MAY_BE_ARRAY) { tmp |= MAY_BE_RC1 | MAY_BE_RCN; - /* SEND_UNPACK may acquire references into the array */ - tmp |= MAY_BE_ARRAY_OF_ANY | MAY_BE_ARRAY_OF_REF; + if (t1 & MAY_BE_ARRAY_OF_ANY) { + /* SEND_UNPACK may acquire references into the array */ + tmp |= MAY_BE_ARRAY_OF_ANY | MAY_BE_ARRAY_OF_REF; + } } if (t1 & MAY_BE_OBJECT) { tmp |= MAY_BE_RC1 | MAY_BE_RCN; diff --git a/ext/opcache/tests/send_unpack_empty_array.phpt b/ext/opcache/tests/send_unpack_empty_array.phpt new file mode 100644 index 0000000..4059ad4 --- /dev/null +++ b/ext/opcache/tests/send_unpack_empty_array.phpt @@ -0,0 +1,24 @@ +--TEST-- +Type inference of SEND_UNPACK with empty array +--FILE-- +<?php +function test() { + $array = [1, 2, 3]; + $values = []; + var_dump(array_push($array, 4, ...$values)); + var_dump($array); +} +test(); +?> +--EXPECT-- +int(4) +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) +}

« previous php.cvs (#106401) next »